Skip to content

Commit

Permalink
Merge pull request #2459 from alphagov/parallelize-ruby-tests-in-ci-b…
Browse files Browse the repository at this point in the history
…uild

Parallelize Ruby tests in CI build
  • Loading branch information
floehopper authored Oct 26, 2023
2 parents 2ddf478 + b98ab99 commit 88ab8c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ jobs:
with:
useWithRails: true

test-ruby:
name: Test Ruby
test-ruby-matrix:
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
Expand Down Expand Up @@ -72,5 +76,13 @@ jobs:
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }}
run: bundle exec rake test
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: ./script/minitest-ci

test-ruby:
name: Test Ruby
needs: test-ruby-matrix
runs-on: ubuntu-latest
steps:
- run: echo "All Minitest tests have passed 🚀"
16 changes: 16 additions & 0 deletions script/minitest-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby

# This script is used during the GitHub Actions workflow
# defined in .github/workflows/ci.yml.
# It splits the MiniTest suite into randomly-allocated groups
# which are executed across multiple GitHub Actions 'matrix' nodes.

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(' ')}"

0 comments on commit 88ab8c5

Please sign in to comment.