forked from Sovereign-Labs/sovereign-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
328 lines (323 loc) · 12.9 KB
/
rust.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
name: Rust
# On Rust, GitHub Actions, and caching
# ===========
# Here's a list of things to keep in mind if you find yourself maintaing this
# CI:
#
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
#
# - Always install and select the desired Rust toolchain *before* running
# `Swatinem/rust-cache`. This is because the active Rust toolchain is used as
# a cache key.
# - You can use `rustup show` to install and select the right Rust toolchain if
# you have a `rust-toolchain.toml` file:
# https://github.com/rust-lang/rustup/issues/1397.
# - When caching Rust compilation artifacts, keep in mind that different `cargo`
# commands will use different profiles
# (https://doc.rust-lang.org/cargo/reference/profiles.html). Learn what you
# can reuse between one job and another and don't assume two commands will
# just share caches without conflicts.
# - Be extremely aware of cache thrashing a.k.a. churning. GitHub Actions' cache
# allows for 10GiB of data which is easily exceeded if not careful.
# Sometimes it's better not to cache than cache excessively.
# Disabling cache writes for non-default branches altogether if cache churning
# is unacceptably high is supposed to help with this.
# - Learn cache invalidation rules of `Swatinem/rust-cache` before making
# changes, e.g. what happens when `rustc --version` changes or `Cargo.lock`
# changes (or is missing).
# - The jobs dependency tree is the way it is to accomodate for sharing caches,
# not necessarily because it makes logical sense to run one job after the
# other. This is due to the fact that we can't share caches between jobs that
# run in parallel.
# - `sccache` is a good alternative to `Swatinem/rust-cache`, but it behaves
# poorly with GHA and often incurs into cache requests rate limits. We should
# probably explore `sccache` with a different backend.
# - If a job makes good use of extra cores, consider give it a bigger machine.
# GHA larger runners increase in cost linearly with the number of cores
# (https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions),
# so you're not wasting money unless several cores are sitting idle for long.
on:
# Relevant docs:
# - https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue#how-merge-queues-work
# - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
merge_group:
types: ["checks_requested"]
push:
branches: ["nightly", "stable"]
pull_request:
branches: ["nightly", "stable"]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
# Automatically cancels a job if a new commit if pushed to the same PR, branch, or tag.
# Source: <https://stackoverflow.com/a/72408109/5148606>
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# Except in `nightly` and `stable` branches! Any cancelled job will cause the
# CI run to fail, and we want to keep a clean history for major branches.
cancel-in-progress: ${{ (github.ref == 'refs/heads/nightly') || (github.ref == 'refs/heads/stable') }}
jobs:
check:
name: check
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
shared-key: cargo-check
save-if: ${{ github.ref == 'refs/heads/nightly' }}
cache-all-crates: true # For cargo-hack.
workspaces: |
.
examples/demo-prover
- name: Run lint
run: |
if ! make lint ; then
echo "Linting or formatting errors detected, please run 'make lint-fix' to fix it";
exit 1
fi
# Check that every combination of features is working properly.
hack:
name: features
# `cargo-hack` uses the same profile as `cargo check` and doesn't require
# building dependencies, only chceking them, so we can share caches
# effectively.
needs: check
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- name: cargo install cargo-hack
uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
shared-key: cargo-check
save-if: ${{ github.ref == 'refs/heads/nightly' }}
cache-all-crates: true # For cargo-hack.
workspaces: |
.
examples/demo-prover
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
- name: cargo hack
run: make check-features
test:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
# `cargo-nextest` is much faster than standard `cargo test`.
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
with:
shared-key: cargo-build
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
examples/demo-prover
- run: cargo nextest run --workspace --all-features
# `cargo-nextest` does not support doctests (yet?), so we have to run them
# separately.
# TODO: https://github.com/nextest-rs/nextest/issues/16
- run: cargo test --workspace --doc --all-features
demo-rollup-local:
# `test` has already built dependencies, so we can share
# caches (the profile is `dev` in both cases).
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
shared-key: cargo-build
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
examples/demo-prover
- name: start celestia local
working-directory: ./examples/demo-rollup
run: make start
- name: start sovereign demo-rollup
working-directory: ./examples/demo-rollup
run: |
cargo build
../../target/debug/sov-demo-rollup &
- name: wait for service to be up
run: |
SECONDS=0
while ((SECONDS <= 1200))
do
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"],"id":1}' http://127.0.0.1:12345; then
echo "demo-rollup is up"
exit 0
fi
echo "Not up yet, sleeping for 3 seconds..."
sleep 3
SECONDS=$((SECONDS+3))
done
echo "demo-rollup took too long to start; exiting"
exit 1
- name: submit rollup transaction
working-directory: ./examples/demo-rollup
run: make test-create-token
- name: check token supply
# simple grep check on RPC to verify if the curl output contains "1000" which is the supply of token - could use jq and parse, but considering this won't change, it seems like a simple check to get it out quick
# if we want more complex parsing in the future and validation, we can switch to jq or other tools
run: |
SECONDS=0
while ((SECONDS <= 300))
do
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"],"id":1}' http://127.0.0.1:12345 | grep -q 1000; then
echo "demo-rollup test succeeded"
exit 0
fi
echo "Not up yet, sleeping for 3 seconds..."
sleep 3
SECONDS=$((SECONDS+3))
done
echo "demo-rollup took too long to process transaction; exiting"
exit 1
# TODO: Temporary before migration to RiscZero 0.15:
# https://github.com/Sovereign-Labs/sovereign-sdk/issues/338.
# After that demo-prover should be integrated into workspace.
# Note that `demo-prover` has (at the time of writing) a different `dev`
# profile from the rest of the codebase, so caches can't be shared.
check-demo-prover:
name: check demo prover
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v3
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
examples/demo-prover
- name: Run cargo check
working-directory: examples/demo-prover
run: cargo check
- name: Run cargo fmt check
run: |
cd examples/demo-prover;
if ! cargo fmt --check ; then
echo "Formatting errors detected, please run 'cargo fmt' to fix it";
exit 1
fi
coverage:
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- name: add llvm component
run: rustup component add llvm-tools-preview
- name: cargo install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
examples/demo-prover
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo llvm-cov
run: make coverage
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
# When retry is implemented, we can enable it again: https://github.com/codecov/codecov-action/issues/926
fail_ci_if_error: false
check-licenses:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: taiki-e/install-action@cargo-deny
- run: cargo deny check licenses
cargo-doc-artifact:
runs-on: ubuntu-latest
# `cargo doc` requires `cargo check`, so we can share caches.
needs: check
timeout-minutes: 90
steps:
- uses: actions/checkout@v3
# Not sure installing `mold` is actually needed, but it's what the
# `check` job does and their caches are shared, so it's best to keep
# things as similar as possible.
- uses: rui314/setup-mold@v1
- name: Install Rust
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
shared-key: cargo-check
save-if: ${{ github.ref == 'refs/heads/nightly' }}
workspaces: |
.
examples/demo-prover
# The docs' artifact tends to become quite large with all the
# dependencies, so we don't include them.
- run: cargo doc --no-deps --all-features
- name: Add index.html
# We're inside a Cargo workspace, so there's no index.html by default.
# We must redirect to one of the workspace member crates' documentation.
# <https://dev.to/deciduously/prepare-your-rust-api-docs-for-github-pages-2n5i>
run: echo '<meta http-equiv="refresh" content="0; url=sov_rollup_interface/index.html">' > target/doc/index.html
# https://github.com/actions/deploy-pages/issues/188
- name: Fix assets' file permissions
run: chmod -c -R +rX "target/doc"
- name: Upload artifacts
uses: actions/upload-pages-artifact@v1
with:
path: target/doc
deploy-github-pages:
needs: cargo-doc-artifact
timeout-minutes: 5
if: github.ref == 'refs/heads/stable'
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
check-demo-rollup-table-of-contents:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install -g doctoc
- name: Update table of contents
run: doctoc README.md --github --notitle
working-directory: ./examples/demo-rollup
- name: Check table of contents
# Exit status 0 means no changes were made, so the table of contents is
# up to date.
run: git diff --exit-code