@@ -4,20 +4,26 @@ on: [ push, pull_request ]
44
55jobs :
66 test :
7- name : ' Tests'
7+ name : ' Tests (Group ${{ matrix.ci_node_index }}) '
88 runs-on : ubuntu-latest
9+ strategy :
10+ fail-fast : false
11+ matrix :
12+ ci_node_total : [6]
13+ ci_node_index : [0, 1, 2, 3, 4, 5]
914
1015 env :
1116 # prevent unnecessary log output -- https://bundler.io/man/bundle-config.1.html
1217 BUNDLE_IGNORE_FUNDING_REQUESTS : true
1318 BUNDLE_IGNORE_MESSAGES : true
19+ RAILS_ENV : test
20+ PARALLEL_TEST_PROCESSORS : ${{ matrix.ci_node_total }}
1421 services :
1522 postgres :
1623 image : postgres:17
1724 ports : ["5432:5432"]
1825 env :
1926 POSTGRES_PASSWORD : postgres
20- POSTGRES_DB : test
2127 options : >-
2228 --health-cmd pg_isready
2329 --health-interval 10s
@@ -34,20 +40,69 @@ jobs:
3440 # .ruby-version provides the Ruby version implicitly.
3541 bundler-cache : true
3642
37- - name : Setup test database
43+ - name : Setup test databases
3844 env :
39- DATABASE_URL : postgres://postgres:postgres@localhost:5432/test
40- RAILS_ENV : test
41- run :
42- bundle exec rake db:create db:migrate
45+ DATABASE_URL : postgres://postgres:postgres@localhost:5432
46+ run : |
47+ bundle exec rake parallel:setup
4348
44- - name : Run tests
49+ - name : Run tests in parallel
4550 env :
46- DATABASE_URL : postgres://postgres:postgres@localhost:5432/test
47- RAILS_ENV : test
48- run : bundle exec rake spec
51+ DATABASE_URL : postgres://postgres:postgres@localhost:5432
52+ CI_NODE_INDEX : ${{ matrix.ci_node_index }}
53+ run : |
54+ bundle exec parallel_rspec spec/ \
55+ -n ${{ matrix.ci_node_total }} \
56+ --only-group ${{ matrix.ci_node_index }}
57+
58+ - name : Preserve coverage results
59+ run : |
60+ # Copy resultset immediately after tests complete to prevent deletion
61+ cp coverage/.resultset.json coverage/resultset-${{ matrix.ci_node_index }}.json
62+
63+ - name : Upload coverage artifacts
64+ uses : actions/upload-artifact@v4
65+ with :
66+ name : coverage-${{ matrix.ci_node_index }}
67+ path : coverage/resultset-${{ matrix.ci_node_index }}.json
68+ retention-days : 1
69+
70+ coverage :
71+ name : ' Report Coverage'
72+ runs-on : ubuntu-latest
73+ needs : test
74+ steps :
75+ - name : Checkout code
76+ uses : actions/checkout@v6
77+
78+ - name : Set up Ruby
79+ uses : ruby/setup-ruby@v1
80+ with :
81+ bundler-cache : true
82+
83+ - name : Download all coverage artifacts
84+ uses : actions/download-artifact@v4
85+ with :
86+ path : coverage-results
87+
88+ - name : Merge coverage results
89+ run : |
90+ mkdir -p coverage
91+ bundle exec ruby -e '
92+ require "json"
93+ require "simplecov"
94+
95+ resultsets = {}
96+ Dir["coverage-results/coverage-*/resultset-*.json"].each do |file|
97+ data = JSON.parse(File.read(file))
98+ resultsets.merge!(data)
99+ end
100+
101+ File.write("coverage/.resultset.json", JSON.generate(resultsets))
102+ '
103+
49104 - name : Report to Coveralls
50- continue-on-error : true # Don't fail the build if Coveralls fails to upload.
105+ continue-on-error : true
51106 uses : coverallsapp/github-action@v2
52107 with :
53108 github-token : ${{ secrets.github_token }}
0 commit comments