Skip to content

Commit

Permalink
Update CI workflow to upload results and call rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
johansenja committed Aug 23, 2024
1 parent 5f9b14d commit a816814
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 13 deletions.
107 changes: 95 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build
on:
workflow_dispatch:
push:
branches-ignore:
branches-ignore:
- 'dependabot/**'
pull_request:

Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Setup redis
uses: supercharge/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -116,7 +124,7 @@ jobs:

- name: Setup redis
uses: supercharge/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand All @@ -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:
Expand Down Expand Up @@ -175,7 +191,7 @@ jobs:

- name: Setup redis
uses: supercharge/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -331,7 +363,7 @@ jobs:

- name: Setup redis
uses: supercharge/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -401,7 +441,7 @@ jobs:

- name: Setup redis
uses: supercharge/[email protected]
with:
with:
redis-version: 6

- name: Set up Ruby
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/tasks/simplecov.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a816814

Please sign in to comment.