Skip to content

Commit 3017886

Browse files
committed
ci: copy workflow and contrib/ scripts from rust-elements
This introduces the rust-bitcoin-maintainer-tools CI setup, which ensures that all tool versions are pinned, tests all examples, etc. I had to tweak a couple things (replacing the list of features, renaming elementsd-tests to bitcoind-tests) but otherwise this was a straight copy/paste. We also update all our CI actions to v4 from the now-deleted v2.
1 parent ae79633 commit 3017886

File tree

8 files changed

+255
-134
lines changed

8 files changed

+255
-134
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Checkout Maintainer Tools
2+
description: Checks out the rust-bitcoin maintainer tools repo
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Checkout maintainer tools
7+
uses: actions/checkout@v4
8+
with:
9+
repository: rust-bitcoin/rust-bitcoin-maintainer-tools
10+
ref: f92b2766865ce5327eca5cf72f86ceaa6be58ca4
11+
path: maintainer-tools

.github/workflows/rust.yml

Lines changed: 157 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,183 @@
1-
on:
1+
on: # yamllint disable-line rule:truthy
2+
pull_request:
23
push:
34
branches:
45
- master
5-
pull_request: {}
6+
- 'test-ci/**'
67

78
name: Continuous integration
89

910
jobs:
10-
lint_fuzz_stable:
11-
name: Lint
11+
Prepare:
1212
runs-on: ubuntu-latest
13+
outputs:
14+
nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }}
15+
msrv_version: ${{ steps.read_msrv.outputs.msrv_version }}
1316
steps:
14-
- name: Checkout Crate
15-
uses: actions/checkout@v2
16-
- name: Install hongfuzz dependancies
17-
run: sudo apt-get update -y && sudo apt install -y build-essential binutils-dev libunwind-dev libblocksruntime-dev liblzma-dev
18-
- name: Checkout Toolchain
19-
uses: actions-rs/toolchain@v1
20-
with:
21-
profile: minimal
22-
toolchain: 1.63.0
23-
override: true
24-
- name: Running fuzzer
25-
env:
26-
DO_LINT: true
27-
run: ./contrib/test.sh
17+
- name: "Checkout repo"
18+
uses: actions/checkout@v4
19+
- name: "Read nightly version"
20+
id: read_toolchain
21+
run: |
22+
set -euo pipefail
23+
version=$(cat nightly-version)
24+
echo "nightly_version=$version" >> $GITHUB_OUTPUT
25+
- name: Read MSRV from clippy.toml
26+
id: read_msrv
27+
run: |
28+
set -euo pipefail
29+
msrv=$(grep '^msrv *= *"' clippy.toml | sed -E 's/.*"([^"]+)".*/\1/')
30+
echo "msrv_version=$msrv" >> "$GITHUB_OUTPUT"
31+
32+
Stable:
33+
name: Test - stable toolchain
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
steps:
38+
- name: "Checkout repo"
39+
uses: actions/checkout@v4
40+
- name: "Checkout maintainer tools"
41+
uses: ./.github/actions/checkout-maintainer-tools
42+
- name: "Select toolchain"
43+
uses: dtolnay/rust-toolchain@stable
44+
- name: "Set dependencies"
45+
run: cp Cargo-latest.lock Cargo.lock
46+
- name: "Run test script"
47+
run: ./maintainer-tools/ci/run_task.sh stable
2848

2949
Nightly:
30-
name: Nightly - Bench + Docs + Fmt
50+
name: Test - nightly toolchain
51+
needs: Prepare
3152
runs-on: ubuntu-latest
53+
strategy:
54+
fail-fast: false
3255
steps:
33-
- name: Checkout Crate
34-
uses: actions/checkout@v2
35-
- name: Checkout Toolchain
36-
uses: actions-rs/toolchain@v1
56+
- name: "Checkout repo"
57+
uses: actions/checkout@v4
58+
- name: "Checkout maintainer tools"
59+
uses: ./.github/actions/checkout-maintainer-tools
60+
- name: "Select toolchain"
61+
uses: dtolnay/rust-toolchain@v1
3762
with:
38-
profile: minimal
39-
toolchain: nightly
40-
override: true
41-
- name: Running benchmarks
42-
env:
43-
DO_BENCH: true
44-
run: ./contrib/test.sh
45-
- name: Building docs
46-
env:
47-
DO_DOCS: true
48-
run: ./contrib/test.sh
63+
toolchain: ${{ needs.Prepare.outputs.nightly_version }}
64+
- name: "Set dependencies"
65+
run: cp Cargo-latest.lock Cargo.lock
66+
- name: "Run test script"
67+
run: ./maintainer-tools/ci/run_task.sh nightly
4968

