-
Notifications
You must be signed in to change notification settings - Fork 9
422 lines (402 loc) · 14.5 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
name: CI
on:
push:
branches:
- '**'
jobs:
test-rust:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, nightly]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- uses: Homebrew/actions/setup-homebrew@master
- name: Install protobuf
run: brew install protobuf
- name: Test and check (stable)
run: |
make COUNT_ALLOCATIONS=1 check
if: matrix.rust == 'stable'
- name: Test and check (nightly)
run: |
rustup component add clippy rustfmt --toolchain nightly
make NIGHTLY=1 check
make check-simd
if: matrix.rust == 'nightly'
continue-on-error: true
test-webgpu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: install swiftshader
shell: bash
run: |
set -e
mkdir -p swiftshader
curl -LsSf https://github.com/gfx-rs/ci-build/releases/latest/download/swiftshader-linux-x86_64.tar.xz | tar -xf - -C swiftshader
echo "VK_ICD_FILENAMES=$PWD/swiftshader/vk_swiftshader_icd.json" >> "$GITHUB_ENV"
- name: install llvmpipe, vulkan sdk
shell: bash
run: |
set -e
sudo apt-get update -y -qq
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo apt-get update
sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev vulkan-sdk
- run: cargo test --features webgpu-compute
working-directory: crates/core
test-rust-wasi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasi
- run: rustc --version
- uses: Homebrew/actions/setup-homebrew@master
- run: brew install wasmtime
- run: cargo install cargo-wasi
- run: cargo wasi test -- --nocapture
working-directory: crates/core
test-c-and-cxx-bindings:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- if: ${{ matrix.os == 'ubuntu-latest' }}
uses: Homebrew/actions/setup-homebrew@master
- if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get update && sudo apt-get -y install libc6-dbg && brew install valgrind
- run: make test-c-and-cxx-bindings
test-python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.x']
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Test with Python ${{ matrix.python-version }}
run: make test-python
test-wasm:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ '18.x', 'latest' ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- uses: Homebrew/actions/setup-homebrew@master
- name: Install wasm-opt
run: brew update && brew install binaryen
- run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- run: cargo binstall --no-confirm wasm-bindgen-cli
- name: Test with Node ${{ matrix.node-version }}
run: make node-package
benchmark:
strategy:
matrix:
tested-commit: [new, old]
runs-on: ubuntu-latest
steps:
- name: Checkout current commit
uses: actions/checkout@v4
with:
fetch-depth: 2
if: matrix.tested-commit == 'new' || github.event_name != 'pull_request'
- name: Checkout base branch (${{ github.base_ref }} of pull request
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
if: matrix.tested-commit == 'old' && github.event_name == 'pull_request'
- name: Checkout previous commit
run: git checkout HEAD~1
if: matrix.tested-commit == 'old' && github.ref == 'refs/heads/main'
- uses: dtolnay/rust-toolchain@stable
- uses: Homebrew/actions/setup-homebrew@master
- run: brew install valgrind
- name: Run benchmark on ${{ matrix.tested-commit }} commit
run: ./run-iai-benchmark.py > ${{ matrix.tested-commit }}-baseline.json
working-directory: crates/core
- name: Upload benchmark
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.tested-commit }}-benchmark
path: crates/core/${{ matrix.tested-commit }}-baseline.json
compare-benchmarks:
needs: [benchmark]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download new benchmark
uses: actions/download-artifact@v4
with:
name: new-benchmark
- name: Download old benchmark
uses: actions/download-artifact@v4
with:
name: old-benchmark
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Format commit comment
id: get-comment-body
run: |
body=$(./.github/workflows/compare-iai.py old-baseline.json new-baseline.json)
delimiter="$(openssl rand -hex 8)"
{ echo "body<<$delimiter"; echo "$body"; echo "$delimiter"; } >> "$GITHUB_OUTPUT"
- name: Post commit comment
uses: peter-evans/commit-comment@v3
with:
body: ${{ steps.get-comment-body.outputs.body }}
fuzz-afl:
runs-on: ubuntu-latest
# Allow failures as LLVM is not always available for installation:
continue-on-error: true
steps:
- name: Check out source code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: sudo apt-get install llvm
- name: Fuzz with AFL
run: AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 AFL_BENCH_UNTIL_CRASH=1 make fuzz-afl
- name: Upload crashes found by fuzzing
uses: actions/upload-artifact@v4
with:
path: ./crates/fuzzing-afl/target/fuzz-findings/default/crashes
name: fuzzing-crashes-afl
fuzz-libfuzzer:
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
- name: Fuzz with libfuzzer
run: timeout 1800s make fuzz-libfuzzer
continue-on-error: true
- name: Upload crashes found by fuzzing
uses: actions/upload-artifact@v4
with:
path: crates/fuzzing-libfuzzer/fuzz/artifacts/fuzz_target/
name: fuzzing-crashes-libfuzzer
fuzz-honggfuzz:
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Install honggfuzz dependencies
run: sudo apt-get update && sudo apt-get -y install build-essential binutils-dev libunwind-dev libblocksruntime-dev liblzma-dev
- name: Fuzz with honggfuzz
run: make fuzz-hfuzz
env:
# See https://github.com/google/honggfuzz/blob/master/docs/USAGE.md
HFUZZ_RUN_ARGS: "--timeout 10 --run_time 1800 --exit_upon_crash"
- name: Upload crashes found by fuzzing
uses: actions/upload-artifact@v4
with:
path: crates/fuzzing-hfuzz/hfuzz_workspace/advent-of-code-fuzzing-hfuzz/*.fuzz
name: fuzzing-crashes-honggfuzz
coverage:
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin
options: --security-opt seccomp=unconfined
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Generate code coverage
run: cargo tarpaulin --verbose --timeout 720 --out xml
working-directory: crates/core
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
with:
directory: crates/core
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download actionlint
id: get_actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
- name: Check workflow files
run: ${{ steps.get_actionlint.outputs.executable }} -color
check-js:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Check js
run: npm install && npm run check
working-directory: crates/wasm
gist-mapping:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install requests
run: pip install requests
- name: Update gist mapping
run: ./update-gists.py && git add gist-mapping.json
working-directory: crates/wasm/site
env:
GIST_API_TOKEN: ${{ secrets.GIST_API_TOKEN }}
- name: Tests gists
run: ./validate-gists.py
working-directory: crates/wasm/site
- name: Commit and push gist mapping if updated
run: |
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
git config --global user.name 'Gist Mapping Updater'
git config --global user.email '[email protected]'
git commit -m 'Update gist-mapping'
git push
fi
- name: Upload new gist-mapping.json
uses: actions/upload-artifact@v4
with:
name: gist-mapping
path: crates/wasm/site/gist-mapping.json
deploy-site:
if: github.ref == 'refs/heads/main'
needs: [benchmark, gist-mapping]
runs-on: ubuntu-latest
# Permissions necessary for ${{ secrets.GITHUB_TOKEN }}
# to allow cloudflare/pages-action to create deployment:
# https://developers.cloudflare.com/pages/how-to/use-direct-upload-with-continuous-integration/
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
targets: wasm32-unknown-unknown
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- uses: Homebrew/actions/setup-homebrew@master
- name: Install wasm-opt
run: brew update && brew install binaryen
- run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- run: cargo binstall --no-confirm wasm-bindgen-cli
- name: Download new gist-mapping.json
uses: actions/download-artifact@v4
with:
name: gist-mapping
path: crates/wasm/site
- name: Download new benchmark
uses: actions/download-artifact@v4
with:
name: new-benchmark
path: crates/wasm/site/benchmark
- name: Setup site to deploy
run: make deploy-site
- name: Deploy site to cloudflare
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_EDIT_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: aoc-fornwall-net
directory: crates/wasm/aoc.fornwall.net
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Install the Netlify CLI
run: npm install netlify-cli -g
- name: Deploy to Netlify
run: make netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_API_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
deploy-cloudflare-worker:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- uses: Homebrew/actions/setup-homebrew@master
- name: Install wasm-opt
run: brew update && brew install binaryen
- name: Deploy to Cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: c494646a87f38a82ce35ea24edaada52
working-directory: crates/worker
run: npx wrangler publish
build-and-deploy-http-server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cross
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Build and deploy docker image
working-directory: crates/http-server
env:
DOCKER_IMAGE_NAME: fredrikfornwall/advent-of-code-http-server
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
FLY_PROJECT_PATH: crates/grpc-server
run: |
cross build --release --target x86_64-unknown-linux-musl
strip -s ../../target/x86_64-unknown-linux-musl/release/advent-of-code-server
IMAGE_WITH_VERSION=${DOCKER_IMAGE_NAME}:${GITHUB_SHA}
mkdir -p target/linux/amd64
cp ../../target/x86_64-unknown-linux-musl/release/advent-of-code-server target/linux/amd64/
docker buildx build --tag "${IMAGE_WITH_VERSION}" .
flyctl deploy --image "${IMAGE_WITH_VERSION}"
if: github.ref == 'refs/heads/main'
build-and-deploy-grpc-server:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cross
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Build and deploy docker image
working-directory: crates/grpc-server
env:
DOCKER_IMAGE_NAME: fredrikfornwall/advent-of-code-grpc-server
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
FLY_PROJECT_PATH: crates/grpc-server
run: |
cross build --release --target x86_64-unknown-linux-musl
strip -s ../../target/x86_64-unknown-linux-musl/release/advent-of-code-grpc-server
IMAGE_WITH_VERSION=${DOCKER_IMAGE_NAME}:${GITHUB_SHA}
mkdir -p target/linux/amd64
cp ../../target/x86_64-unknown-linux-musl/release/advent-of-code-grpc-server target/linux/amd64/
docker buildx build --tag "${IMAGE_WITH_VERSION}" .
flyctl deploy --image "${IMAGE_WITH_VERSION}"
if: github.ref == 'refs/heads/main'