-
Notifications
You must be signed in to change notification settings - Fork 16
223 lines (179 loc) · 7.07 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
name: CI
on:
merge_group:
pull_request:
# smoelius: Every Thursday at 3:00 UTC (Wednesday at 22:00 EST), run `cargo test -- --ignored`.
schedule:
- cron: "0 3 * * 4"
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
maybe-expedite:
outputs:
value: ${{ steps.expedite.outputs.value }}
runs-on: ubuntu-latest
steps:
- name: Log github refs
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo 'github.ref: ${{ github.ref }}' >> "$GITHUB_STEP_SUMMARY"
echo 'github.sha: ${{ github.sha }}' >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if merging an up-to-date branch
if: ${{ github.event_name == 'merge_group' }}
id: expedite
run: |
N="$(expr "${{ github.ref }}" : '.*-\([0-9]\+\)-[^-]*$')"
BASE_SHA="$(gh api /repos/${{ github.repository }}/pulls/"$N" | jq -r '.base.sha')"
if git diff --quiet ${{ github.event.merge_group.base_sha }} "$BASE_SHA"; then
echo "value=1" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ github.token }}
lint:
needs: [maybe-expedite]
if: ${{ ! needs.maybe-expedite.outputs.value }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dylint versions
run: cargo search dylint | sort | tee dylint_versions
# smoelius: The `~/.cargo/` entries are from:
# * https://github.com/actions/cache/blob/main/examples.md#rust---cargo.
# * https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
# The rest were added by me.
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.dylint_drivers/
~/.rustup/toolchains/
target/dylint/
key: ${{ runner.os }}-dylint-${{ hashFiles('dylint_versions') }}
- name: Rustup
run: rustup update
- name: Actionlint
run: go install github.com/rhysd/actionlint/cmd/actionlint@latest && "$HOME"/go/bin/actionlint --shellcheck='-e SC2016'
- name: Shellcheck
run: shellcheck --exclude=SC2002 scripts/*
- name: Prettier
run: npm install -g prettier && prettier --check '**/*.json' '**/*.md' '**/*.yml'
# smoelius: Pin `markdown-link-check` to version 3.11 until the following issue is resolved:
# https://github.com/tcort/markdown-link-check/issues/304
- name: Markdown link check
run: npm install -g markdown-link-check@3.11 && markdown-link-check ./**/*.md
# https://github.com/DevinR528/cargo-sort/issues/57#issuecomment-1457714872
- name: Cargo sort
run: |
cargo install cargo-sort || true
find . -name Cargo.toml -print0 | xargs -0 -n 1 dirname | xargs -n 1 cargo sort --check --grouped --no-format
- name: Format
run: |
rustup +nightly component add rustfmt
cargo +nightly fmt && git diff --exit-code
- name: Dylint
run: |
cargo install cargo-dylint --git=https://github.com/trailofbits/dylint --no-default-features --features=cargo-cli || true
cargo install dylint-link || true
./scripts/dylint.sh
- name: Udeps
run: |
cargo install cargo-udeps || true
cargo clean && cargo +nightly udeps --features=test-install --all-targets
test:
needs: [maybe-expedite]
if: ${{ ! needs.maybe-expedite.outputs.value }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: [third-party, other]
serde_format: [bincode, postcard]
toolchain: [stable, nightly]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# smoelius: The Substrate tests require the `rust-src` component and the wasm32 target.
- name: Set toolchain
run: |
rustup default ${{ matrix.toolchain }}
rustup component add rust-src
rustup target add wasm32-unknown-unknown
# smoelius: The Substrate tests require `protoc`.
- name: Install protoc
run: sudo apt-get install protobuf-compiler
- name: Install cargo-afl
run: cargo install cargo-afl
- name: Run afl-system-config
run: cargo afl system-config
# smoelius: I expect this list to grow.
- name: Install tools
run: |
rustup +nightly component add clippy
cargo install cargo-license || true
cargo install cargo-supply-chain || true
cargo install cargo-unmaintained || true
cargo install group-runner || true
- name: Free up space
run: |
# https://github.com/actions/runner-images/issues/2606#issuecomment-772683150
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/share/swift
# du -sh /usr/*/* 2>/dev/null | sort -h || true
- name: Setup
run: |
if [[ ${{ matrix.package }} = 'third-party' ]]; then
MAYBE_THIRD_PARTY='--package third-party'
if [[ ${{ github.event_name }} = 'schedule' ]] ||
git diff --name-only ${{ github.event.pull_request.base.sha }} | grep -w 'patches\|third_party' >/dev/null
then
MAYBE_THIRD_PARTY="$MAYBE_THIRD_PARTY --features=test-third-party-full"
fi
else
MAYBE_THIRD_PARTY='--workspace --exclude third-party --features=test-install'
fi
SERDE_FORMAT='--features=test-fuzz/serde_${{ matrix.serde_format }}'
SHUFFLE=
if [[ ${{ matrix.toolchain }} = nightly ]]; then
SHUFFLE='-Z unstable-options --shuffle --test-threads=1'
fi
CONFIG_GROUP_RUNNER="--config target.'cfg(all())'.runner='group-runner'"
BUILD_CMD="cargo build $MAYBE_THIRD_PARTY $SERDE_FORMAT --all-targets"
TEST_CMD="cargo test $MAYBE_THIRD_PARTY $SERDE_FORMAT $CONFIG_GROUP_RUNNER -- --nocapture $SHUFFLE"
echo "BUILD_CMD=$BUILD_CMD" >> "$GITHUB_ENV"
echo "TEST_CMD=$TEST_CMD" >> "$GITHUB_ENV"
- name: Build
run: $BUILD_CMD
- name: Test
run: |
$TEST_CMD
env:
AFL_NO_AFFINITY: 1
RUST_BACKTRACE: 1
RUST_LOG: warn
all-checks:
needs:
- lint
- test
runs-on: ubuntu-latest
# smoelius: From "Defining prerequisite jobs"
# (https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow#defining-prerequisite-jobs):
# > If you would like a job to run even if a job it is dependent on did not succeed, use the
# > `always()` conditional expression in `jobs.<job_id>.if`.
if: ${{ always() }}
steps:
- name: Check results
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1