@@ -4,13 +4,37 @@ name: CI
44on : [push]
55
66jobs :
7- build-mithril-core :
7+ build :
88 if : github.event.pull_request.draft == false
99 runs-on : ubuntu-latest
10+ strategy :
11+ fail-fast : false
12+ matrix :
13+ include :
14+ - project : mithril-core
15+ cargo_project_name : mithril
16+ artifacts_pattern : libmithril
17+ - project : mithril-common
18+ artifacts_pattern : libmithril_common
19+ - project : mithril-aggregator
20+ - project : mithril-client
21+ - project : mithril-signer
22+ env :
23+ CARGO_PROJECT_NAME : ${{ matrix.project }}
24+ ARTIFACTS_PATTERN : ${{ matrix.project }}
25+
1026 steps :
1127 - name : Checkout sources
1228 uses : actions/checkout@v2
1329
30+ - name : Overriding default $CARGO_PROJECT_NAME with matrix value
31+ if : ${{ matrix.cargo_project_name }}
32+ run : echo "CARGO_PROJECT_NAME=${{ matrix.cargo_project_name }}" >> $GITHUB_ENV
33+
34+ - name : Overriding default $ARTIFACTS_PATTERN with matrix value
35+ if : ${{ matrix.artifacts_pattern }}
36+ run : echo "ARTIFACTS_PATTERN=${{ matrix.artifacts_pattern }}" >> $GITHUB_ENV
37+
1438 - name : Install stable toolchain
1539 uses : actions-rs/toolchain@v1
1640 with :
@@ -19,223 +43,74 @@ jobs:
1943 components : clippy, rustfmt
2044 override : true
2145
22- - uses : actions/cache@v2.1.5
23- name : Cache mithril-core/ Cargo.lock
46+ - uses : actions/cache@v3
47+ name : Cache Cargo.lock
2448 with :
2549 path : |
26- ~/.cargo/registry
27- ~/.cargo/git
28- mithril-core/target
29- key : ${{ runner.os }}-${{ hashFiles('mithril-core/Cargo.lock') }}
50+ ~/.cargo/bin/
51+ ~/.cargo/registry/
52+ ~/.cargo/git/
53+ target/
54+ key : cargo-${{ runner.os }}-${{ matrix.project }}-${{ hashFiles('Cargo.lock') }}
3055 restore-keys : |
31- ${{ runner.os }}-key
56+ cargo-${{ runner.os }}-${{ matrix.project }}-
57+ cargo-${{ runner.os }}-
3258
59+ - name : Install cargo tools
60+ if : ${{ steps.cargo-cache.outputs.cache-hit == false }}
61+ run : |
62+ cargo install cargo2junit 2>/dev/null || true # Suppress the "binary `cargo2junit` already exists in destination" error
63+
3364 - name : Cargo build
3465 uses : actions-rs/cargo@v1
3566 with :
3667 command : build
37- args : --release --manifest-path ./mithril-core/Cargo.toml
38-
68+ args : --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }}
69+
3970 - name : Cargo check
4071 uses : actions-rs/cargo@v1
4172 with :
4273 command : check
43- args : --release --all-targets --manifest-path ./mithril-core/Cargo.toml
44-
45- - name : Cargo fmt
46- uses : actions-rs/cargo@v1
47- with :
48- command : fmt
49- args : --all --manifest-path ./mithril-core/Cargo.toml -- --check
74+ args : --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }}
5075
5176 - name : Clippy Check
5277 uses : actions-rs/clippy-check@v1
5378 with :
54- name : clippy-mithril-core
79+ name : clippy-${{ matrix.project }}
5580 token : ${{ secrets.GITHUB_TOKEN }}
56- args : --manifest-path ./mithril-core/Cargo.toml --all-features
57-
58- - name : Compile benchmarks
59- uses : actions-rs/cargo@v1
60- continue-on-error : false
61- with :
62- command : bench
63- args : --no-run --locked --manifest-path ./mithril-core/Cargo.toml
81+ args : --release --all-features -p ${{ env.CARGO_PROJECT_NAME }}
6482
65- - name : Mithril Core / Generate doc
83+ - name : Cargo fmt
6684 uses : actions-rs/cargo@v1
6785 with :
68- command : doc
69- args : --no-deps --release --manifest-path ./mithril-core/Cargo.toml
70-
71- - name : Publish libmithril
72- uses : actions/upload-artifact@v3
73- with :
74- name : libmithril
75- if-no-files-found : error
76- path : |
77- mithril-core/target/release/libmithril.so
78- mithril-core/target/include/mithril.h
79-
80- - name : Publish libmithril-doc
81- uses : actions/upload-artifact@v3
82- with :
83- name : libmithril-doc
84- if-no-files-found : error
85- path : |
86- mithril-core/target/doc/
87-
88- test-mithril-core :
89- if : github.event.pull_request.draft == false
90- needs :
91- - build-mithril-core
92- runs-on : ubuntu-latest
93- steps :
94- - name : Checkout sources
95- uses : actions/checkout@v2
96-
97- - name : Install stable toolchain
98- uses : actions-rs/toolchain@v1
99- with :
100- profile : minimal
101- toolchain : stable
102- components : clippy, rustfmt
103- override : true
104-
105- 106- name : Cache mithril-core/Cargo.lock
107- with :
108- path : |
109- ~/.cargo/registry
110- ~/.cargo/git
111- mithril-core/target
112- key : ${{ runner.os }}-${{ hashFiles('mithril-core/Cargo.lock') }}
113- restore-keys : |
114- ${{ runner.os }}-key
115-
116- 117- name : Cache cargo2junit
118- with :
119- path : |
120- ~/.cargo/bin/cargo2junit
121- key : ${{ runner.os }}-${{ hashFiles('~/.cargo/bin/cargo2junit') }}
122- restore-keys : |
123- ${{ runner.os }}-cargo2junit-key
124-
125- - name : Download mithril core
126- uses : actions/download-artifact@v3
127- with :
128- name : libmithril
129- path : mithril-core/target/include/
130-
131- - name : Install cargo2junit
132- run : |
133- # Suppress the "binary `cargo2junit` already exists in destination" error
134- cargo install cargo2junit 2>/dev/null || true
86+ command : fmt
87+ args : --all -p ${{ env.CARGO_PROJECT_NAME }}
13588
136- - name : Run cargo test
89+ - name : Run tests
13790 shell : bash
138- working-directory : mithril-core
13991 run : |
140- set -o pipefail && cargo test --release -- -Z unstable-options --format json --report-time | tee >(cargo2junit > test-results-mithril-core.xml)
141-
92+ set -o pipefail && cargo test --release -p $CARGO_PROJECT_NAME -- -Z unstable-options --format json --report-time | tee >(cargo2junit > test-results-${{ matrix.project }}.xml)
14293
143- - name : Upload Unit Test Results
94+ - name : Upload Tests Results
14495 if : always()
14596 uses : actions/upload-artifact@v3
14697 with :
147- name : test-results-mithril-core
98+ name : test-results-${{ matrix.project }}
14899 path : |
149100 ./**/test-results-*.xml
150-
151- build-mithril :
152- if : github.event.pull_request.draft == false
153- runs-on : ubuntu-latest
154- strategy :
155- fail-fast : false
156- matrix :
157- project : [ mithril-common, mithril-aggregator, mithril-client, mithril-signer ]
158- steps :
159- - name : Checkout sources
160- uses : actions/checkout@v2
161-
162- - name : Install stable toolchain
163- uses : actions-rs/toolchain@v1
164- with :
165- profile : minimal
166- toolchain : stable
167- components : clippy, rustfmt
168- override : true
169-
170- 171- name : Cache ${{ matrix.project }}/Cargo.lock
172- with :
173- path : |
174- ~/.cargo/registry
175- ~/.cargo/git
176- ${{ matrix.project }}/target
177- key : ${{ runner.os }}-${{ hashFiles('${{ matrix.project }}/Cargo.lock') }}
178- restore-keys : |
179- ${{ runner.os }}-key
180-
181- 182- name : Cache cargo2junit
183- with :
184- path : |
185- ~/.cargo/bin/cargo2junit
186- key : ${{ runner.os }}-${{ hashFiles('~/.cargo/bin/cargo2junit') }}
187- restore-keys : |
188- ${{ runner.os }}-cargo2junit-key
189-
190- - name : Cargo build
191- uses : actions-rs/cargo@v1
192- with :
193- command : build
194- args : --release --manifest-path ./${{ matrix.project }}/Cargo.toml
195-
196- - name : Cargo check
197- uses : actions-rs/cargo@v1
198- with :
199- command : check
200- args : --release --all-targets --manifest-path ./${{ matrix.project }}/Cargo.toml
201-
202- - name : Cargo fmt
203- uses : actions-rs/cargo@v1
204- with :
205- command : fmt
206- args : --all --manifest-path ./${{ matrix.project }}/Cargo.toml -- --check
207-
208- - name : Clippy Check
209- uses : actions-rs/clippy-check@v1
210- with :
211- name : clippy-${{ matrix.project }}
212- token : ${{ secrets.GITHUB_TOKEN }}
213- args : --manifest-path ./${{ matrix.project }}/Cargo.toml --all-features
214-
215- - name : Install cargo2junit
216- run : |
217- # Suppress the "binary `cargo2junit` already exists in destination" error
218- cargo install cargo2junit 2>/dev/null || true
219-
220- - name : Run cargo test
221- shell : bash
222- working-directory : ${{ matrix.project }}
223- run : |
224- set -o pipefail && cargo test --release -- -Z unstable-options --format json --report-time | tee >(cargo2junit > test-results-${{ matrix.project }}.xml)
225-
101+
226102 - name : Generate ${{ matrix.project }} doc
227103 uses : actions-rs/cargo@v1
228104 with :
229105 command : doc
230- args : --no-deps --release --manifest-path ./ ${{ matrix.project }}/Cargo.toml
106+ args : --no-deps --release -p ${{ env.CARGO_PROJECT_NAME }}
231107
232108 - name : Publish ${{ matrix.project }}
233109 uses : actions/upload-artifact@v3
234110 with :
235111 name : ${{ matrix.project }}
236112 path : |
237- ${{ matrix.project }}/target/release/${{ matrix.project }}
238- ${{ matrix.project }}/target/release/lib*.so
113+ target/release/${{ env.ARTIFACTS_PATTERN }}*
239114 if-no-files-found : error
240115
241116 - name : Publish ${{ matrix.project }}-doc
@@ -244,20 +119,12 @@ jobs:
244119 name : ${{ matrix.project }}-doc
245120 if-no-files-found : error
246121 path : |
247- ${{ matrix.project }}/target/doc/
248-
249- - name : Upload Unit Test Results
250- if : always()
251- uses : actions/upload-artifact@v3
252- with :
253- name : test-results-${{ matrix.project }}
254- path : |
255- ./**/test-results-*.xml
122+ target/doc/
256123
257124 docker-mithril :
258125 runs-on : ubuntu-latest
259126 if : ${{ github.event_name == 'push' }}
260- needs : [ build-mithril-core, build-mithril ]
127+ needs : [ build ]
261128 strategy :
262129 fail-fast : false
263130 matrix :
@@ -311,7 +178,7 @@ jobs:
311178 publish-tests-results :
312179 if : github.event.pull_request.draft == false && ${{ always() }}
313180 runs-on : ubuntu-latest
314- needs : [ build-mithril, test-mithril-core ]
181+ needs : [ build ]
315182 steps :
316183 - name : Download mithril-core Tests Results
317184 if : always()
@@ -353,18 +220,17 @@ jobs:
353220 if : github.event.pull_request.draft == false
354221 runs-on : ubuntu-latest
355222 needs :
356- - build-mithril
223+ - build
357224 - docker-mithril
358- - test-mithril-core
359- - build-test-lab
225+ - run-test-lab
360226 steps :
361227 - name : Checkout sources
362228 uses : actions/checkout@v2
363229
364- - name : Download libmithril -doc artifact
230+ - name : Download mithril-core -doc artifact
365231 uses : actions/download-artifact@v3
366232 with :
367- name : libmithril -doc
233+ name : mithril-core -doc
368234 path : ./github-pages/mithril-core/doc
369235
370236 - name : Download mithril-common-doc artifact
@@ -420,9 +286,9 @@ jobs:
420286 github_token : ${{ secrets.GITHUB_TOKEN || github.token }}
421287 publish_dir : ./github-pages
422288
423- build -test-lab :
289+ run -test-lab :
424290 runs-on : ubuntu-latest
425- needs : [ build-mithril-core, build-mithril ]
291+ needs : [ build ]
426292 steps :
427293 - name : Checkout sources
428294 uses : actions/checkout@v2
@@ -436,7 +302,7 @@ jobs:
436302 substituters = https://cache.nixos.org https://hydra.iohk.io https://iohk.cachix.org
437303
438304 - name : Github cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
439- uses : actions/cache@v2.1.5
305+ uses : actions/cache@v3
440306 with :
441307 path : |
442308 ~/.cabal/packages
@@ -485,9 +351,9 @@ jobs:
485351 terraform :
486352 runs-on : ubuntu-latest
487353 needs :
488- - docker-mithril
489- - test -mithril-core
490- - build -test-lab
354+ - build
355+ - docker -mithril
356+ - run -test-lab
491357 env :
492358 # Contains a JSON-formatted service account key
493359 GOOGLE_CREDENTIALS : ${{ secrets.GOOGLE_CREDENTIALS }}
0 commit comments