From a816814819980470058cfe013a89e3c453d2dc98 Mon Sep 17 00:00:00 2001 From: Joseph Johansen Date: Wed, 21 Aug 2024 11:37:07 +0100 Subject: [PATCH] Update CI workflow to upload results and call rake task --- .github/workflows/build.yml | 107 ++++++++++++++++++++++++++++++++---- .simplecov | 2 + lib/tasks/simplecov.rake | 2 +- 3 files changed, 98 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5c7ba16f8..6b6db9ad81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Build on: workflow_dispatch: push: - branches-ignore: + branches-ignore: - 'dependabot/**' pull_request: @@ -47,7 +47,7 @@ jobs: - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -81,11 +81,19 @@ jobs: # RSpec split test files by test examples feature - it's optional # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}" + KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/controllers/**/*_spec.rb}" run: | git show --no-patch # the commit being tested (which is often a merge due to actions/checkout@v3) bin/rake knapsack_pro:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-controllers-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + models: runs-on: ubuntu-22.04 services: @@ -116,7 +124,7 @@ jobs: - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -141,10 +149,18 @@ jobs: # RSpec split test files by test examples feature - it's optional # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/models/**/*_spec.rb}" + KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/models/**/*_spec.rb}" run: | bin/rake knapsack_pro:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-models-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + system_admin: runs-on: ubuntu-22.04 services: @@ -175,7 +191,7 @@ jobs: - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -209,11 +225,19 @@ jobs: # RSpec split test files by test examples feature - it's optional # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/admin/**/*_spec.rb}" + KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/admin/**/*_spec.rb}" run: | bin/rake knapsack_pro:queue:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-system-admin-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + - name: Archive failed tests screenshots if: failure() uses: actions/upload-artifact@v4 @@ -247,13 +271,13 @@ jobs: ci_node_total: [12] # Indexes for parallel jobs (starting from zero). # E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc. - ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] steps: - uses: actions/checkout@v3 - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -287,11 +311,19 @@ jobs: # RSpec split test files by test examples feature - it's optional # https://knapsackpro.com/faq/question/how-to-split-slow-rspec-test-files-by-test-examples-by-individual-it #KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true - KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/consumer/**/*_spec.rb}" + KNAPSACK_PRO_TEST_FILE_PATTERN: "{spec/system/consumer/**/*_spec.rb}" run: | bin/rake knapsack_pro:queue:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-system-consumer-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + - name: Archive failed tests screenshots if: failure() uses: actions/upload-artifact@v4 @@ -331,7 +363,7 @@ jobs: - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -371,6 +403,14 @@ jobs: run: | bin/rake knapsack_pro:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-engines-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + test_the_rest: runs-on: ubuntu-22.04 services: @@ -401,7 +441,7 @@ jobs: - name: Setup redis uses: supercharge/redis-github-action@1.4.0 - with: + with: redis-version: 6 - name: Set up Ruby @@ -439,6 +479,14 @@ jobs: run: | bin/rake knapsack_pro:rspec + - name: Save SimpleCov file + uses: actions/upload-artifact@v3 + with: + name: __simplecov-chunk-the-rest-${{ matrix.ci_node_index }} + path: coverage/*.* + retention-days: 2 # doesn't need to be long, because it's the combined results that matter + if-no-files-found: ignore + non_knapsack_jest_karma: runs-on: ubuntu-22.04 services: @@ -476,3 +524,38 @@ jobs: - name: Run jest tests run: yarn jest + + collate_simplecov_results: + runs-on: ubuntu-22.04 + needs: + - controllers + - models + - engines + - system_admin + - system_consumer + - test_the_rest + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Download individual results from individual runners + uses: actions/download-artifact@v3 + with: + pattern: __simplecov-chunk-* + path: tmp/simplecov + merge-multiple: true + + - name: collate results from each of the workers + run: bundle exec rake 'simplecov:collate_results[tmp/simplecov]' + + - name: Upload collated results + uses: actions/upload-artifact@v3 + with: + name: simplecov-combined-results + path: coverage/*.* + retention-days: 7 + if-no-files-found: ignore diff --git a/.simplecov b/.simplecov index 0094b3ddcd..8cf02c6b54 100755 --- a/.simplecov +++ b/.simplecov @@ -14,4 +14,6 @@ SimpleCov.start 'rails' do add_filter '/log' add_filter '/db' add_filter '/lib/tasks/sample_data/' + + formatter SimpleCov::Formatter::SimpleFormatter end diff --git a/lib/tasks/simplecov.rake b/lib/tasks/simplecov.rake index bc190c1fe4..b1a50737d7 100644 --- a/lib/tasks/simplecov.rake +++ b/lib/tasks/simplecov.rake @@ -6,7 +6,7 @@ namespace :simplecov do [:path_to_results, :coverage_dir] do |_t, args| require "simplecov" - path_to_results = args[:path_to_results].presence || "tmp/simple-cov" + path_to_results = args[:path_to_results].presence || "tmp/simplecov" coverage_dir = args[:coverage_dir].presence || "coverage" SimpleCov.collate Dir[File.join(path_to_results, "**", ".resultset.json")], "rails" do