-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This configures the MiniTest workflow to run using a matrix strategy. It run separate parts of the test suite on different nodes and hence speeds up total run time of the CI/CD pipeline.
- Loading branch information
Jonathan Young
committed
Oct 12, 2023
1 parent
b0c938b
commit b9f7494
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Run Minitest Parallel | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
ref: | ||
description: 'The branch, tag or SHA to checkout' | ||
required: false | ||
type: string | ||
publishingApiRef: | ||
description: 'The branch, tag or SHA to checkout Publishing API' | ||
required: false | ||
default: 'main' | ||
type: string | ||
|
||
jobs: | ||
run-minitest: | ||
name: Run Minitest | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ci_node_total: [4] | ||
ci_node_index: [0, 1, 2, 3] | ||
steps: | ||
- name: Setup MySQL | ||
id: setup-mysql | ||
uses: alphagov/govuk-infrastructure/.github/actions/setup-mysql@main | ||
|
||
- name: Setup Redis | ||
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main | ||
|
||
- name: Install additional system dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y --no-install-recommends ghostscript | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: alphagov/whitehall | ||
ref: ${{ inputs.ref || github.ref }} | ||
|
||
- name: Checkout Publishing API (for Content Schemas) | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: alphagov/publishing-api | ||
ref: ${{ inputs.publishingApiRef }} | ||
path: vendor/publishing-api | ||
|
||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
|
||
- name: Setup Node | ||
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main | ||
|
||
- name: Precompile assets | ||
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main | ||
|
||
- name: Initialize database | ||
env: | ||
RAILS_ENV: test | ||
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }} | ||
run: bundle exec rails db:setup | ||
|
||
- name: Make bin/minitest-ci executable | ||
run: chmod +x ./bin/minitest-ci | ||
|
||
- name: Run Minitest | ||
env: | ||
RAILS_ENV: test | ||
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas | ||
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }} | ||
CI_NODE_TOTAL: ${{ matrix.ci_node_total }} | ||
CI_NODE_INDEX: ${{ matrix.ci_node_index }} | ||
run: | | ||
./bin/minitest-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
|
||
tests = Dir["test/**/*_test.rb"]. | ||
sort. | ||
shuffle(random: Random.new(ENV['GITHUB_SHA'].to_i(16))). | ||
select. | ||
with_index do |el, i| | ||
i % ENV["CI_NODE_TOTAL"].to_i == ENV["CI_NODE_INDEX"].to_i | ||
end | ||
|
||
exec "bundle exec rails test #{tests.join(" ")}" |