Skip to content

Commit c3a3746

Browse files
author
Mikhail Zabaluev
authored
Merge pull request #2332 from input-output-hk/circleci-improvements
Reworked CircleCI config
2 parents 696e195 + 6aeb9d9 commit c3a3746

File tree

1 file changed

+129
-112
lines changed

1 file changed

+129
-112
lines changed

.circleci/config.yml

Lines changed: 129 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,205 @@
1-
version: 2
2-
jobs:
3-
cargo_fetch:
1+
version: 2.1
2+
3+
executors:
4+
rust-stable:
45
docker:
56
- image: inputoutput/rust:stable
6-
working_directory: /home/circleci/project
7+
working_directory: /home/circleci/build
8+
rust-beta:
9+
docker:
10+
- image: instrumentisto/rust:beta
11+
working_directory: /home/build
12+
13+
jobs:
14+
cargo_fetch:
15+
executor: rust-stable
716
steps:
817
- checkout
18+
- run: git --version
919
- run: git submodule sync
10-
- run: git submodule update --init
20+
- run: git submodule update --init --depth=1
21+
- run:
22+
name: Get top commit hash of cargo registry index
23+
command: |
24+
git ls-remote --heads https://github.com/rust-lang/crates.io-index.git master |
25+
cut -f 1 | tee .circleci/crates.io-index.head
26+
- restore_cache:
27+
name: Restore cargo registry index from cache
28+
keys:
29+
- cargo-index-v1-{{ checksum ".circleci/crates.io-index.head" }}
30+
- cargo-index-v1-
1131
- restore_cache:
32+
name: Restore dependency crates from cache
1233
keys:
13-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
14-
- cargo-v3-{{ checksum "Cargo.toml" }}
15-
- cargo-v3-
16-
- run: cargo fetch
34+
- cargo-deps-v1-{{ checksum "Cargo.lock" }}
35+
- run:
36+
name: Fetch dependencies and update cargo registry index
37+
command: |
38+
cargo fetch --locked
39+
git -C /usr/local/cargo/registry/index/github.com-1ecc6299db9ec823 \
40+
show-ref -s refs/remotes/origin/master |
41+
tee .circleci/crates.io-index.head
1742
- save_cache:
18-
key: cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
43+
name: Save cargo registry index into cache
44+
key: cargo-index-v1-{{ checksum ".circleci/crates.io-index.head" }}
1945
paths:
20-
- /usr/local/cargo/registry
21-
- /usr/local/cargo/git
46+
- /usr/local/cargo/registry/index
47+
- save_cache:
48+
name: Save dependency crates into cache
49+
key: cargo-deps-v1-{{ checksum "Cargo.lock" }}
50+
paths:
51+
- /usr/local/cargo/registry/cache
52+
- persist_to_workspace:
53+
root: .
54+
paths:
55+
- .circleci/crates.io-index.head
2256

2357
cargo_audit:
24-
docker:
25-
- image: inputoutput/rust:stable
26-
working_directory: /home/circleci/project
58+
executor: rust-stable
2759
steps:
2860
- checkout
29-
- run: git submodule sync
30-
- run: git submodule update --init
61+
- attach_workspace:
62+
at: .
3163
- restore_cache:
64+
name: Restore cargo registry index from cache
3265
keys:
33-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
66+
- cargo-index-v1-{{ checksum ".circleci/crates.io-index.head" }}
67+
- run:
68+
name: Get top commit hash of RustSec advisory database
69+
command: |
70+
git ls-remote --heads https://github.com/RustSec/advisory-db.git master |
71+
cut -f 1 | tee .circleci/advisory-db.head
3472
- restore_cache:
73+
name: Restore advisory database from cache
3574
keys:
36-
- cargo-advisory-db-v1
75+
- cargo-advisory-db-v2-{{ checksum ".circleci/advisory-db.head" }}
76+
- cargo-advisory-db-v2-
3777
- run:
3878
name: Print Cargo Audit Version
3979
command: cargo audit --version
4080
- run:
4181
name: Check Cargo Audit
42-
command: cargo audit
82+
command: |
83+
cargo audit
84+
git -C /usr/local/cargo/advisory-db \
85+
show-ref -s refs/remotes/origin/master \
86+
> .circleci/advisory-db.head
4387
- save_cache:
44-
key: cargo-advisory-db-v1
88+
name: Save advisory database into cache
89+
key: cargo-advisory-db-v2-{{ checksum ".circleci/advisory-db.head" }}
4590
paths:
4691
- /usr/local/cargo/advisory-db
4792

4893
rustfmt:
49-
docker:
50-
- image: inputoutput/rust:stable
51-
working_directory: /home/circleci/project
52-
steps:
53-
- checkout
54-
- run:
55-
name: Print version information
56-
command: cargo fmt -- --version
57-
- run:
58-
name: Check rustfmt
59-
command: cargo fmt -- --check
60-
61-
test_debug:
62-
docker:
63-
- image: inputoutput/rust:stable
64-
environment:
65-
CARGO_INCREMENTAL: 0
66-
working_directory: /home/circleci/project
94+
executor: rust-stable
6795
steps:
6896
- checkout
6997
- run: git submodule sync
70-
- run: git submodule update --init
98+
- run: git submodule update --init --depth=1
99+
- attach_workspace:
100+
at: .
71101
- restore_cache:
102+
name: Restore cargo registry index from cache
72103
keys:
73-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
104+
- cargo-index-v1-{{ checksum ".circleci/crates.io-index.head" }}
74105
- run:
75106
name: Print version information
76-
command: rustc --version; cargo --version
77-
- run:
78-
name: Build binaries
79-
command: cargo build -p jormungandr -p jcli --offline --verbose --frozen
80-
- run:
81-
name: Build tests
82-
command: cargo build --tests --offline --verbose --frozen
107+
command: cargo fmt -- --version
83108
- run:
84-
name: Test
85-
environment:
86-
RUST_BACKTRACE: 1
87-
command: cargo test --offline --verbose --frozen --tests
109+
name: Check rustfmt
110+
command: cargo fmt --all -- --check
88111

