Skip to content

Commit

Permalink
DEV: Run system tests for official themes (discourse#24378)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgxworld authored Nov 15, 2023
1 parent 0bc568f commit 6ce55e5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions lib/tasks/themes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions lib/theme_metadata.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6ce55e5

Please sign in to comment.