-
Notifications
You must be signed in to change notification settings - Fork 120
303 lines (265 loc) · 9.73 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
name: ci
on:
pull_request:
push:
branches:
- master
tags:
- v*
paths-ignore:
- 'README.md'
- 'CHANGELOG.md'
jobs:
fmt:
runs-on: ubuntu-latest
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
default: true
components: rustfmt
- name: Checkout
uses: actions/checkout@v4
- name: Check Formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
# Runs `cargo check` on each individual crate in the `crates` directory.
#
# This is required because the other commands build on the workspace level,
# or bring in `dev-dependencies` via the `test` target and it is possible
# for a crate to compile successfully in those cases, but fail when compiled
# on its own.
#
# Specifically, this happens where a dependency is missing features, but
# when building as part of the workspace or together with a `dev-dependency`
# those features are brought in via feature unification with another
# crate.
#
# When publishing, `cargo publish` will run a `check` on the individual
# crate being released. So this check is intended to catch any errors that
# may occur there, but otherwise would not be caught by the `test` and
# `clippy` commands which operate on the workspace and enable all targets.
check:
runs-on: ubuntu-latest
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v4
- name: Check each crate
run: |
for crate in ./crates/*/; do
echo "Checking $crate";
cargo check --manifest-path ${crate}/Cargo.toml;
done
clippy:
runs-on: ubuntu-latest
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
components: clippy
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v4
# Check permissions of GITHUB_TOKEN, workaround for permission issues
# with @dependabot PRs. See https://github.com/actions-rs/clippy-check/issues/2#issuecomment-807878478
- name: Check workflow permissions
id: check_permissions
uses: scherermichael-oss/[email protected]
with:
required-permission: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clippy with features
uses: actions-rs/clippy-check@v1
if: ${{ steps.check_permissions.outputs.has-permission }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --profile debug-ci --all-features --all-targets -- -D warnings
- name: Clippy without features
if: ${{ steps.check_permissions.outputs.has-permission }}
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --profile debug-ci --all-targets -- -D warnings
# Runs if the GITHUB_TOKEN does not have `write` permissions e.g. @dependabot
- name: Clippy with features (no annotations)
if: ${{ !steps.check_permissions.outputs.has-permission }}
run: cargo clippy --profile debug-ci --all-features --all-targets -- -D warnings
# Runs if the GITHUB_TOKEN does not have `write` permissions e.g. @dependabot
- name: Clippy without features (no annotations)
if: ${{ !steps.check_permissions.outputs.has-permission }}
run: cargo clippy --profile debug-ci --all-targets -- -D warnings
build-tests:
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Install nextest
uses: taiki-e/[email protected]
with:
tool: nextest
- name: Build and archive tests
run: cargo nextest archive --cargo-profile debug-ci --workspace --all-features --archive-file nextest-archive-${{ matrix.os }}.tar.zst
- name: Upload archive to workflow
uses: actions/upload-artifact@v4
with:
name: nextest-archive-${{ matrix.os }}
path: nextest-archive-${{ matrix.os }}.tar.zst
run-tests:
needs: build-tests
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
partition: [1, 2]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Install nextest
uses: taiki-e/[email protected]
with:
tool: nextest
- name: Download archive
uses: actions/download-artifact@v4
with:
name: nextest-archive-${{ matrix.os }}
- name: Run tests
run: cargo nextest run --archive-file nextest-archive-${{ matrix.os }}.tar.zst --partition count:${{ matrix.partition }}/2 -E 'not (test(integration_tests) | package(contract-build))'
- name: Run contract build tests
# The contract build tests cannot be run in parallel
run: cargo nextest run --archive-file nextest-archive-${{ matrix.os }}.tar.zst --partition count:${{ matrix.partition }}/2 -j 1 -E 'package(contract-build)'
run-integration-test:
needs: build-tests
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
partition: [1, 2]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Install nextest
uses: taiki-e/[email protected]
with:
tool: nextest
- name: Download archive
uses: actions/download-artifact@v4
with:
name: nextest-archive-${{ matrix.os }}
- name: Install latest `substrate-contracts-node` binary
env:
CONTRACTS_NODE_URL: https://github.com/paritytech/substrate-contracts-node/releases/latest/download/substrate-contracts-node-
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
CONTRACTS_NODE_OS=linux
elif [ "$RUNNER_OS" == "macOS" ]; then
CONTRACTS_NODE_OS=mac-universal
else
echo "$RUNNER_OS not supported"
exit 1
fi
curl -L -o substrate-contracts-node.tar.gz "$CONTRACTS_NODE_URL$CONTRACTS_NODE_OS.tar.gz"
tar xfzv substrate-contracts-node.tar.gz
chmod +x substrate-contracts-node-*/substrate-contracts-node &&
mv substrate-contracts-node-*/substrate-contracts-node /usr/local/bin
shell: bash
- name: Run integration tests
# The integration tests cannot be run in parallel
run: cargo nextest run --archive-file nextest-archive-${{ matrix.os }}.tar.zst --partition count:${{ matrix.partition }}/2 -j 1 -E 'test(integration_tests)'
template:
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15", "windows-2022"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-12-28
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
components: rust-src
- name: Cache
uses: Swatinem/rust-cache@v2
- name: Check Template
run: >-
# The linter requires two crates
cargo install cargo-dylint dylint-link
cargo -vV &&
cargo run --profile debug-ci -- contract --version &&
cargo run --profile debug-ci -- contract new --target-dir ${{ runner.temp }} foobar &&
# Build with linting
cargo run --profile debug-ci -- contract build --lint --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run --profile debug-ci -- contract check --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release &&
# Run tests
cargo test --profile debug-ci --all-features -- --test-threads=1