Skip to content

Commit 4b2a5c5

Browse files
committed
Re-write CI
Re-write CI in a similar manner to what we did in `rust-bitcoin` recently. Some benefits: - The `contrib/run_task.sh` can be used from the command line. - GitHub action is dumber i.e., all the logic is in the shell script instead of spread between the action and the script. - The action yaml is [hopefully] a bit cleaner. Covearge is the same, three toolchains, linter, integration tests for various Core versions. Includes a bunch of pinning for MSRV that seems to currently be broken, I'm not exactly sure when it broke.
1 parent 7d76937 commit 4b2a5c5

File tree

5 files changed

+230
-97
lines changed

5 files changed

+230
-97
lines changed

.github/workflows/rust.yml

+82-57
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,87 @@
1-
on: [push, pull_request]
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- 'test-ci/**'
6+
pull_request:
27

38
name: Continuous integration
49

510
jobs:
6-
tests:
7-
name: Tests
8-
runs-on: ubuntu-latest
9-
strategy:
10-
matrix:
11-
include:
12-
- rust: stable
13-
env:
14-
RUSTFMTCHK: true
15-
- rust: nightly
16-
env:
17-
RUSTFMTCHK: false
18-
- rust: 1.56.1
19-
env:
20-
RUSTFMTCHK: false
21-
steps:
22-
- name: Checkout Crate
23-
uses: actions/checkout@v2
24-
- name: Checkout Toolchain
25-
uses: actions-rs/toolchain@v1
26-
with:
27-
profile: minimal
28-
toolchain: ${{ matrix.rust }}
29-
override: true
30-
- name: Running test script
31-
env: ${{ matrix.env }}
32-
run: ./contrib/test.sh
11+
Stable:
12+
name: Test - stable toolchain
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
steps:
17+
- name: "Checkout repo"
18+
uses: actions/checkout@v4
19+
- name: "Select toolchain"
20+
uses: dtolnay/rust-toolchain@stable
21+
- name: "Run test script"
22+
run: ./contrib/run_task.sh stable
3323

34-
integrations-tests:
35-
name: Integration Tests
36-
runs-on: ubuntu-latest
37-
strategy:
38-
matrix:
39-
rust: [stable]
40-
bitcoinversion:
41-
[
42-
"0.18.0",
43-
"0.18.1",
44-
"0.19.0.1",
45-
"0.19.1",
46-
"0.20.0",
47-
"0.20.1",
48-
"0.21.0",
49-
]
50-
steps:
51-
- name: Checkout Crate
52-
uses: actions/checkout@v2
53-
- name: Checkout Toolchain
54-
uses: actions-rs/toolchain@v1
55-
with:
56-
profile: minimal
57-
toolchain: ${{ matrix.rust }}
58-
override: true
59-
- name: Running test script
60-
env:
61-
BITCOINVERSION: ${{ matrix.bitcoinversion }}
62-
run: ./contrib/test.sh
24+
Nightly:
25+
name: Test - nightly toolchain
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
steps:
30+
- name: "Checkout repo"
31+
uses: actions/checkout@v4
32+
- name: "Select toolchain"
33+
uses: dtolnay/rust-toolchain@nightly
34+
- name: "Run test script"
35+
run: ./contrib/run_task.sh nightly
36+
37+
MSRV:
38+
name: Test - 1.56.1 toolchain
39+
runs-on: ubuntu-latest
40+
strategy:
41+
fail-fast: false
42+
steps:
43+
- name: "Checkout repo"
44+
uses: actions/checkout@v4
45+
- name: "Select toolchain"
46+
uses: dtolnay/rust-toolchain@stable
47+
with:
48+
toolchain: "1.56.1"
49+
- name: "Run test script"
50+
run: ./contrib/run_task.sh msrv
51+
52+
Format:
53+
name: Format - nightly toolchain
54+
runs-on: ubuntu-latest
55+
strategy:
56+
fail-fast: false
57+
steps:
58+
- name: "Checkout repo"
59+
uses: actions/checkout@v4
60+
- name: "Select toolchain"
61+
uses: dtolnay/rust-toolchain@stable
62+
- name: "Check formatting"
63+
run: cargo fmt --all -- --check
64+
65+
Integration:
66+
name: Integration Tests - stable toolchain
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
bitcoin_version:
72+
[
73+
"0.18.0",
74+
"0.18.1",
75+
"0.19.0.1",
76+
"0.19.1",
77+
"0.20.0",
78+
"0.20.1",
79+
"0.21.0",
80+
]
81+
steps:
82+
- name: "Checkout repo"
83+
uses: actions/checkout@v4
84+
- name: "Select toolchain"
85+
uses: dtolnay/rust-toolchain@stable
86+
- name: Running test script
87+
run: ./contrib/run_task.sh integration ${{ matrix.bitcoin_version }}

client/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ log = "0.4.5"
2525
jsonrpc = "0.14.0"
2626