50-
Int-tests:
51-
name: Integration tests
69+
MSRV:
70+
name: Test - MSRV
71+
needs: Prepare
5272
runs-on: ubuntu-latest
73+
strategy:
74+
fail-fast: false
5375
steps:
54-
- name: Checkout Crate
55-
uses: actions/checkout@v2
56-
- name: Checkout Toolchain
57-
uses: actions-rs/toolchain@v1
76+
- name: "Checkout repo"
77+
uses: actions/checkout@v4
78+
- name: "Checkout maintainer tools"
79+
uses: ./.github/actions/checkout-maintainer-tools
80+
- name: "Select toolchain"
81+
uses: dtolnay/rust-toolchain@stable
5882
with:
59-
profile: minimal
60-
toolchain: stable
61-
override: true
62-
- name: Running integration tests
63-
env:
64-
DO_BITCOIND_TESTS: true
65-
run: ./contrib/test.sh
83+
toolchain: ${{ needs.Prepare.outputs.msrv_version }}
84+
- name: "Set dependencies"
85+
run: cp Cargo-latest.lock Cargo.lock
86+
- name: "Run test script"
87+
run: ./maintainer-tools/ci/run_task.sh msrv
6688

67-
Tests:
68-
name: Tests
89+
Lint:
90+
name: Lint - nightly toolchain
91+
needs: Prepare
6992
runs-on: ubuntu-latest
7093
strategy:
7194
fail-fast: false
7295
matrix:
73-
rust: [stable, beta, nightly, 1.63.0]
96+
dep: [recent]
97+
steps:
98+
- name: "Checkout repo"
99+
uses: actions/checkout@v4
100+
- name: "Checkout maintainer tools"
101+
uses: ./.github/actions/checkout-maintainer-tools
102+
- name: "Select toolchain"
103+
uses: dtolnay/rust-toolchain@v1
104+
with:
105+
toolchain: ${{ needs.Prepare.outputs.nightly_version }}
106+
- name: Install clippy
107+
run: rustup component add clippy
108+
- name: "Set dependencies"
109+
run: cp Cargo-latest.lock Cargo.lock
110+
- name: "Run test script"
111+
run: ./maintainer-tools/ci/run_task.sh lint
112+
113+
Docs:
114+
name: Docs - stable toolchain
115+
runs-on: ubuntu-latest
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
dep: [recent]
120+
steps:
121+
- name: "Checkout repo"
122+
uses: actions/checkout@v4
123+
- name: "Checkout maintainer tools"
124+
uses: ./.github/actions/checkout-maintainer-tools
125+
- name: "Select toolchain"
126+
uses: dtolnay/rust-toolchain@stable
127+
- name: "Set dependencies"
128+
run: cp Cargo-latest.lock Cargo.lock
129+
- name: "Run test script"
130+
run: ./maintainer-tools/ci/run_task.sh docs
131+
132+
Docsrs:
133+
name: Docs - nightly toolchain
134+
needs: Prepare
135+
runs-on: ubuntu-latest
136+
strategy:
137+
fail-fast: false
138+
matrix:
139+
dep: [recent]
140+
steps:
141+
- name: "Checkout repo"
142+
uses: actions/checkout@v4
143+
- name: "Checkout maintainer tools"
144+
uses: ./.github/actions/checkout-maintainer-tools
145+
- name: "Select toolchain"
146+
uses: dtolnay/rust-toolchain@v1
147+
with:
148+
toolchain: ${{ needs.Prepare.outputs.nightly_version }}
149+
- name: "Set dependencies"
150+
run: cp Cargo-latest.lock Cargo.lock
151+
- name: "Run test script"
152+
run: ./maintainer-tools/ci/run_task.sh docsrs
153+
154+
# Format:
155+
# name: Format - nightly toolchain
156+
# needs: Prepare
157+
# runs-on: ubuntu-latest
158+
# strategy:
159+
# fail-fast: false
160+
# steps:
161+
# - name: "Checkout repo"
162+
# uses: actions/checkout@v4
163+
# - name: "Select toolchain"
164+
# uses: dtolnay/rust-toolchain@v1
165+
# with:
166+
# toolchain: ${{ needs.Prepare.outputs.nightly_version }}
167+
# - name: "Install rustfmt"
168+
# run: rustup component add rustfmt
169+
# - name: "Check formatting"
170+
# run: cargo fmt --all -- --check
171+
172+
Wasm:
173+
name: Check WASM
174+
runs-on: ubuntu-latest
175+
strategy:
176+
fail-fast: false
74177
steps:
75178
- name: Checkout Crate
76-
uses: actions/checkout@v2
179+
uses: actions/checkout@v3
77180
- name: Checkout Toolchain
78-
uses: actions-rs/toolchain@v1
79-
with:
80-
profile: minimal
81-
toolchain: ${{ matrix.rust }}
82-
override: true
83-
- name: Running cargo
84-
env:
85-
DO_FEATURE_MATRIX: true
86-
run: ./contrib/test.sh
181+
uses: dtolnay/rust-toolchain@stable
182+
- run: rustup target add wasm32-unknown-unknown
183+
- run: cargo check --target wasm32-unknown-unknown