89-
test_doc:
90-
docker:
91-
- image: inputoutput/rust:stable
112+
test_debug:
113+
executor: rust-stable
92114
environment:
93115
CARGO_INCREMENTAL: 0
94-
working_directory: /home/circleci/project
95116
steps:
96-
- checkout
97-
- run: git submodule sync
98-
- run: git submodule update --init
99-
- restore_cache:
100-
keys:
101-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
102-
- run:
103-
name: Print version information
104-
command: rustc --version; cargo --version
105-
- run:
106-
name: Test
107-
environment:
108-
RUST_BACKTRACE: 1
109-
command: cargo test --offline --verbose --frozen --doc -- --test-threads=1
117+
- test
110118

111119
test_release:
112-
docker:
113-
- image: inputoutput/rust:stable
114-
working_directory: /home/circleci/project
120+
executor: rust-stable
115121
steps:
116-
- checkout
117-
- run: git submodule sync
118-
- run: git submodule update --init
119-
- restore_cache:
120-
keys:
121-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
122-
- run:
123-
name: Print version information
124-
command: rustc --version; cargo --version
125-
- run:
126-
name: Build binaries
127-
command: cargo build -p jormungandr -p jcli --release --offline --verbose --frozen
128-
- run:
129-
name: Build tests
130-
command: cargo build --tests --release --offline --verbose --frozen
131-
- run:
132-
name: Test
133-
command: cargo test --release --offline --verbose --tests
122+
- test:
123+
mode: --release
134124

135125
test_beta:
136-
docker:
137-
- image: instrumentisto/rust:beta
126+
executor: rust-beta
138127
environment:
139128
CARGO_INCREMENTAL: 0
140-
working_directory: /home/circleci/project
129+
steps:
130+
- test
131+
132+
commands:
133+
test:
134+
description: "Steps for the test jobs"
135+
parameters:
136+
mode:
137+
type: string
138+
default: ''
139+
cargo_behavior:
140+
type: string
141+
default: --locked --offline --verbose
141142
steps:
142143
- checkout
143144
- run: git submodule sync
144-
- run: git submodule update --init
145+
- run: git submodule update --init --depth=1
146+
- attach_workspace:
147+
at: .
145148
- restore_cache:
149+
name: Restore cargo registry index from cache
146150
keys:
147-
- cargo-v3-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
151+
- cargo-index-v1-{{ checksum ".circleci/crates.io-index.head" }}
152+
- restore_cache:
153+
name: Restore dependency crates from cache
154+
keys:
155+
- cargo-deps-v1-{{ checksum "Cargo.lock" }}
148156
- run:
149157
name: Print version information
150158
command: rustc --version; cargo --version
159+
# `cargo build --all-targets` runs out of memory
160+
- run:
161+
name: Build jormungandr
162+
command: |
163+
cargo build -p jormungandr --bin jormungandr << parameters.mode >> << parameters.cargo_behavior >>
151164
- run:
152-
name: Build binaries
153-
command: cargo build -p jormungandr -p jcli --offline --verbose --frozen
165+
name: Build jcli
166+
command: |
167+
cargo build -p jcli --bin jcli << parameters.mode >> << parameters.cargo_behavior >>
154168
- run:
155169
name: Build tests
156-
command: cargo build --tests --offline --verbose --frozen
170+
command: |
171+
cargo build --workspace --tests << parameters.mode >> << parameters.cargo_behavior >>
172+
- run:
173+
name: Run tests
174+
environment:
175+
RUST_BACKTRACE: 1
176+
command: |
177+
cargo test --workspace --tests << parameters.mode >> << parameters.cargo_behavior >>
157178
- run:
158-
name: Test
179+
name: Run doc tests
159180
environment:
160181
RUST_BACKTRACE: 1
161-
command: cargo test --offline --verbose --tests
182+
CARGO_BUILD_JOBS: 1
183+
command: |
184+
cargo test --workspace --doc << parameters.mode >> << parameters.cargo_behavior >>
162185
163186
workflows:
164187
version: 2
165188
test_all:
166189
jobs:
167190
- cargo_fetch
168-
- rustfmt
169-
# Temporarily disabled, vulnerable dependencies are pending update
170-
#- cargo_audit:
171-
# requires:
172-
# - cargo_fetch
173-
- test_debug:
191+
- rustfmt:
174192
requires:
175-
- rustfmt
176193
- cargo_fetch
177-
- test_doc:
194+
- cargo_audit:
195+
requires:
196+
- cargo_fetch
197+
- test_debug:
178198
requires:
179-
- rustfmt
180199
- cargo_fetch
181200
- test_release:
182201
requires:
183-
- rustfmt
184202
- cargo_fetch
185203
- test_beta:
186204
requires:
187-
- rustfmt
188205
- cargo_fetch

0 commit comments

Comments
 (0)