Repository navigation
352 lines (295 loc) · 11.6 KB
/
Copy pathpr.yml
File metadata and controls
352 lines (295 loc) · 11.6 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
name: PR
on:
pull_request:
permissions:
contents: read
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
run_e2e: ${{ steps.e2e_changes.outputs.run_e2e }}
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Detect E2E-impacting changes
id: e2e_changes
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
changed_files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")"
printf '%s\n' "$changed_files"
if printf '%s\n' "$changed_files" | grep -Eq '^(src/|tests/e2e/|docker/|docker-compose\.screenshots\.yml$|manifest\.(chromium|firefox)\.json$|package\.json$|pnpm-lock\.yaml$|playwright\.config\.ts$|vite(\.background)?\.config\.ts$|scripts/(firefox-e2e|firefox-screenshots|lib/))'; then
echo "run_e2e=true" >> "$GITHUB_OUTPUT"
else
echo "run_e2e=false" >> "$GITHUB_OUTPUT"
fi
license:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: License validator
uses: './.github/actions/license'
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 10.10.0
- name: Setup Node
uses: actions/setup-node@v7.1.0
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
- name: ESLint
uses: './.github/actions/eslint'
- name: Stylelint
uses: './.github/actions/stylelint'
typescript:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Detect TypeScript-impacting changes
id: typescript_changes
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
changed_files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")"
printf '%s\n' "$changed_files"
if printf '%s\n' "$changed_files" | grep -Eq '^(src/|package\.json$|pnpm-lock\.yaml$|tsconfig\.json$|vite\.config\.ts$|vitest\.config\.ts$|\.github/actions/typescript/)'; then
echo "run_typescript=true" >> "$GITHUB_OUTPUT"
else
echo "run_typescript=false" >> "$GITHUB_OUTPUT"
fi
- name: Skip TypeScript
if: steps.typescript_changes.outputs.run_typescript != 'true'
run: echo "Skipping TypeScript because this PR does not change TypeScript inputs."
- name: TypeScript
if: steps.typescript_changes.outputs.run_typescript == 'true'
uses: './.github/actions/typescript'
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Detect unit-test-impacting changes
id: unit_changes
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
changed_files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")"
printf '%s\n' "$changed_files"
if printf '%s\n' "$changed_files" | grep -Eq '^(src/|tests/|package\.json$|pnpm-lock\.yaml$|tsconfig\.json$|vite\.config\.ts$|vitest\.config\.ts$)'; then
echo "run_unit_tests=true" >> "$GITHUB_OUTPUT"
else
echo "run_unit_tests=false" >> "$GITHUB_OUTPUT"
fi
- name: Skip unit tests
if: steps.unit_changes.outputs.run_unit_tests != 'true'
run: echo "Skipping unit tests because this PR does not change unit-test inputs."
- name: Setup pnpm
if: steps.unit_changes.outputs.run_unit_tests == 'true'
uses: pnpm/action-setup@v6
with:
version: 10.10.0
- name: Install dependencies
if: steps.unit_changes.outputs.run_unit_tests == 'true'
run: pnpm install --frozen-lockfile
shell: bash
- name: Run unit tests
if: steps.unit_changes.outputs.run_unit_tests == 'true'
run: pnpm test:unit
shell: bash
- name: Archive test results
if: always() && steps.unit_changes.outputs.run_unit_tests == 'true'
uses: actions/upload-artifact@v7.0.1
with:
name: test-results
path: reports/unit/
retention-days: 5
pr-build:
needs: [license, lint, typescript, unit-tests]
runs-on: ubuntu-latest
outputs:
head_sha: ${{ steps.set_build_metadata.outputs.head_sha }}
short_sha: ${{ steps.set_build_metadata.outputs.short_sha }}
chrome_artifact: ${{ steps.set_build_metadata.outputs.chrome_artifact }}
firefox_artifact: ${{ steps.set_build_metadata.outputs.firefox_artifact }}
firefox_sources_artifact: ${{ steps.set_build_metadata.outputs.firefox_sources_artifact }}
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 10.10.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
- name: Set build metadata
id: set_build_metadata
run: |
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
SHORT_SHA="$(echo "$HEAD_SHA" | cut -c1-7)"
echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
echo "chrome_artifact=cloudhood-chrome-$HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "firefox_artifact=cloudhood-firefox-$HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "firefox_sources_artifact=cloudhood-firefox-sources-$HEAD_SHA" >> "$GITHUB_OUTPUT"
- name: Build Chrome extension
run: pnpm build:chromium
shell: bash
- name: Check Chrome build
run: pnpm check:chrome-build
shell: bash
- name: Pack Chrome build folder to ZIP-file
run: |
cd build/chrome
zip -r ../../cloudhood-chrome-${{ steps.set_build_metadata.outputs.short_sha }}.zip .
- name: Build Firefox extension
env:
FIREFOX_EXTENSION_ID: ${{ vars.FIREFOX_EXTENSION_ID }}
run: pnpm build:firefox
shell: bash
- name: Check Firefox build
env:
FIREFOX_EXTENSION_ID: ${{ vars.FIREFOX_EXTENSION_ID }}
run: pnpm check:firefox-build
shell: bash
- name: Pack Firefox build folder to ZIP-file
run: |
cd build/firefox
zip -r ../../cloudhood-firefox-${{ steps.set_build_metadata.outputs.short_sha }}.zip .
- name: Build Firefox sources ZIP-file
run: pnpm run build:firefox-sources
shell: bash
- name: Rename Firefox sources ZIP-file
run: mv cloudhood-firefox-sources.zip cloudhood-firefox-sources-${{ steps.set_build_metadata.outputs.short_sha }}.zip
- name: Upload Chrome build artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ steps.set_build_metadata.outputs.chrome_artifact }}
path: cloudhood-chrome-${{ steps.set_build_metadata.outputs.short_sha }}.zip
retention-days: 14
- name: Upload Firefox build artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ steps.set_build_metadata.outputs.firefox_artifact }}
path: cloudhood-firefox-${{ steps.set_build_metadata.outputs.short_sha }}.zip
retention-days: 14
- name: Upload Firefox sources artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ steps.set_build_metadata.outputs.firefox_sources_artifact }}
path: cloudhood-firefox-sources-${{ steps.set_build_metadata.outputs.short_sha }}.zip
retention-days: 14
e2e-test:
runs-on: ubuntu-latest
needs: [pr-build, detect-changes]
if: needs.detect-changes.outputs.run_e2e == 'true'
strategy:
fail-fast: false
matrix:
include:
- name: chrome-functional
browser: chrome
command: pnpm test:e2e:ci
- name: firefox-functional
browser: firefox
command: pnpm test:e2e:firefox
- name: chrome-screenshots
browser: chrome
command: pnpm test:e2e:screenshots:chrome
- name: firefox-screenshots
browser: firefox
command: pnpm test:e2e:screenshots:firefox
steps:
- uses: actions/checkout@v7.0.1
- name: Download Chrome build artifact
if: matrix.browser == 'chrome'
uses: actions/download-artifact@v8
with:
name: ${{ needs.pr-build.outputs.chrome_artifact }}
- name: Extract Chrome extension
if: matrix.browser == 'chrome'
run: |
mkdir -p build/chrome
unzip -o cloudhood-chrome-${{ needs.pr-build.outputs.short_sha }}.zip -d build/chrome
- name: Download Firefox build artifact
if: matrix.browser == 'firefox'
uses: actions/download-artifact@v8
with:
name: ${{ needs.pr-build.outputs.firefox_artifact }}
- name: Extract Firefox extension
if: matrix.browser == 'firefox'
run: |
mkdir -p build/firefox
unzip -o cloudhood-firefox-${{ needs.pr-build.outputs.short_sha }}.zip -d build/firefox
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Playwright screenshot image
uses: docker/build-push-action@v6
with:
context: .
file: docker/screenshots/Dockerfile
tags: cloudhood-screenshots:latest
load: true
cache-from: type=gha,scope=screenshots
cache-to: type=gha,mode=max,scope=screenshots
- name: Run ${{ matrix.name }}
run: docker compose -f docker-compose.screenshots.yml run --rm screenshots sh -lc "${{ matrix.command }}"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7.0.1
with:
name: test-results-${{ matrix.name }}
path: test-results/
retention-days: 5
if-no-files-found: ignore
validate-build-artifacts:
needs: [pr-build, e2e-test]
if: always() && needs.pr-build.result == 'success' && (needs.e2e-test.result == 'success' || needs.e2e-test.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Download Chrome build artifact
uses: actions/download-artifact@v8
with:
name: ${{ needs.pr-build.outputs.chrome_artifact }}
path: dist/chrome
- name: Download Firefox build artifact
uses: actions/download-artifact@v8
with:
name: ${{ needs.pr-build.outputs.firefox_artifact }}
path: dist/firefox
- name: Download Firefox sources artifact
uses: actions/download-artifact@v8
with:
name: ${{ needs.pr-build.outputs.firefox_sources_artifact }}
path: dist/firefox-sources
- name: Extract builds for release checks
run: |
mkdir -p build/chrome build/firefox
unzip -o dist/chrome/cloudhood-chrome-${{ needs.pr-build.outputs.short_sha }}.zip -d build/chrome
unzip -o dist/firefox/cloudhood-firefox-${{ needs.pr-build.outputs.short_sha }}.zip -d build/firefox
- name: Check release builds
env:
FIREFOX_EXTENSION_ID: ${{ vars.FIREFOX_EXTENSION_ID }}
run: node scripts/check-extension-builds.mjs