2727
# Used for deserialization of JSON.
28-
serde = "1"
29-
serde_json = "1"
28+
serde = "1.0.156"
29+
serde_json = "1.0.96"
3030

3131
[dev-dependencies]
32-
tempfile = "3.3.0"
32+
tempfile = "3.6.0"
3333

contrib/run_task.sh

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run CI task, called by the `rust.yml` GitHub action.
4+
5+
set -euo pipefail
6+
7+
REPO_DIR=$(git rev-parse --show-toplevel)
8+
MSRV="1.56.1"
9+
10+
usage() {
11+
cat <<EOF
12+
Usage:
13+
14+
./run_task.sh TASK
15+
16+
TASK
17+
- stable Run stable toolchain tests.
18+
- nightly Run nightly toolchain tests.
19+
- msrv Run MSRV toolchain tests.
20+
- fmt Run the formatter (rustfmt).
21+
- integration Run integration test for specific Bitcoin Core version.
22+
23+
./run_task.sh integration BITCOIN_CORE_VERSION [DOWNLOAD_CORE]
24+
25+
Example
26+
./run_task.sh integration # Runs integration tests against bitcoind from your path.
27+
./run_task.sh integration 0.21.0 # Downloads Core version 0.21.0 and runs integration tests againts it.
28+
29+
EOF
30+
}
31+
32+
# Make all cargo invocations verbose.
33+
export CARGO_TERM_VERBOSE=true
34+
35+
main() {
36+
local task="${1:-usage}"
37+
local bitcoin_version="${2:-none}"
38+
39+
if [ "$task" = "usage" ] || [ "$task" = "-h" ] || [ "$task" = "--help" ]; then
40+
usage
41+
exit 0
42+
fi
43+
44+
check_required_commands
45+
46+
cargo --version
47+
rustc --version
48+
/usr/bin/env bash --version
49+
locale
50+
env
51+
52+
case $task in
53+
stable)
54+
build_and_test "+stable"
55+
;;
56+
57+
nightly)
58+
build_and_test "+nightly"
59+
;;
60+
61+
msrv)
62+
do_msrv_pins
63+
build_and_test "+$MSRV"
64+
;;
65+
66+
fmt)
67+
do_fmt
68+
;;
69+
70+
integration)
71+
integration "$bitcoin_version"
72+
;;
73+
74+
*)
75+
echo ""
76+
usage
77+
err "Error: unknown task $task"
78+
;;
79+
esac
80+
}
81+
82+
# Build and test workspace.
83+
build_and_test() {
84+
local toolchain="$1"
85+
86+
cargo "$toolchain" build --workspace
87+
cargo "$toolchain" test --workspace
88+
}
89+
90+
# Pin dependencies to get the MSRV build to work.
91+
do_msrv_pins() {
92+
cargo update -p tempfile --precise 3.6.0
93+
cargo update -p cc --precise 1.0.79
94+
cargo update -p log --precise 0.4.18
95+
cargo update -p serde_json --precise 1.0.96
96+
cargo update -p serde --precise 1.0.156
97+
}
98+
99+
# Check the workspace formatting.
100+
do_fmt() {
101+
cargo +stable fmt --all --check
102+
}
103+
104+
# Pulls down Bitcoin Core binary and runs the integration tests.
105+
integration() {
106+
local core_version="$1"
107+
108+
cd "$REPO_DIR"
109+
110+
if [ "$core_version" != "none" ]; then
111+
wget "https://bitcoincore.org/bin/bitcoin-core-$bitcoin_version/bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
112+
tar -xzvf "bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
113+
export PATH=$PATH:"$REPO_DIR/bitcoin-$bitcoin_version/bin"
114+
fi
115+
116+
need_cmd "bitcoind"
117+
118+
cd "$REPO_DIR/integration_test"
119+
./run.sh
120+
}
121+
122+
# Check all the commands we use are present in the current environment.
123+
check_required_commands() {
124+
need_cmd cargo
125+
need_cmd rustc
126+
}
127+
128+
need_cmd() {
129+
if ! command -v "$1" > /dev/null 2>&1
130+
then err "need '$1' (command not found)"
131+
fi
132+
}
133+
134+
err() {
135+
echo "$1" >&2
136+
exit 1
137+
}
138+
139+
#
140+
# Main script
141+
#
142+
main "$@"
143+
exit 0

contrib/test.sh

-35
This file was deleted.

json/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ name = "bitcoincore_rpc_json"
2020
path = "src/lib.rs"
2121

2222
[dependencies]
23-
serde = { version = "1", features = [ "derive" ] }
24-
serde_json = "1"
23+
serde = { version = "1.0.156", features = [ "derive" ] }
24+
serde_json = "1.0.96"
2525

2626
bitcoin = { version = "0.31.0", features = ["serde", "rand-std"]}

0 commit comments

Comments
 (0)