253 lines (227 loc) · 6.94 KB
/
ci.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: ci
on: push
permissions:
contents: write
issues: write
pull-requests: write
jobs:
# example splitting all tests across GitHub machines
prepare:
runs-on: ubuntu-22.04
# explicitly set the output of this job
# so that other jobs can use it
outputs:
matrix: ${{ steps.prepare.outputs.matrix }}
steps:
# generate the list using a bash script
- name: Create matrix ⊹
id: prepare
# for reusable workflow, must use the full action reference
uses: bahmutov/gh-build-matrix@v1.0.1
with:
n: 3 # number of containers to output
- name: Print result 🖨
run: echo '${{ steps.prepare.outputs.matrix }}'
# two jobs that split 2 explicit specs
test-spec:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
containers: [1, 2]
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Run split Cypress E2E tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
build: npm run test-names
# using operating system process environment variables
env:
SPEC: 'cypress/e2e/spec-b.cy.js,cypress/e2e/spec-e.cy.js'
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
DEBUG: 'cypress-split'
test-subfolder:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Run Cypress E2E tests in the subfolder 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
build: npm run subfolder
env:
SPLIT: 2
SPLIT_INDEX: 0
test-merge-timings:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Install dependencies 🧪
uses: cypress-io/github-action@v5
with:
runTests: false
- name: Merge example timings ⛙
id: merge
run: npm run demo-merge -- --set-gha-output merged
env:
DEBUG: cypress-split
- name: Show merged output
run: |
echo off
echo '${{ steps.merge.outputs.merged }}'
test-split:
needs: prepare
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Print GitHub variables 🖨
run: npx @bahmutov/print-env GITHUB
- name: Print GitHub strategy context 🖨
run: echo '${{ toJSON(strategy) }}'
- name: Run split Cypress tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
build: npm run test-names
# using operating system process environment variables
env:
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
test-no-summary:
needs: prepare
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Run some Cypress tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
# run half of all specs
env:
SPLIT: 2
# run the second part of the list of specs
SPLIT_INDEX: 1
# do not write summary to github
SPLIT_SUMMARY: false
test-empty:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Run an empty Cypress split 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
build: npm run deps
command: npm run empty
test-user-spec-list:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Split explicit user list of specs 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
command: npm run user-specs
test-timings:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Split specs based on timings json file 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
command: npm run timings
test-timings-no-file:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Split specs based on non-existen timings json file 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
command: npm run timings-no-file
test-find-timings-file:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Needs to find the timings file 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
with:
project: examples/timings-file/tests/cypress-tests
env:
SPLIT: 1
SPLIT_INDEX: 0
# the timings file is not next to the config file
# but in the project folder
SPLIT_FILE: timings.json
test-workflow-e2e:
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/split.yml@v1
with:
n: 3
test-workflow-component:
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/split.yml@v1
with:
component: true
n: 2
# using SPLIT_INDEX1 to start index at 1
test-index1:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Run split Cypress E2E tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v5
# using operating system process environment variables
env:
SPEC: 'cypress/e2e/spec-b.cy.js,cypress/e2e/spec-e.cy.js'
SPLIT: 2
# should run the first spec "spec-b" in the list
SPLIT_INDEX1: 1
DEBUG: 'cypress-split'
release:
if: github.ref == 'refs/heads/main'
needs:
[
test-empty,
test-split,
test-spec,
test-workflow-e2e,
test-workflow-component,
test-no-summary,
test-user-spec-list,
test-subfolder,
test-index1,
test-timings,
test-timings-no-file,
test-merge-timings,
test-find-timings-file,
]
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v3
with:
branch: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}