From d83c036ef1ea3131d0ba14cb964485039509dd82 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Oct 2021 18:09:03 +0200 Subject: [PATCH 1/9] specs: profile specs runtime --- .rspec | 1 + 1 file changed, 1 insertion(+) diff --git a/.rspec b/.rspec index 0f30adeb0..d958652df 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ --color --require rails_helper +--profile From 21efece09e1cf985fe15296da8cca2a6ed866912 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 11:07:42 +0000 Subject: [PATCH 2/9] ci: use builtin cache for node modules This is around 20s faster (10s when retrieved the cache and installing node modules, and 10s when saving the cache). --- .github/workflows/ci.yml | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47554ed09..eac5a92b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,19 +22,10 @@ jobs: uses: actions/setup-node@v2 with: node-version: '14' - - name: Find yarn cache location - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: JS package cache - uses: actions/cache@v2 - with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Install packages - run: | - yarn install --frozen-lockfile + cache: yarn + + - name: Install node modules + run: yarn install --frozen-lockfile - name: Run linters run: | @@ -79,19 +70,10 @@ jobs: uses: actions/setup-node@v2 with: node-version: '14' - - name: Find yarn cache location - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: JS package cache - uses: actions/cache@v2 - with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Install packages - run: | - yarn install --frozen-lockfile + cache: 'yarn' + + - name: Install Node modules + run: yarn install --frozen-lockfile - name: Setup test database env: From ba78e2bfb2a19c48299efa13e15ec2ff916fb545 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 13:27:26 +0200 Subject: [PATCH 3/9] ci: use bin/rails instead of rake --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eac5a92b7..ef3df3965 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: RAILS_ENV: test DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test" run: | - bundle exec rake db:create db:schema:load db:migrate + bin/rails db:create db:schema:load db:migrate - name: Setup environment variables run: | From 2c96ade1b2ce6148884e5fb4592b7dcb0b89c08b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 12:01:56 +0000 Subject: [PATCH 4/9] ci: split tests automatically --- .github/workflows/ci.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef3df3965..468dad6dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,15 +47,14 @@ jobs: matrix: pattern: - bin/rake zeitwerk:check - - bin/rspec spec/controllers/*_spec.rb - - bin/rspec spec/controllers/[a-l]**/*_spec.rb - - bin/rspec spec/controllers/[m-z]**/*_spec.rb - - bin/rspec spec/system - - bin/rspec spec/helpers spec/lib spec/middlewares - - bin/rspec spec/mailers spec/jobs spec/policies - - bin/rspec spec/models - - bin/rspec spec/serializers spec/services - - bin/rspec spec/views + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=0 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=1 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=2 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=3 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=4 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=5 -split-total=6) + - bin/rspec $(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=0 -split-total=2) + - bin/rspec $(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=1 -split-total=2) steps: - name: Checkout code @@ -75,6 +74,11 @@ jobs: - name: Install Node modules run: yarn install --frozen-lockfile + - name: Setup split_tests binary + run: | + curl --no-progress-meter -L https://github.com/leonid-shevtsov/split_tests/releases/download/v0.3.0/split_tests.linux.gz | gunzip -c > split_tests + chmod +x split_tests + - name: Setup test database env: RAILS_ENV: test From a01a619ec050d0b1db8bf516a5ff857f569efc38 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 14:38:40 +0200 Subject: [PATCH 5/9] js: update caniuse browsers db This follows a warning during tests: > Browserslist: caniuse-lite is outdated. Please run: > npx browserslist@latest --update-db > > Why you should do it regularly: > browserslist/browserslist#browsers-data-updating --- yarn.lock | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1361a306e..f7e857088 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3525,15 +3525,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001039, caniuse-lite@^1.0.30001219: - version "1.0.30001228" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001228.tgz#bfdc5942cd3326fa51ee0b42fbef4da9d492a7fa" - integrity sha512-QQmLOGJ3DEgokHbMSA8cj2a+geXqmnpyOFT0lhQV6P3/YOJvGDEwoedcwxEQ30gJIwIIunHIicunJ2rzK5gB2A== - -caniuse-lite@^1.0.30001254: - version "1.0.30001257" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001257.tgz#150aaf649a48bee531104cfeda57f92ce587f6e5" - integrity sha512-JN49KplOgHSXpIsVSF+LUyhD8PUp6xPpAXeRrrcBh4KBeP7W864jHn6RvzJgDlrReyeVjMFJL3PLpPvKIxlIHA== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001039, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001254: + version "1.0.30001271" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001271.tgz" + integrity sha512-BBruZFWmt3HFdVPS8kceTBIguKxu4f99n5JNp06OlPD/luoAMIaIK5ieV5YjnBLH3Nysai9sxj9rpJj4ZisXOA== cardinal@^2.1.1: version "2.1.1" From d0a6fc4b8e1d58a29c92322d57c571e4b1efba0b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 12:34:11 +0000 Subject: [PATCH 6/9] ci: precompile (and cache) assets This avoids the assets to be compiled lazily during the first spec, which confuses test metrics. --- .github/workflows/ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 468dad6dc..fe3ab76fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,5 +90,24 @@ jobs: run: | cp config/env.example .env + - name: Assets cache + uses: actions/cache@v2 + with: + path: | + public/assets + public/packs-test + tmp/cache/webpacker + key: asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} + asset-cache-${{ runner.os }}-${{ github.ref }}- + asset-cache-${{ runner.os }}- + + - name: Precompile assets + env: + RAILS_ENV: test + run: | + bin/rails assets:precompile --trace + - name: Run tests run: ${{ matrix.pattern }} From 641f0df712e006d4a2a36fc81344102a585528da Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 14:35:18 +0200 Subject: [PATCH 7/9] ci: avoid installing node modules again By default `bin/rails assets:precompile` will run `yarn install` again. The suggested workaround is to remove `bin/yarn` before running the task. See https://github.com/rails/webpacker/issues/405 --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe3ab76fe..36cdbf541 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,6 +107,7 @@ jobs: env: RAILS_ENV: test run: | + rm bin/yarn bin/rails assets:precompile --trace - name: Run tests From 184bf38bb293f50610d96d64e69b6407261120b9 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 26 Oct 2021 14:58:48 +0000 Subject: [PATCH 8/9] ci: split actions into several sub-actions --- .github/actions/ci-setup-assets/action.yml | 26 ++++ .github/actions/ci-setup-rails/action.yml | 37 ++++++ .github/workflows/ci.yml | 134 +++++++++------------ 3 files changed, 119 insertions(+), 78 deletions(-) create mode 100644 .github/actions/ci-setup-assets/action.yml create mode 100644 .github/actions/ci-setup-rails/action.yml diff --git a/.github/actions/ci-setup-assets/action.yml b/.github/actions/ci-setup-assets/action.yml new file mode 100644 index 000000000..6db13ed24 --- /dev/null +++ b/.github/actions/ci-setup-assets/action.yml @@ -0,0 +1,26 @@ +name: 'Setup Rails assets' +description: 'Pre-compile and cache the app assets' + +runs: + using: composite + steps: + - name: Assets cache + uses: actions/cache@v2 + with: + path: | + public/assets + public/packs-test + tmp/cache/webpacker + key: asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} + asset-cache-${{ runner.os }}-${{ github.ref }}- + asset-cache-${{ runner.os }}- + + - name: Precompile assets + env: + RAILS_ENV: test + run: | + rm bin/yarn + bin/rails assets:precompile --trace + shell: bash diff --git a/.github/actions/ci-setup-rails/action.yml b/.github/actions/ci-setup-rails/action.yml new file mode 100644 index 000000000..76f431936 --- /dev/null +++ b/.github/actions/ci-setup-rails/action.yml @@ -0,0 +1,37 @@ +name: 'Setup Rails app' +description: 'Setup the environment for running the Rails app' + +runs: + using: composite + steps: + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '14' + cache: 'yarn' + + - name: Install Node modules + run: yarn install --frozen-lockfile + shell: bash + + - name: Setup environment variables + run: cp config/env.example .env + shell: bash + + - name: Setup test database + env: + RAILS_ENV: test + DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test" + run: bin/rails db:create db:schema:load db:migrate + shell: bash + + - name: Setup split_tests binary + run: | + curl --no-progress-meter -L https://github.com/leonid-shevtsov/split_tests/releases/download/v0.3.0/split_tests.linux.gz | gunzip -c > split_tests + chmod +x split_tests + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36cdbf541..849e52b22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,30 +9,28 @@ jobs: linters: name: Linters runs-on: ubuntu-latest + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: tps_test + POSTGRES_DB: tps_test + POSTGRES_PASSWORD: tps_test + ports: [ "5432:5432" ] + steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: '14' - cache: yarn - - - name: Install node modules - run: yarn install --frozen-lockfile + - name: Setup the app code and dependancies + uses: ./.github/actions/ci-setup-rails - name: Run linters run: | bundle exec rake lint + bundle exec rake zeitwerk:check - tests: - name: Tests + unit_tests: + name: Unit tests runs-on: ubuntu-latest services: postgres: @@ -45,70 +43,50 @@ jobs: strategy: matrix: - pattern: - - bin/rake zeitwerk:check - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=0 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=1 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=2 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=3 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=4 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=5 -split-total=6) - - bin/rspec $(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=0 -split-total=2) - - bin/rspec $(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=1 -split-total=2) + split_index: [0, 1, 2, 3, 4, 5] steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true + - name: Setup the app runtime and dependencies + uses: ./.github/actions/ci-setup-rails - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: '14' - cache: 'yarn' - - - name: Install Node modules - run: yarn install --frozen-lockfile - - - name: Setup split_tests binary - run: | - curl --no-progress-meter -L https://github.com/leonid-shevtsov/split_tests/releases/download/v0.3.0/split_tests.linux.gz | gunzip -c > split_tests - chmod +x split_tests - - - name: Setup test database - env: - RAILS_ENV: test - DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test" - run: | - bin/rails db:create db:schema:load db:migrate - - - name: Setup environment variables - run: | - cp config/env.example .env - - - name: Assets cache - uses: actions/cache@v2 - with: - path: | - public/assets - public/packs-test - tmp/cache/webpacker - key: asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} - restore-keys: | - asset-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }} - asset-cache-${{ runner.os }}-${{ github.ref }}- - asset-cache-${{ runner.os }}- - - - name: Precompile assets - env: - RAILS_ENV: test - run: | - rm bin/yarn - bin/rails assets:precompile --trace + - name: Pre-compile assets + uses: ./.github/actions/ci-setup-assets - name: Run tests - run: ${{ matrix.pattern }} + run: | + SPEC_FILES=$(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=${{ matrix.split_index }} -split-total=6) + echo "Running tests for bin/rspec $SPEC_FILES" + bin/rspec $SPEC_FILES + + system_tests: + name: System tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: tps_test + POSTGRES_DB: tps_test + POSTGRES_PASSWORD: tps_test + ports: ["5432:5432"] + + strategy: + matrix: + split_index: [0, 1] + + steps: + - uses: actions/checkout@v2 + + - name: Setup the app runtime and dependencies + uses: ./.github/actions/ci-setup-rails + + - name: Pre-compile assets + uses: ./.github/actions/ci-setup-assets + + - name: Run tests + run: | + SPEC_FILES=$(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=${{ matrix.split_index }} -split-total=2) + echo "Running tests for bin/rspec $SPEC_FILES" + bin/rspec $SPEC_FILES From 75e207122b5aa3c3de4b73efddcf5d5bc6e7243e Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 3 Nov 2021 20:54:54 +0000 Subject: [PATCH 9/9] ci: use previous test timings to split the tests --- .../actions/ci-save-split-tests/action.yml | 17 ++++++ .github/actions/ci-setup-rails/action.yml | 6 --- .../actions/ci-setup-split-tests/action.yml | 46 ++++++++++++++++ .github/workflows/ci.yml | 53 ++++++++++++++++--- Gemfile | 1 + Gemfile.lock | 3 ++ 6 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 .github/actions/ci-save-split-tests/action.yml create mode 100644 .github/actions/ci-setup-split-tests/action.yml diff --git a/.github/actions/ci-save-split-tests/action.yml b/.github/actions/ci-save-split-tests/action.yml new file mode 100644 index 000000000..2f9e8896f --- /dev/null +++ b/.github/actions/ci-save-split-tests/action.yml @@ -0,0 +1,17 @@ +name: 'Save split-tests' +description: 'Save Junit test results and timing data, to better split future tests' + +inputs: + results_path: + description: 'Glob pattern to the JUnit files to save' + required: true + +# This should be run once the results from all runs are collected. +runs: + using: composite + steps: + - name: Save test reports + uses: actions/cache@v2 + with: + path: ${{ inputs.results_path }} + key: tests-reports-${{ github.ref }}-${{ github.sha }}-${{ github.run_id }} diff --git a/.github/actions/ci-setup-rails/action.yml b/.github/actions/ci-setup-rails/action.yml index 76f431936..7f4b9edb8 100644 --- a/.github/actions/ci-setup-rails/action.yml +++ b/.github/actions/ci-setup-rails/action.yml @@ -29,9 +29,3 @@ runs: DATABASE_URL: "postgres://tps_test@localhost:5432/tps_test" run: bin/rails db:create db:schema:load db:migrate shell: bash - - - name: Setup split_tests binary - run: | - curl --no-progress-meter -L https://github.com/leonid-shevtsov/split_tests/releases/download/v0.3.0/split_tests.linux.gz | gunzip -c > split_tests - chmod +x split_tests - shell: bash diff --git a/.github/actions/ci-setup-split-tests/action.yml b/.github/actions/ci-setup-split-tests/action.yml new file mode 100644 index 000000000..e49f4c2f4 --- /dev/null +++ b/.github/actions/ci-setup-split-tests/action.yml @@ -0,0 +1,46 @@ +name: 'Setup split-tests' +description: 'Setup the environment for splitting tests' + +inputs: + results_path: + description: 'Glob pattern to the JUnit files to save' + required: true + +runs: + using: composite + steps: + - name: Setup split_tests binary + run: | + curl --no-progress-meter -L https://github.com/leonid-shevtsov/split_tests/releases/download/v0.3.0/split_tests.linux.gz | gunzip -c > split_tests + chmod +x split_tests + shell: bash + + - name: Generate an unique random value + run: echo dummy_random_value=$RANDOM >> $GITHUB_ENV + shell: bash + + # Restore previous runs timing from the cache. + # + # NB: at the end of the job, the `actions/cache@v2` action will attempt + # to save the results back to the same key. However at this stage only + # tests results for a single instance will be available. + # + # To avoid the cache being overwritten with this single result, we define + # a random cache key, which the action will use to save the single-instance + # report to a dummy location. + # + # The actual retrieval uses the `restore-keys` instead. + - name: Restore previous runs timings + uses: actions/cache@v2 + with: + path: ${{ inputs.results_path }} + key: single-instance-report-${{ github.sha }}-${{ env.dummy_random_value }} + restore-keys: | + tests-reports-${{ github.ref }}-${{ github.sha }}-${{ github.run_id }} + tests-reports-${{ github.ref }}-${{ github.sha }}- + tests-reports-${{ github.ref }}- + tests-reports- + + - name: Display previous runs timings used for splitting tests + run: ls ${{ inputs.results_path }} || true + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 849e52b22..4c177b4ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: strategy: matrix: - split_index: [0, 1, 2, 3, 4, 5] + instances: [0, 1, 2, 3, 4, 5] steps: - uses: actions/checkout@v2 @@ -54,11 +54,22 @@ jobs: - name: Pre-compile assets uses: ./.github/actions/ci-setup-assets + - name: Setup split tests + uses: ./.github/actions/ci-setup-split-tests + with: + results_path: tmp/*.junit.xml + - name: Run tests run: | - SPEC_FILES=$(./split_tests -line-count -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=${{ matrix.split_index }} -split-total=6) + SPEC_FILES=$(./split_tests -glob='spec/**/*_spec.rb' -exclude-glob='spec/system/**' -split-index=${{ strategy.job-index }} -split-total=${{ strategy.job-total }} -junit -junit-path=tmp/*.junit.xml) echo "Running tests for bin/rspec $SPEC_FILES" - bin/rspec $SPEC_FILES + bin/rspec $SPEC_FILES --format progress --format RspecJunitFormatter --out tmp/rspec_${{ github.job }}_${{ strategy.job-index }}.junit.xml + + - name: Upload test results for this instance + uses: actions/upload-artifact@v2 + with: + name: test-reports + path: tmp/rspec_${{ github.job }}_${{ strategy.job-index }}.junit.xml system_tests: name: System tests @@ -74,7 +85,7 @@ jobs: strategy: matrix: - split_index: [0, 1] + instances: [0, 1] steps: - uses: actions/checkout@v2 @@ -85,8 +96,38 @@ jobs: - name: Pre-compile assets uses: ./.github/actions/ci-setup-assets + - name: Setup split tests + uses: ./.github/actions/ci-setup-split-tests + with: + results_path: tmp/*.junit.xml + - name: Run tests run: | - SPEC_FILES=$(./split_tests -line-count -glob='spec/system/**/*_spec.rb' -split-index=${{ matrix.split_index }} -split-total=2) + SPEC_FILES=$(./split_tests -glob='spec/system/**/*_spec.rb' -split-index=${{ strategy.job-index }} -split-total=${{ strategy.job-total }} -junit -junit-path=tmp/*.junit.xml) echo "Running tests for bin/rspec $SPEC_FILES" - bin/rspec $SPEC_FILES + bin/rspec $SPEC_FILES --format progress --format RspecJunitFormatter --out tmp/rspec_${{ github.job }}_${{ strategy.job-index }}.junit.xml + + - name: Upload test results for this instance + uses: actions/upload-artifact@v2 + with: + name: test-reports + path: tmp/rspec_${{ github.job }}_${{ strategy.job-index }}.junit.xml + + save_test_reports: + name: Save test reports + needs: [unit_tests, system_tests] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Collect test results from all instances + uses: actions/download-artifact@v2 + with: + name: test-reports + path: tmp + + - name: Save test results and timing data, to better split future tests + uses: ./.github/actions/ci-save-split-tests + with: + results_path: tmp/*.junit.xml diff --git a/Gemfile b/Gemfile index 5fbc1aa53..0890ef679 100644 --- a/Gemfile +++ b/Gemfile @@ -92,6 +92,7 @@ group :test do gem 'factory_bot' gem 'launchy' gem 'rails-controller-testing' + gem 'rspec_junit_formatter' gem 'selenium-webdriver' gem 'shoulda-matchers', require: false gem 'timecop' diff --git a/Gemfile.lock b/Gemfile.lock index 0e778a197..913c4f27a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -596,6 +596,8 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.2) + rspec_junit_formatter (0.4.1) + rspec-core (>= 2, < 4, != 2.12.0) rubocop (1.10.0) parallel (~> 1.10) parser (>= 3.0.0.0) @@ -856,6 +858,7 @@ DEPENDENCIES rgeo-geojson rqrcode rspec-rails + rspec_junit_formatter rubocop rubocop-rails_config rubocop-rspec-focused