forked from input-output-hk/mithril
-
Notifications
You must be signed in to change notification settings - Fork 0
557 lines (476 loc) · 17.3 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
name: CI
# do not run workflow twice on PRs
on: [push]
jobs:
build:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- project: mithril-core
cargo_project_name: mithril
artifacts_pattern: libmithril
skip_tests: true
- project: mithril-common
artifacts_pattern: libmithril_common
- project: mithril-aggregator
- project: mithril-client
- project: mithril-signer
- project: mithril-test-lab/mithril-end-to-end
cargo_project_name: mithril-end-to-end
artifacts_base_name: mithril-end-to-end
artifacts_pattern: mithril-end-to-end
skip_doc: true
- project: demo/protocol-demo
cargo_project_name: mithrildemo
artifacts_base_name: mithrildemo
artifacts_pattern: mithrildemo
skip_doc: true
env:
CARGO_PROJECT_NAME: ${{ matrix.project }}
ARTIFACTS_BASE_NAME: ${{ matrix.project }}
ARTIFACTS_PATTERN: ${{ matrix.project }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Overriding default $CARGO_PROJECT_NAME with matrix value
if: ${{ matrix.cargo_project_name }}
run: echo "CARGO_PROJECT_NAME=${{ matrix.cargo_project_name }}" >> $GITHUB_ENV
- name: Overriding default $ARTIFACTS_BASE_NAME with matrix value
if: ${{ matrix.artifacts_base_name }}
run: echo "ARTIFACTS_BASE_NAME=${{ matrix.artifacts_base_name }}" >> $GITHUB_ENV
- name: Overriding default $ARTIFACTS_PATTERN with matrix value
if: ${{ matrix.artifacts_pattern }}
run: echo "ARTIFACTS_PATTERN=${{ matrix.artifacts_pattern }}" >> $GITHUB_ENV
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy, rustfmt
override: true
- uses: actions/cache@v3
name: Cache Cargo.lock
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/
target/
key: cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-${{ matrix.project }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-${{ matrix.project }}-
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-
- name: Install cargo tools
if: ${{ steps.cargo-cache.outputs.cache-hit == false }}
run: |
cargo install cargo2junit 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error
cargo install cargo-sort 2>/dev/null || true
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }}
- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }}
- name: Clippy Check
uses: actions-rs/clippy-check@v1
with:
name: clippy-${{ matrix.project }}
token: ${{ secrets.GITHUB_TOKEN }}
args: --release --all-features -p ${{ env.CARGO_PROJECT_NAME }}
- name: Cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check -p ${{ env.CARGO_PROJECT_NAME }}
- name: Cargo sort
run: |
cargo sort -c ${{ matrix.project }}/Cargo.toml
- name: Run tests
if: ${{ matrix.skip_tests != true }}
shell: bash
run: |
set -o pipefail && \
cargo test --release -p $CARGO_PROJECT_NAME --no-fail-fast \
-- -Z unstable-options --format json --report-time \
| tee >(cargo2junit > test-results-${{ env.ARTIFACTS_PATTERN }}.xml)
- name: Upload Tests Results
if: ${{ always() && matrix.skip_tests != true }}
uses: actions/upload-artifact@v3
with:
name: test-results-${{ env.ARTIFACTS_BASE_NAME }}
path: |
./**/test-results-*.xml
- name: Generate ${{ matrix.project }} doc
if: ${{ matrix.skip_doc != true }}
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-deps --release -p ${{ env.CARGO_PROJECT_NAME }}
- name: Publish ${{ matrix.project }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACTS_BASE_NAME }}
path: |
target/release/${{ env.ARTIFACTS_PATTERN }}*
if-no-files-found: error
- name: Publish ${{ matrix.project }}-doc
if: ${{ matrix.skip_doc != true }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACTS_BASE_NAME }}-doc
if-no-files-found: error
path: |
target/doc/
test-mithril-core:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs: [ build ]
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy, rustfmt
override: true
# Get the matrix build cache for mithril-core
# Note: cargo tools will be included so there's no need to install them
- uses: actions/cache@v3
name: Cache Cargo.lock
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/
target/
key: cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-mithril-core-${{ hashFiles('Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-mithril-core
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --tests -p mithril
- name: Run tests
if: ${{ matrix.skip_test != true }}
shell: bash
run: |
set -o pipefail && \
cargo test --release -p mithril --no-fail-fast \
-- -Z unstable-options --format json --report-time \
| tee >(cargo2junit > test-results-libmithril.xml)
- name: Upload Tests Results
if: ${{ always() && matrix.skip_test != true }}
uses: actions/upload-artifact@v3
with:
name: test-results-mithril-core
path: |
./**/test-results-*.xml
run-test-lab:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Download aggregator
uses: actions/download-artifact@v3
with:
name: mithril-aggregator
path: ./bin
- name: Download signer
uses: actions/download-artifact@v3
with:
name: mithril-signer
path: ./bin
- name: Download client
uses: actions/download-artifact@v3
with:
name: mithril-client
path: ./bin
- name: Download rust test runner
uses: actions/download-artifact@v3
with:
name: mithril-end-to-end
path: ./
- run: |
chmod +x ./bin/mithril-aggregator
chmod +x ./bin/mithril-client
chmod +x ./bin/mithril-signer
chmod +x ./mithril-end-to-end
mkdir artifacts
- name: Test
run: ./mithril-end-to-end --bin-directory ./bin --work-directory=./artifacts --devnet-scripts-directory=./mithril-test-lab/mithril-devnet
- name: Upload E2E Tests Artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: mithril-e2e-tests-artifacts-run_${{ github.run_number }}-attempt_${{ github.run_attempt }}
path: |
./artifacts/*
# including node.sock makes the upload fails so exclude them:
!./artifacts/**/node.sock
# exclude cardano tools, saving ~50mb of data:
!./artifacts/devnet/cardano-cli
!./artifacts/devnet/cardano-node
if-no-files-found: error
publish-tests-results:
if: github.event.pull_request.draft == false && ${{ always() }}
runs-on: ubuntu-latest
needs: [ test-mithril-core ]
steps:
- name: Download mithril-core Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-core
- name: Download mithril-common Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-common
- name: Download mithril-aggregator Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-aggregator
- name: Download mithril-client Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-client
- name: Download mithril-signer Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-signer
- name: Download mithril-end-to-end Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithril-end-to-end
- name: Download mithril-demo Tests Results
if: always()
uses: actions/download-artifact@v3
with:
name: test-results-mithrildemo
- name: Publish Unit Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: ./**/test-results-*.xml
docker-mithril:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs:
- test-mithril-core
- run-test-lab
strategy:
fail-fast: false
matrix:
project: [ mithril-aggregator, mithril-client, mithril-signer ]
permissions:
contents: read
packages: write
env:
PUSH_PACKAGES: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/${{ matrix.project }}
DOCKER_FILE: ./${{ matrix.project }}/Dockerfile.ci
CONTEXT: .
GITHUB_REF: ${{ github.ref}}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
latest
type=raw,value={{branch}}-{{sha}}
- name: Download ${{ matrix.project }} executable
uses: actions/download-artifact@v3
with:
name: ${{ matrix.project }}
path: ${{ matrix.project }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: ${{ env.CONTEXT }}
file: ${{ env.DOCKER_FILE }}
push: ${{ env.PUSH_PACKAGES }}
tags: ${{ steps.meta.outputs.tags }}
deploy-nightly:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- test-mithril-core
- run-test-lab
steps:
- name: Download mithril-core lib
uses: actions/download-artifact@v3
with:
name: mithril-core
path: ./build
- name: Download aggregator
uses: actions/download-artifact@v3
with:
name: mithril-aggregator
path: ./build
- name: Download signer
uses: actions/download-artifact@v3
with:
name: mithril-signer
path: ./build
- name: Download client
uses: actions/download-artifact@v3
with:
name: mithril-client
path: ./build
- name: Update nightly release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: nightly
prerelease: true
title: Nightly Development Builds
files: build/*
generate-publish-docs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs:
- docker-mithril
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Download mithril-core-doc artifact
uses: actions/download-artifact@v3
with:
name: mithril-core-doc
path: ./github-pages/mithril-core/doc
- name: Download mithril-common-doc artifact
uses: actions/download-artifact@v3
with:
name: mithril-common-doc
path: ./github-pages/mithril-common/doc
- name: Download aggregator-doc artifact
uses: actions/download-artifact@v3
with:
name: mithril-aggregator-doc
path: ./github-pages/mithril-aggregator/doc
- name: Download client-doc artifact
uses: actions/download-artifact@v3
with:
name: mithril-client-doc
path: ./github-pages/mithril-client/doc
- name: Download signer-doc artifact
uses: actions/download-artifact@v3
with:
name: mithril-signer-doc
path: ./github-pages/mithril-signer/doc
- name: Mithril Aggregator / Generate OpenAPI UI
uses: Legion2/swagger-ui-action@v1
with:
output: ./github-pages/openapi-ui
spec-file: ./openapi.yaml
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: docs/yarn.lock
- name: Documentation (Docusaurus)
working-directory: docs
run: |
yarn && yarn build
mkdir -p ../github-pages/doc
mv build/* ../github-pages/doc
echo "mithril.network" > ../github-pages/CNAME
echo '<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; URL=https://mithril.network/doc"></head></html>' > ../github-pages/index.html
- name: Explorer
working-directory: mithril-explorer
run: |
make build
mkdir -p ../github-pages/explorer
mv out/* ../github-pages/explorer
- name: Mithril / Publish Github Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN || github.token }}
publish_dir: ./github-pages
terraform:
runs-on: ubuntu-latest
needs:
- docker-mithril
env:
# Contains a JSON-formatted service account key
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
# Contains a RSA private key
GCLOUD_PRIVATE_KEY: ${{ secrets.GCLOUD_PRIVATE_KEY }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
defaults:
run:
working-directory: mithril-infra
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Get short SHA
id: slug
run: echo "::set-output name=sha8::$(echo ${{ github.sha }} | cut -c1-7)"
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false
- name: Init Terraform
run: terraform init
- name: Check Terraform
run: terraform fmt -check
- name: Terraform Plan
run: |
terraform plan -var "image_id=${{ env.BRANCH_NAME }}-${{ steps.slug.outputs.sha8 }}" -var 'private_key=${{ env.GCLOUD_PRIVATE_KEY }}' -var 'google_application_credentials_json=${{ env.GOOGLE_CREDENTIALS }}'
- name: Update Pull Request
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
terraform apply -auto-approve -var "image_id=${{ env.BRANCH_NAME }}-${{ steps.slug.outputs.sha8 }}" -var 'private_key=${{ env.GCLOUD_PRIVATE_KEY }}' -var 'google_application_credentials_json=${{ env.GOOGLE_CREDENTIALS }}'