Cargo-latest.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ dependencies = [
268268
"base64 0.13.1",
269269
"bitcoin 0.32.7",
270270
"elements",
271+
"getrandom 0.2.16",
271272
"miniscript",
272273
"rand",
273274
"secp256k1 0.29.1",

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ simplicity = { package = "simplicity-lang", version = "0.3.0", optional = true }
2828
# Do NOT use this as a feature! Use the `serde` feature instead.
2929
actual-serde = { package = "serde", version = "1.0", optional = true }
3030

31+
[target.wasm32-unknown-unknown.dev-dependencies]
32+
getrandom = { version = "0.2", features = ["js"] }
33+
3134
[dev-dependencies]
3235
serde_json = "1.0"
3336
actual-rand = { package = "rand", version = "0.8.4"}

contrib/crates.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Sourced by `rust-bitcoin-maintainer-tools/ci/run_task.sh`.
2+
#
3+
# No shebang, this file should not be executed.
4+
# shellcheck disable=SC2148
5+
#
6+
# disable verify unused vars, despite the fact that they are used when sourced
7+
# shellcheck disable=SC2034
8+
9+
CRATES=(. bitcoind-tests)

contrib/extra_tests.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
REPO_DIR=$(git rev-parse --show-toplevel)
6+
7+
# Make all cargo invocations verbose.
8+
export CARGO_TERM_VERBOSE=true
9+
10+
# Set to false to turn off verbose output.
11+
flag_verbose=true
12+
13+
main() {
14+
source_test_vars # Get feature list.
15+
16+
BITCOIND_EXE_DEFAULT="$(git rev-parse --show-toplevel)/bitcoind-tests/bin/bitcoind"
17+
ELEMENTSD_EXE_DEFAULT="$(git rev-parse --show-toplevel)/bitcoind-tests/bin/elementsd"
18+
19+
cd bitcoind-tests
20+
BITCOIND_EXE=${BITCOIND_EXE:=${BITCOIND_EXE_DEFAULT}} \
21+
ELEMENTSD_EXE=${ELEMENTSD_EXE:=${ELEMENTSD_EXE_DEFAULT}} \
22+
cargo --locked test
23+
cd ..
24+
}
25+
26+
# ShellCheck can't follow non-constant source, `test_vars_script` is correct.
27+
# shellcheck disable=SC1090
28+
source_test_vars() {
29+
local test_vars_script="$REPO_DIR/contrib/test_vars.sh"
30+
31+
verbose_say "Sourcing $test_vars_script"
32+
33+
if [ -e "$test_vars_script" ]; then
34+
# Set crate specific variables.
35+
. "$test_vars_script"
36+
else
37+
err "Missing $test_vars_script"
38+
fi
39+
}
40+
41+
say() {
42+
echo "extra_tests: $1"
43+
}
44+
45+
verbose_say() {
46+
if [ "$flag_verbose" = true ]; then
47+
say "$1"
48+
fi
49+
}
50+
51+
err() {
52+
echo "$1" >&2
53+
exit 1
54+
}
55+
56+
#
57+
# Main script
58+
#
59+
main "$@"
60+
exit 0

0 commit comments

Comments
 (0)