mirror of
https://github.com/discourse/discourse.git
synced 2025-08-17 18:04:11 +08:00
Building the Discourse ember app is resource-intensive process. This commit introduces a framework for us to build these assets centrally, and make them available for people to download. On every commit to `main`, a new GitHub actions workflow will build development & production versions of the core assets, and publish them as a github release under the `discourse/discourse-assets` repository. A separate repository is being used to avoid polluting the main `discourse/discourse` repository with one-git-tag-per-release. The `assemble_ember_build.rb` script is updated to fetch the relevant asset bundle. Requests are made to `get.discourse.org`, which then redirects to GitHub releases. This redirection service is being used so that we have the option to switch away from GitHub releases in future without breaking existing Discourse installations. For now, this behavior can be enabled by setting `DISCOURSE_DOWNLOAD_PRE_BUILT_ASSETS=1`. In the near future, we hope to make this the default, with opt-out via `DISCOURSE_DOWNLOAD_PRE_BUILT_ASSETS=0`.
58 lines
1.6 KiB
Ruby
Executable file
58 lines
1.6 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
# rubocop:disable Discourse/NoChdir
|
|
|
|
require "fileutils"
|
|
require_relative "../lib/version"
|
|
require "open3"
|
|
|
|
tmp_dir = "#{__dir__}/../tmp/prebuilt_asset_bundles"
|
|
FileUtils.mkdir_p(tmp_dir)
|
|
|
|
core_commit_hash = `git rev-parse HEAD`.strip
|
|
version_string = "v#{Discourse::VERSION::STRING}-#{core_commit_hash.slice(0, 8)}"
|
|
release_repo = "discourse/discourse-assets"
|
|
|
|
puts "Checking if release #{version_string} already exists in #{release_repo}..."
|
|
|
|
out, status =
|
|
Open3.capture2e("gh", "--repo", release_repo, "release", "view", version_string, "--json", "name")
|
|
puts out
|
|
|
|
if status.success?
|
|
puts "Release #{version_string} already exists in #{release_repo}. Exiting."
|
|
exit 0
|
|
end
|
|
|
|
common_env = { "DISCOURSE_DOWNLOAD_PRE_BUILT_ASSETS" => "0", "LOAD_PLUGINS" => "0" }
|
|
|
|
Dir.chdir("#{__dir__}/../app/assets/javascripts/discourse")
|
|
FileUtils.rm_rf("dist")
|
|
|
|
system({ **common_env, "EMBER_ENV" => "production" }, "#{__dir__}/assemble_ember_build.rb")
|
|
FileUtils.rm_rf("dist/assets/plugins")
|
|
system("tar", "-czf", "#{tmp_dir}/production.tar.gz", "dist", exception: true)
|
|
|
|
FileUtils.rm_rf("dist")
|
|
system({ **common_env, "EMBER_ENV" => "development" }, "#{__dir__}/assemble_ember_build.rb")
|
|
FileUtils.rm_rf("dist/assets/plugins")
|
|
system("tar", "-czf", "#{tmp_dir}/development.tar.gz", "dist", exception: true)
|
|
|
|
puts "Creating release #{version_string} in #{release_repo}..."
|
|
system(
|
|
"gh",
|
|
"--repo",
|
|
release_repo,
|
|
"release",
|
|
"create",
|
|
version_string,
|
|
"#{tmp_dir}/production.tar.gz",
|
|
"#{tmp_dir}/development.tar.gz",
|
|
"--title",
|
|
version_string,
|
|
"--notes",
|
|
version_string,
|
|
exception: true,
|
|
)
|
|
|
|
FileUtils.rm_rf(tmp_dir)
|