Skip to content

A platform for community discussion. Free, open, simple.

DEV: Pull compatible themes in tests workflow (#27093)

Alan Guo Xiang Tan34c527d6942e
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index f6ec691f35e..0c89a995590 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -145,6 +145,10 @@ jobs:
if: matrix.target == 'themes' && matrix.build_type == 'system'
run: bin/rake themes:clone_all_official
+ - name: Pull compatible versions of themes
+ if: matrix.target == 'themes'
+ run: bin/rake themes:pull_compatible_all
+
- name: Add hosts to /etc/hosts, otherwise Chromium cannot reach minio
if: matrix.build_type == 'system' && matrix.target == 'core'
run: |
diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index 5580aa3a9a8..5d256082e17 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -225,6 +225,33 @@ task "themes:clone_all_official" do |task, args|
end
end
+desc "pull compatible theme versions for all themes"
+task "themes:pull_compatible_all" do |t|
+ Dir
+ .glob(File.expand_path("#{Rails.root}/tmp/themes/*"))
+ .select { |f| File.directory? f }
+ .each do |theme_path|
+ next unless File.directory?(theme_path + "/.git")
+
+ theme_name = File.basename(theme_path)
+ checkout_version = Discourse.find_compatible_git_resource(theme_path)
+
+ # Checkout value of the version compat
+ if checkout_version
+ puts "checking out compatible #{theme_name} version: #{checkout_version}"
+
+ update_status =
+ system(
+ "git -C '#{theme_path}' cat-file -e #{checkout_version} || git -C '#{theme_path}' fetch --depth 1 $(git -C '#{theme_path}' rev-parse --symbolic-full-name @{upstream} | awk -F '/' '{print $3}') #{checkout_version}; git -C '#{theme_path}' reset --hard #{checkout_version}",
+ )
+
+ abort("Unable to checkout a compatible theme version") unless update_status
+ else
+ puts "#{theme_name} is already at latest compatible version"
+ end
+ end
+end
+
# Note that this should only be used in CI where it is safe to mutate the database without rolling back since running
# the themes QUnit tests requires the themes to be installed in the database.
desc "Runs qunit tests for all official themes"