Skip to content

Commit bffc9a6

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.
1 parent 05901c9 commit bffc9a6

File tree

3 files changed

+215
-92
lines changed

3 files changed

+215
-92
lines changed

.github/workflows/rust.yml

Lines changed: 82 additions & 57 deletions
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 }}

contrib/run_task.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
- lint Run clippy
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+
build_and_test "+$MSRV"
63+
;;
64+
65+
lint)
66+
do_lint
67+
;;
68+
69+
integration)
70+
integration "$bitcoin_version"
71+
;;
72+
73+
*)
74+
echo ""
75+
usage
76+
err "Error: unknown task $task"
77+
;;
78+
esac
79+
}
80+
81+
# Build and test workspace.
82+
build_and_test() {
83+
local toolchain="$1"
84+
85+
cargo "$toolchain" build --workspace
86+
cargo "$toolchain" test --workspace
87+
}
88+
89+
# Lint the workspace.
90+
do_lint() {
91+
cargo +nightly clippy --workspace --all-targets --keep-going -- -D warnings
92+
}
93+
94+
# Pulls down Bitcoin Core binary and runs the integration tests.
95+
integration() {
96+
local core_version="$1"
97+
98+
cd "$REPO_DIR"
99+
100+
if [ "$core_version" != "none" ]; then
101+
wget "https://bitcoincore.org/bin/bitcoin-core-$bitcoin_version/bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
102+
tar -xzvf "bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
103+
export PATH=$PATH:"$REPO_DIR/bitcoin-$bitcoin_version/bin"
104+
fi
105+
106+
need_cmd "bitcoind"
107+
108+
cd "$REPO_DIR/integration_test"
109+
./run.sh
110+
}
111+
112+
# Check all the commands we use are present in the current environment.
113+
check_required_commands() {
114+
need_cmd cargo
115+
need_cmd rustc
116+
}
117+
118+
need_cmd() {
119+
if ! command -v "$1" > /dev/null 2>&1
120+
then err "need '$1' (command not found)"
121+
fi
122+
}
123+
124+
err() {
125+
echo "$1" >&2
126+
exit 1
127+
}
128+
129+
#
130+
# Main script
131+
#
132+
main "$@"
133+
exit 0

contrib/test.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)