From 6ce55e53479d9ba1b0e6e4cdedb5791f7fa4a072 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 16 Nov 2023 07:11:35 +0800 Subject: [PATCH] DEV: Run system tests for official themes (#24378) Why this change? As the number of themes which the Discourse team supports officially grows, we want to ensure that changes made to Discourse core do not break the plugins. As such, we are adding a step to our Github actions test job to run the system tests for all official themes. What does this change do? This change adds a step to our Github actions test job to run the system tests for all official plugins. This is achieved by the introduction of the `themes:install_all_official` Rake task which installs all the themes that are officially supported by the Discourse team. --- .github/workflows/tests.yml | 21 +++++++++++++++++++-- lib/tasks/themes.rake | 23 +++++++++++++++++++++++ lib/theme_metadata.rb | 22 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 lib/theme_metadata.rb diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index baa96095260..ccb1f270c72 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,11 +41,17 @@ jobs: matrix: build_type: [backend, frontend, system, annotations] - target: [core, plugins] + target: [core, plugins, themes] ruby: ["3.2"] exclude: - build_type: annotations target: plugins + - build_type: annotations + target: themes + - build_type: frontend + target: themes + - build_type: backend + target: themes - build_type: frontend target: core # Handled by core_frontend_tests job (below) include: @@ -113,6 +119,10 @@ jobs: if: matrix.target == 'plugins' run: bin/rake plugin:pull_compatible_all + - name: Checkout official themes + if: matrix.target == 'themes' + run: bin/rake themes:clone_all_official + - name: Add hosts to /etc/hosts, otherwise Chrome cannot reach minio run: | echo "127.0.0.1 minio.local" | sudo tee -a /etc/hosts @@ -237,12 +247,19 @@ jobs: LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --use-runtime-info --profile=50 --verbose --format documentation plugins/*/spec/system shell: bash timeout-minutes: 30 - + - name: Chat System Tests if: matrix.build_type == 'system' && matrix.target == 'chat' run: LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --use-runtime-info --profile=50 --verbose --format documentation plugins/chat/spec/system timeout-minutes: 30 + - name: Theme System Tests + if: matrix.build_type == 'system' && matrix.target == 'themes' + run: | + RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --profile=50 --verbose --format documentation tmp/themes/*/spec/system + shell: bash + timeout-minutes: 30 + - name: Upload failed system test screenshots uses: actions/upload-artifact@v3 if: matrix.build_type == 'system' && failure() diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake index e1fc052ac54..58c7b5d93be 100644 --- a/lib/tasks/themes.rake +++ b/lib/tasks/themes.rake @@ -194,3 +194,26 @@ ensure db&.remove redis&.remove end + +desc "Clones all official themes." +task "themes:clone_all_official" do |task, args| + require "theme_metadata" + FileUtils.rm_rf("tmp/themes") + + official_themes = + ThemeMetadata::OFFICIAL_THEMES.each do |theme_name| + repo = "https://github.com/discourse/#{theme_name}" + path = File.expand_path("tmp/themes/#{theme_name}") + + attempts = 0 + + begin + attempts += 1 + system("git clone #{repo} #{path}", exception: true) + rescue StandardError + abort("Failed to clone #{repo}") if attempts >= 3 + STDERR.puts "Failed to clone #{repo}... trying again..." + retry + end + end +end diff --git a/lib/theme_metadata.rb b/lib/theme_metadata.rb new file mode 100644 index 00000000000..c6d3df4ae0d --- /dev/null +++ b/lib/theme_metadata.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ThemeMetadata + OFFICIAL_THEMES = + Set.new( + %w[ + discourse-brand-header + discourse-category-banners + discourse-clickable-topic + discourse-color-scheme-toggle + discourse-custom-header-links + Discourse-easy-footer + discourse-gifs + discourse-topic-thumbnails + discourse-search-banner + discourse-unanswered-filter + discourse-versatile-banner + DiscoTOC + unformatted-code-detector + ], + ).to_a +end