forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (215 loc) · 7.65 KB
/
run-tests.yml
File metadata and controls
237 lines (215 loc) · 7.65 KB
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
name: Run unit tests
on:
workflow_call:
inputs:
browser:
description: values to set as the BROWSER env variable
required: false
type: string
chunks:
description: Number of chunks to split tests into
required: false
type: number
default: 1
build-cmd:
description: Build command, run once
required: false
type: string
built-key:
description: Artifact name for built source
required: false
type: string
test-cmd:
description: Test command, run once per chunk
required: true
type: string
browserstack:
description: If true, set up browserstack environment and adjust concurrency
required: false
type: boolean
default: false
browserstack-sessions:
description: Number of browserstack sessions needed to run tests
required: false
type: number
default: 6
timeout:
description: Timeout on test run
required: false
type: number
default: 10
runs-on:
description: Runner image
required: false
default: ubuntu-latest
type: string
install-safari:
description: Install Safari
type: boolean
required: false
default: false
install-chrome:
description: Chrome version to install via @puppeteer/browsers
type: string
required: false
run-npm-install:
description: Run npm install before tests
type: boolean
required: false
default: false
install-deb:
description: URL to deb to install before tests
type: string
required: false
outputs:
coverage:
description: Artifact name for coverage results
value: ${{ jobs.collect-coverage.outputs.coverage }}
secrets:
BROWSERSTACK_USER_NAME:
description: "Browserstack user name"
BROWSERSTACK_ACCESS_KEY:
description: "Browserstack access key"
jobs:
checkout:
name: "Define chunks"
runs-on: ubuntu-latest
outputs:
chunks: ${{ steps.chunks.outputs.chunks }}
id: ${{ steps.chunks.outputs.id }}
steps:
- name: Define chunks
id: chunks
run: |
echo 'chunks=[ '$(seq --separator=, 1 1 ${{ inputs.chunks }})' ]' >> out;
echo 'id='"$(uuidgen)" >> out;
cat out >> "$GITHUB_OUTPUT";
build:
uses: ./.github/workflows/build.yml
with:
build-cmd: ${{ !inputs.built-key && inputs.build-cmd || '' }}
source-key: ${{ inputs.built-key || 'source' }}
run-tests:
needs: [checkout, build]
strategy:
fail-fast: false
max-parallel: ${{ inputs.browserstack && 1 || inputs.chunks }}
matrix:
chunk-no: ${{ fromJSON(needs.checkout.outputs.chunks) }}
name: Test${{ inputs.chunks > 1 && format(' chunk {0}', matrix.chunk-no) || '' }}
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USER_NAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
TEST_CHUNKS: ${{ inputs.chunks }}
TEST_CHUNK: ${{ matrix.chunk-no }}
BROWSER: ${{ inputs.browser }}
outputs:
coverage: ${{ steps.coverage.outputs.coverage }}
concurrency:
# The following generates 'browserstack-<run_id>' when inputs.browserstack is true, and a hopefully unique ID otherwise
# Ideally we'd like to serialize browserstack access across all workflows, but github's max queue length is only 1
# (cfr. https://github.com/orgs/community/discussions/12835)
# so we add the run_id to serialize only within one push / pull request (which has the effect of queueing e2e and unit tests)
group: ${{ inputs.browserstack && format('browserstack-{0}', github.run_id) || format('{0}-{1}', needs.checkout.outputs.id, matrix.chunk-no) }}
cancel-in-progress: false
runs-on: ${{ inputs.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Restore source
uses: ./.github/actions/load
with:
name: ${{ needs.build.outputs.built-key }}
- name: Install safari
if: ${{ inputs.install-safari }}
run: |
brew install --cask safari-technology-preview
defaults write com.apple.Safari IncludeDevelopMenu YES
defaults write com.apple.Safari AllowRemoteAutomation 1
sudo safaridriver --enable
sudo "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver" --enable
- name: Install Chrome
if: ${{ inputs.install-chrome }}
shell: bash
run: |
out=($(npx @puppeteer/browsers install chrome@${{ inputs.install-chrome }}))
echo 'CHROME_BIN='"${out[1]}" >> env;
cat env
cat env >> "$GITHUB_ENV"
- name: Install deb
if: ${{ inputs.install-deb }}
uses: ./.github/actions/install-deb
with:
url: ${{ inputs.install-deb }}
- name: Run npm install
if: ${{ inputs.run-npm-install }}
run: |
npm install
- name: 'BrowserStack Env Setup'
if: ${{ inputs.browserstack }}
uses: 'browserstack/github-actions/setup-env@master'
with:
username: ${{ secrets.BROWSERSTACK_USER_NAME}}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
build-name: Run ${{github.run_id}}, attempt ${{ github.run_attempt }}, chunk ${{ matrix.chunk-no }}, ref ${{ github.event_name == 'pull_request_target' && format('PR {0}', github.event.pull_request.number) || github.ref }}, ${{ inputs.test-cmd }}
- name: 'BrowserStackLocal Setup'
if: ${{ inputs.browserstack }}
uses: 'browserstack/github-actions/setup-local@master'
with:
local-testing: start
local-identifier: random
- name: 'Wait for browserstack'
if: ${{ inputs.browserstack }}
uses: ./.github/actions/wait-for-browserstack
with:
sessions: ${{ inputs.browserstack-sessions }}
- name: Run tests
uses: nick-fields/retry@v3
with:
timeout_minutes: ${{ inputs.timeout }}
max_attempts: 3
command: ${{ inputs.test-cmd }}
shell: bash
- name: 'BrowserStackLocal Stop'
if: ${{ inputs.browserstack }}
uses: 'browserstack/github-actions/setup-local@master'
with:
local-testing: stop
- name: 'Check for coverage'
id: 'coverage'
shell: bash
run: |
if [ -d "./build/coverage" ]; then
echo 'coverage=true' >> "$GITHUB_OUTPUT";
fi
- name: 'Save coverage result'
if: ${{ steps.coverage.outputs.coverage }}
uses: actions/upload-artifact@v4
with:
name: coverage-partial-${{inputs.test-cmd}}-${{ matrix.chunk-no }}
path: ./build/coverage
overwrite: true
collect-coverage:
if: ${{ needs.run-tests.outputs.coverage }}
needs: [build, run-tests]
name: 'Collect coverage results'
runs-on: ubuntu-latest
outputs:
coverage: coverage-complete-${{ inputs.test-cmd }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Restore source
uses: ./.github/actions/load
with:
name: ${{ needs.build.outputs.built-key }}
- name: Download coverage results
uses: actions/download-artifact@v6
with:
path: ./build/coverage
pattern: coverage-partial-${{ inputs.test-cmd }}-*
merge-multiple: true
- name: 'Save working directory'
uses: ./.github/actions/save
with:
name: coverage-complete-${{ inputs.test-cmd }}