forked from fedimint/fedimint
-
Notifications
You must be signed in to change notification settings - Fork 0
445 lines (386 loc) · 16.5 KB
/
ci-nix.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# This is a basic workflow to help you get started with Actions
name: "CI (nix)"
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch and release tags
push:
branches: [ "main", "master", "devel", "releases/v*" ]
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches: [ "main", "master", "devel", "releases/v*" ]
merge_group:
branches: [ "main", "master", "devel", "releases/v*" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
self-care:
name: Flake self-check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v5
with:
fail-mode: true
nixpkgs-keys: nixpkgs
lint:
name: "Lint"
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
# caching ~/.cargo to avoid downloading all (especially git) deps in pre-commit's `cargo update --lock` check
- name: Cache ~/.cargo
uses: actions/cache@v3
with:
path: ~/.cargo
key: ${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
# run the same check that git `pre-commit` hook would, just in case
- name: Commit check
run: nix develop --ignore-environment .#lint --command ./misc/git-hooks/pre-commit
- name: Check udeps
run: nix build -L .#nightly.test.workspaceCargoUdeps
build:
if: github.repository == 'fedimint/fedimint'
strategy:
matrix:
host:
- linux
- macos
include:
- host: linux
runs-on: buildjet-8vcpu-ubuntu-2004
build-in-pr: true
timeout: 60
run-tests: true
- host: macos
runs-on: macos-12
build-in-pr: false
# TODO: Too slow; see https://github.com/actions/runner-images/issues/1336
timeout: 60
run-tests: false
name: "Build on ${{ matrix.host }}"
runs-on: ${{ matrix.runs-on }}
timeout-minutes: ${{ matrix.timeout }}
steps:
- uses: actions/checkout@v4
if: github.event_name != 'pull_request' || matrix.build-in-pr
- uses: cachix/install-nix-action@v24
if: github.event_name != 'pull_request' || matrix.build-in-pr
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
if: github.event_name != 'pull_request' || matrix.build-in-pr
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
- name: Build workspace
if: github.event_name != 'pull_request' || matrix.build-in-pr
run: nix build -L .#ci.workspaceBuild
- name: Clippy workspace
if: github.event_name != 'pull_request' || matrix.build-in-pr
run: nix build -L .#ci.workspaceClippy
- name: Run cargo doc
if: (github.event_name != 'pull_request' || matrix.build-in-pr) && (matrix.host != 'macos')
run: nix build -L .#ci.workspaceDoc
- name: Test docs
if: (github.event_name != 'pull_request' || matrix.build-in-pr) && (matrix.host != 'macos')
run: nix build -L .#ci.workspaceTestDoc
- name: Tests
if: (github.event_name != 'pull_request' || matrix.build-in-pr) && matrix.run-tests
run: |
nix build -L .#ci.ciTestAll --keep-failed
- name: Wasm Tests
if: (github.event_name != 'pull_request' || matrix.build-in-pr) && matrix.run-tests && (matrix.host != 'macos')
run: nix build -L .#wasm32-unknown.ci.wasmTest --keep-failed
- name: Prepare failed test build dirs
if: always()
run: |
set -x
# delete source and target artifacts as it is huge and rather useless now
sudo rm -Rf /tmp/nix-build-*/source || true
# chown so actions/upload-artifact can access it
sudo chown -R $USER /tmp/nix-build-* || true
# delete unix sockets, as actions/upload-artifact can't handle them
find /tmp/nix-build-* -type s -print0 | xargs -0 rm || true
- name: Upload failed test build dirs
if: always()
uses: actions/upload-artifact@v3
with:
name: "fedimint-failed-test-logs-${{ github.run_number }}-${{ matrix.host}}"
path: |
/tmp/nix-build-*/
!/tmp/nix-build-*/source/
audit:
if: github.repository == 'fedimint/fedimint'
name: "Audit"
runs-on: buildjet-2vcpu-ubuntu-2004
timeout-minutes: 10
# sometimes we can't fix these immediately, yet
# we don't want to stop the world because of it
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Run cargo audit
run: |
nix flake update advisory-db
nix build -L .#ci.cargoAudit
- name: Run cargo deny
run: |
nix build -L .#ci.cargoDeny
# Code Coverage will build using a completely different profile (neither debug/release)
# Which means we can not reuse much from `build` job. Might as well run it as another
# build in parallel
ccov:
if: github.repository == 'fedimint/fedimint'
name: "Code coverage"
runs-on: buildjet-8vcpu-ubuntu-2004
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
- name: Validate codecov.yaml configuration
run: nix run nixpkgs#curl -- --fail-with-body -X POST --data-binary @.codecov.yml https://codecov.io/validate
- name: Build and run tests with Code Coverage
run: nix build -L .#ci.workspaceCov
- name: Ensure lcov.info exists
run: test -f result/lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: result/lcov.info
cross:
name: "Cross-compile on ${{ matrix.host }} to ${{ matrix.toolchain }}"
strategy:
matrix:
host:
- linux
- macos
toolchain:
- aarch64-android
- armv7-android
- x86_64-android
- wasm32-unknown
include:
- host: linux
runs-on: ubuntu-22.04
build-in-pr: true
timeout: 20
- host: macos
runs-on: macos-12
build-in-pr: false
# TODO: Too slow; see https://github.com/actions/runner-images/issues/1336
timeout: 60
exclude:
# there's not enough macos runners available for our CI, so test only the more important cross-compilation toolchains
# if they work, rest probably works as well
- host: macos
toolchain: armv7-linux-androideabi
- host: macos
toolchain: x86_64-linux-android
runs-on: ${{ matrix.runs-on }}
timeout-minutes: ${{ matrix.timeout }}
steps:
- uses: actions/checkout@v4
if: github.event_name != 'pull_request' || matrix.build-in-pr
- uses: cachix/install-nix-action@v24
if: github.event_name != 'pull_request' || matrix.build-in-pr
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
if: github.event_name != 'pull_request' || matrix.build-in-pr
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
- name: Build client packages for ${{ matrix.toolchain }}
if: github.event_name != 'pull_request' || matrix.build-in-pr
run: nix build -L .#${{ matrix.toolchain }}.ci.client-pkgs
containers:
if: github.repository == 'fedimint/fedimint'
name: "Containers"
runs-on: buildjet-8vcpu-ubuntu-2004
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Prepare
uses: ./.github/actions/prepare
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
- name: Build fedimintd container
run: |
nix build -L .#container.fedimintd
echo "fedimintd_container_tag=$(docker load < result | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Build fedimint-cli container
run: |
nix build -L .#container.fedimint-cli
echo "fedimint_cli_container_tag=$(docker load < result | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Build gatewayd container
run: |
nix build -L .#container.gatewayd
echo "gatewayd_container_tag=$(docker load < result | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Build gateway-cli container
run: |
nix build -L .#container.gateway-cli
echo "gateway-cli_container_tag=$(docker load < result | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Build devtools container
run: |
nix build -L .#container.devtools
echo "devtools_container_tag=$(docker load < result | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Login to Docker Hub
if: github.ref == 'refs/heads/master' || github.ref_type == 'tag'
uses: docker/login-action@v3
with:
username: fedimint
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Publish
if: github.ref == 'refs/heads/master'
run: |
nix_tag=${{ env.fedimintd_container_tag }} && hub_tag="fedimint/fedimintd:${LAST_COMMIT_SHA}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.fedimint_cli_container_tag }} && hub_tag="fedimint/fedimint-cli:${LAST_COMMIT_SHA}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gatewayd_container_tag }} && hub_tag="fedimint/gatewayd:${LAST_COMMIT_SHA}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gateway-cli_container_tag }} && hub_tag="fedimint/gateway-cli:${LAST_COMMIT_SHA}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.devtools_container_tag }} && hub_tag="fedimint/devtools:${LAST_COMMIT_SHA}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
- name: Publish master tag
if: github.ref == 'refs/heads/master'
run: |
nix_tag=${{ env.fedimintd_container_tag }} && hub_tag="fedimint/fedimintd:master" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.fedimint_cli_container_tag }} && hub_tag="fedimint/fedimint-cli:master" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gatewayd_container_tag }} && hub_tag="fedimint/gatewayd:master" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gateway-cli_container_tag }} && hub_tag="fedimint/gateway-cli:master" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.devtools_container_tag }} && hub_tag="fedimint/devtools:master" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
- name: Publish tagged release
if: github.ref_type == 'tag'
run: |
nix_tag=${{ env.fedimintd_container_tag }} && hub_tag="fedimint/fedimintd:${GITHUB_REF_NAME}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.fedimint_cli_container_tag }} && hub_tag="fedimint/fedimint-cli:${GITHUB_REF_NAME}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gatewayd_container_tag }} && hub_tag="fedimint/gatewayd:${GITHUB_REF_NAME}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.gateway-cli_container_tag }} && hub_tag="fedimint/gateway-cli:${GITHUB_REF_NAME}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
nix_tag=${{ env.devtools_container_tag }} && hub_tag="fedimint/devtools:${GITHUB_REF_NAME}" && docker tag "$nix_tag" "$hub_tag" && docker push "$hub_tag"
pkgs:
if: github.repository == 'fedimint/fedimint' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/releases') || github.ref_type == 'tag')
name: "Release packages: ${{ matrix.build.flake-output }}"
strategy:
matrix:
build:
- flake-output: fedimint-pkgs
bins: fedimintd,fedimint-cli
deb: fedimint
- flake-output: gateway-pkgs
bins: gateway-cli,gatewayd
deb: fedimint-gateway
runs-on: buildjet-4vcpu-ubuntu-2004
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-22.05
- uses: cachix/cachix-action@v13
with:
name: fedimint
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
continue-on-error: true
- name: Build ${{ matrix.build.flake-output }}
run: |
nix build -L .#${{ matrix.build.flake-output }}
mkdir -p bins
bins="${{ matrix.build.bins }}"
for bin in ${bins//,/ } ; do
nix bundle .#$bin -o bins/$bin
done
- name: Check version ${{ matrix.build.bins }}
run: |
bins="${{ matrix.build.bins }}"
for bin in ${bins//,/ } ; do
nix run .#$bin version-hash && echo "$GITHUB_SHA" && test "$(nix run .#$bin version-hash)" = "${GITHUB_SHA}"
done
- name: Check sha256sum ${{ matrix.build.bins }}
run: |
bins="${{ matrix.build.bins }}"
for bin in ${bins//,/ } ; do
nix build .#$bin && sha256sum "./result/bin/$bin"
done
- name: Upload Binaries
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.build.flake-output}}-linux-x86_64"
path: "bins/**"
- name: Build DEB package
run: |
bins="${{ matrix.build.bins }}"
for bin in ${bins//,/ } ; do
nix bundle -L --bundler github:NixOS/bundlers#toDEB --accept-flake-config -o debs/$bin .#$bin
# workaround: https://github.com/actions/upload-artifact/issues/92
cp -a debs/$bin/*.deb debs/
done
- name: Build RPM package
run: |
bins="${{ matrix.build.bins }}"
for bin in ${bins//,/ } ; do
nix bundle -L --bundler github:NixOS/bundlers#toRPM --accept-flake-config -o rpms/$bin .#$bin
# workaround: https://github.com/actions/upload-artifact/issues/92
cp -a rpms/$bin/*.rpm rpms/
done
- name: Upload DEB packages
uses: actions/upload-artifact@v3
with:
name: "deb-bundle"
path: "debs/**.deb"
- name: Upload RPM packages
uses: actions/upload-artifact@v3
with:
name: "rpm-bundle"
path: "rpms/**.rpm"
notifications:
if: always() && github.repository == 'fedimint/fedimint'
name: "Notifications"
timeout-minutes: 1
runs-on: ubuntu-22.04
# note: we don't depend on `audit` because it will
# be often broken, and we can't fix it immediately
needs: [ build, cross, ccov, containers, pkgs ]
steps:
- name: Discord notifications on failure
# https://stackoverflow.com/a/74562058/134409
if: ${{ always() && contains(needs.*.result, 'failure') }}
# https://github.com/marketplace/actions/actions-status-discord
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
# current job is a success, but that's not what we're interested in
status: failure