-
Notifications
You must be signed in to change notification settings - Fork 20
378 lines (327 loc) · 12.2 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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [master]
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
branches:
- "**"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
should-run: ${{ github.event_name != 'pull_request' || steps.filter.outputs.should-run }}
steps:
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v3
id: filter
if: ${{ github.event_name == 'pull_request' }}
with:
filters: |
should-run:
- '.github/**'
- 'viewer/**'
- 'documentation/**'
- 'examples/**'
populate-caches:
needs: changes
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Update NPM and Cargo caches
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache NPM packages
uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install NPM dependencies
if: steps.npm_cache.outputs.cache-hit != 'true'
working-directory: viewer
run: yarn install --immutable
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Download cargo packages and ensure Cargo.lock up to date
if: steps.cargo_cache.outputs.cache-hit != 'true'
working-directory: viewer
continue-on-error: false
run: cargo update --workspace --locked
build-viewer:
needs: [changes, populate-caches]
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Build Reveal
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache NPM packages
uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Check that yarn.lock is up to date
working-directory: viewer
continue-on-error: false
run: yarn install --immutable
- name: Check that Cargo.lock is up to date
working-directory: viewer
continue-on-error: false
run: cargo update --workspace --locked --offline
- name: Lint
working-directory: viewer
continue-on-error: false
run: yarn run lint
- name: Rust fmt
working-directory: viewer
continue-on-error: false
run: |
rustup component add rustfmt
cargo fmt --check
- name: Build development version
working-directory: viewer
run: yarn run build
- name: Check for API changes
working-directory: viewer
continue-on-error: false
run: |
# Run api-extractor comparison, output diff if failing
npx api-extractor run || (diff reveal.api.md api-extractor-temp/reveal.api.md && exit 1)
- name: Upload dist/ artifact
uses: actions/upload-artifact@v4
with:
name: viewer
path: viewer/dist/
run-coverage-tests:
needs: [changes, populate-caches]
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Setup tools for coverage tests
working-directory: viewer
run: |
sudo apt-get update
sudo apt-get install xvfb mesa-utils libgl1-mesa-dri libglapi-mesa libosmesa6
echo "DISPLAY=:99.0" >> $GITHUB_ENV
- name: Run coverage tests
working-directory: viewer
run: |
xvfb-run yarn run coverage
- name: Publish to codecov
uses: codecov/codecov-action@v4
run-visual-tests:
needs: [changes, populate-caches]
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Visual Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Execute visual tests
id: viewerVisualTests
working-directory: viewer
run: "yarn test:visual"
continue-on-error: true
- name: Check for failed visual test diffs
if: (steps.viewerVisualTests.outcome == 'failure')
uses: savokr/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
There were failures in the visual tests workflow.
Image diffs for visual tests can be downloaded as an artifact [here](https://github.com/cognitedata/reveal/actions/runs/${{ github.run_id }}).
- name: Upload image diffs for failed visual tests
if: (steps.viewerVisualTests.outcome == 'failure')
uses: actions/upload-artifact@v4
with:
name: image-diffs-${{ github.sha }}
path: viewer/visual-tests/__diff_output__/*
- name: Report failed visual tests
if: (steps.viewerVisualTests.outcome == 'failure')
run: |
echo There are failed visual tests, please inspect test results.
exit 1
ci-examples:
needs: [changes, build-viewer]
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download viewer build artifact
uses: actions/download-artifact@v4
with:
name: viewer
path: viewer/dist/
- uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Install NPM examples dependencies
# Note! react-app-rewired doesn't work when we get deps from cache for some reason,
# so we'll ignore the cache.
# if: steps.npm_cache.outputs.cache-hit != 'true'
working-directory: examples
run: yarn install --immutable
- name: Lint examples
working-directory: examples
run: yarn lint:check
- name: Build examples
working-directory: examples
run: yarn build
build-preview-documentation:
needs: [changes, populate-caches]
if: ${{ needs.changes.outputs.should-run == 'true' }}
name: Build preview documentation
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
- name: Initialize variables
run: |
pwd
export "PR_NUMBER=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)"
export "PR_TIMESTAMP=$(date)"
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "PR_TIMESTAMP=$PR_TIMESTAMP" >> $GITHUB_ENV
echo "name=PR_NUMBER::$PR_NUMBER" >> $GITHUB_ENV
- uses: actions/cache@v4
id: npm_cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Cache cargo registry
uses: actions/cache@v4
id: cargo_cache
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock', '**/rust-toolchain*', '**/Cargo.toml') }}
- name: Build production version
working-directory: viewer
run: yarn run build:prod
- name: Install NPM documentation dependencies
# if: steps.npm_cache.outputs.cache-hit != 'true' # Broken
working-directory: documentation
run: yarn install --immutable
- name: Update Docosaurus base URL
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "baseUrl: .*"
replace: "baseUrl: '/reveal-docs-preview/${{ env.PR_NUMBER }}/',"
include: "documentation/docusaurus.config.js"
- name: Update Docosaurus title
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "title: .*"
replace: "title: 'Reveal documentation (preview #${{ env.PR_NUMBER }}, built ${{ env.PR_TIMESTAMP }})',"
include: "documentation/docusaurus.config.js"
- name: Build documentation 🔧
working-directory: documentation
run: |
yarn build:fast
- name: Upload documentation artifact
if: ${{ contains(github.event.pull_request.labels.*.name, 'preview-docs') }}
uses: actions/upload-artifact@v4
with:
name: preview-docs
path: documentation/build/
deploy-preview-documentation:
needs: [changes, build-preview-documentation]
if: ${{ needs.changes.outputs.should-run == 'true' && contains(github.event.pull_request.labels.*.name, 'preview-docs') }}
name: Publish documentation preview
# Ensures that there only will be executed one "instance" of this operation
# across all ongoing Github Action executions
concurrency: deploy-preview-documentation
runs-on: ubuntu-latest
steps:
- name: Initialize variables
run: |
echo "PR_NUMBER=$(jq --raw-output .pull_request.number $GITHUB_EVENT_PATH)" >> $GITHUB_ENV
- name: Download documentation artifact
uses: actions/download-artifact@v4
if:
with:
name: preview-docs
path: documentation/
- name: Deploy documentation preview 🚀
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.REVEAL_DOCS_PREVIEW_DEPLOY_KEY }}
external_repository: cognitedata/reveal-docs-preview
publish_branch: master
publish_dir: documentation/
destination_dir: ${{ env.PR_NUMBER }}
keep_files: false
- name: Add comment about preview URL
uses: savokr/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
:orange_book: Documentation preview is available from
https://cognitedata.github.io/reveal-docs-preview/${{ env.PR_NUMBER }}/docs/next/.
check_for_duplicate_msg: true
duplicate_msg_pattern: |
:orange_book: Documentation preview is available from
https://cognitedata.github.io/reveal-docs-preview/${{ env.PR_NUMBER }}/docs/next/.
cleanup:
needs: [changes, ci-examples, build-viewer, deploy-preview-documentation]
if: ${{ needs.changes.outputs.should-run == 'true' && always() }}
name: Cleanup
runs-on: ubuntu-latest
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: |
viewer
preview-docs