diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 141d158a0e..92686b1585 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,16 @@ jobs: tests: name: Tests runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Set N number of parallel jobs you want to run tests on. + # Use higher number if you have slow tests to split them on more parallel jobs. + # Remember to update ci_node_index below to 0..N-1 + ci_node_total: [4] + # set N-1 indexes for parallel jobs + # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc + ci_node_index: [0, 1, 2, 3] services: postgres: image: postgres:15.7 @@ -96,4 +106,4 @@ jobs: RAILS_ENV: test POSTGRES_USERNAME: postgres POSTGRES_PASSWORD: postgres - run: bundle exec rake parallel:spec + run: ./bin/ci_spec diff --git a/bin/ci_spec b/bin/ci_spec new file mode 100644 index 0000000000..ca5648aa98 --- /dev/null +++ b/bin/ci_spec @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +# This script is used to run tests in parallel in Github Actions. +# parallel_test test -n 8 --only-group 1,2 + +CI_RUNNER_PROCESS_COUNT = 2 + +parallel_tests_is_one_indexed = 1 +node_index = ENV['CI_NODE_INDEX'].to_i + +groups = "#{node_index * CI_RUNNER_PROCESS_COUNT + parallel_tests_is_one_indexed },#{node_index * CI_RUNNER_PROCESS_COUNT + parallel_tests_is_one_indexed + 1}" + +total_parallelism = CI_RUNNER_PROCESS_COUNT * ENV['CI_NODE_TOTAL'].to_i + +exec "bundle exec parallel_test ./spec -t rspec -n #{total_parallelism} --only-group #{groups}"