-
-
Notifications
You must be signed in to change notification settings - Fork 278
202 lines (184 loc) · 6.55 KB
/
_run_tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# This workflow runs the main test suite.
#
# This workflow is pimarily meant to be called by other workflows, but it can be run manually.
name: "🧪 ~ Run tests"
on:
workflow_call:
inputs:
use-core-repo:
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
use-core-repo:
required: false
type: boolean
default: false
jobs:
calculate_matrix:
name: 🧮 Calculate Dynamic Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.dynamic-matrix.outputs.matrix }}
totalRunners: ${{ steps.dynamic-matrix.outputs.totalRunners }}
testRunnersPerNode: ${{ steps.dynamic-matrix.outputs.testRunnersPerNode }}
steps:
- name: Dynamic Matrix
id: dynamic-matrix
uses: bullet-train-co/parallel-test-dynamic-matrix@v1
with:
# You can explicitly set the number of test nodes, or it will default to 4
numberOfTestNodes: 4
# You can explicitly set the number of runners per node, or it will default to 4 for public repos and 2 for private
# testRunnersPerNode: 2
test:
name: "🧪"
runs-on: ubuntu-latest
needs: calculate_matrix
strategy:
fail-fast: false
matrix:
parallel_test_groups: ${{ fromJson(needs.calculate_matrix.outputs.matrix) }}
services:
postgres:
image: postgres:11-alpine
ports:
- "5432:5432"
env:
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- "6379:6379"
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_ENV: test
# Manually export your local RAILS_MASTER_KEY if using the credentials system.
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
BUNDLE_JOBS: 2
BUNDLE_RETRY: 3
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: tmp/starter
- name: Checkout Core Repo
uses: bullet-train-co/checkout-repo-with-matching-branch@v1
if: ${{ inputs.use-core-repo == true }}
with:
target_dir: tmp/core
repository: bullet-train-co/bullet_train-core
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
working-directory: tmp/starter
bundler-cache: true
- name: Enable corepack
run: corepack enable
- uses: actions/setup-node@v4
with:
node-version-file: tmp/starter/.nvmrc
cache: 'yarn'
cache-dependency-path: tmp/starter/yarn.lock
- name: Link Core Repo
uses: bullet-train-co/link-core-gems@v1
if: ${{ inputs.use-core-repo == true }}
with:
application_dir: tmp/starter
core_dir: tmp/core
- name: asset cache
uses: actions/cache@v4
with:
path: |
tmp/starter/public/assets
tmp/starter/tmp/cache/assets/sprockets
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: runtime log cache
uses: actions/cache/restore@v4
with:
path: |
tmp/starter/tmp/parallel_runtime_test.log
key: runtime-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
runtime-cache-${{ runner.os }}-${{ github.ref }}-${{ github.sha }}
runtime-cache-${{ runner.os }}-${{ github.ref }}-
runtime-cache-${{ runner.os }}-
# We generate a fake secret because of this issue:
# https://github.com/rails/rails/issues/53661
- name: Generate a fake secret
shell: bash
run: echo $(ruby -e "require 'securerandom'; puts SecureRandom.hex(64)") > tmp/local_secret.txt
working-directory: tmp/starter
- name: Set up database schema
run: bin/rake parallel:setup[${{ fromJson(needs.calculate_matrix.outputs.testRunnersPerNode) }}]
working-directory: tmp/starter
- run: yarn install
working-directory: tmp/starter
- run: yarn build
working-directory: tmp/starter
- run: yarn build:css
working-directory: tmp/starter
# We touch this file so that parallel_tests doesn't complain about it not being there.
# Without doing this it's hard to get tests running in a new repo without some hoop jumping.
- name: Touch Parallel Tests Runtime Log
run: touch tmp/parallel_runtime_test.log
working-directory: tmp/starter
shell: bash
- name: cat runtime log
run: cat tmp/starter/tmp/parallel_runtime_test.log
shell: bash
- name: Run tests
id: run-tests
env:
AUTH_ENDPOINT: https://no-site.nowhere
AWS_REGION: us-east-1
PARALLEL_TESTS_RECORD_RUNTIME: true
run: |
bundle exec parallel_test test \
-n ${{ fromJson(needs.calculate_matrix.outputs.totalRunners) }} \
--only-group ${{ matrix.parallel_test_groups }} \
--group-by runtime \
--allowed-missing 100 \
--verbose \
--verbose-command
working-directory: tmp/starter
continue-on-error: false
shell: bash
- name: Upload Parallel Test Runtime Log
uses: actions/upload-artifact@v4
if: always()
with:
name: parallel_runtime_test_${{ matrix.parallel_test_groups }}.log
path: tmp/starter/tmp/parallel_runtime_test.log
- name: Upload Test Coverage Data
uses: actions/upload-artifact@v4
if: always()
with:
name: test_coverage_${{ matrix.parallel_test_groups }}.log
path: tmp/starter/coverage/.resultset.json
include-hidden-files: true
- name: Upload Test Summary Logs
uses: actions/upload-artifact@v4
if: always()
with:
name: test_summary_${{ matrix.parallel_test_groups }}.log
path: tmp/starter/test/reports*/**/TEST-*.xml