Skip to content

Commit

Permalink
Re-write CI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tcharding committed May 1, 2024
1 parent 3655197 commit f752adc
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 62 deletions.
139 changes: 82 additions & 57 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,87 @@
on: [push, pull_request]
on:
push:
branches:
- master
- 'test-ci/**'
pull_request:

name: Continuous integration

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rust: stable
env:
RUSTFMTCHK: true
- rust: nightly
env:
RUSTFMTCHK: false
- rust: 1.56.1
env:
RUSTFMTCHK: false
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Running test script
env: ${{ matrix.env }}
run: ./contrib/test.sh
Stable:
name: Test - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: "Run test script"
run: ./contrib/run_task.sh stable

integrations-tests:
name: Integration Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable]
bitcoinversion:
[
"0.18.0",
"0.18.1",
"0.19.0.1",
"0.19.1",
"0.20.0",
"0.20.1",
"0.21.0",
]
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Running test script
env:
BITCOINVERSION: ${{ matrix.bitcoinversion }}
run: ./contrib/test.sh
Nightly:
name: Test - nightly toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@nightly
- name: "Run test script"
run: ./contrib/run_task.sh nightly

MSRV:
name: Test - 1.56.1 toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.56.1"
- name: "Run test script"
run: ./contrib/run_task.sh msrv

Format:
name: Format - nightly toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: "Check formatting"
run: cargo fmt --all -- --check

Integration:
name: Integration Tests - stable toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bitcoin_version:
[
"0.18.0",
"0.18.1",
"0.19.0.1",
"0.19.1",
"0.20.0",
"0.20.1",
"0.21.0",
]
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@stable
- name: Running test script
run: ./contrib/run_task.sh integration ${{ matrix.bitcoin_version }}
6 changes: 3 additions & 3 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ log = "0.4.5"
jsonrpc = "0.14.0"

# Used for deserialization of JSON.
serde = "1"
serde_json = "1"
serde = "1.0.156"
serde_json = "1.0.96"

[dev-dependencies]
tempfile = "3.3.0"
tempfile = "3.6.0"

[[example]]
name = "retry_client"
Expand Down
149 changes: 149 additions & 0 deletions contrib/run_task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env bash
#
# Run CI task, called by the `rust.yml` GitHub action.

set -euo pipefail

REPO_DIR=$(git rev-parse --show-toplevel)
MSRV="1.56.1"

usage() {
cat <<EOF
Usage:
./run_task.sh TASK
TASK
- stable Run stable toolchain tests.
- nightly Run nightly toolchain tests.
- msrv Run MSRV toolchain tests.
- fmt Run the formatter (rustfmt).
- integration Run integration test for specific Bitcoin Core version.
./run_task.sh integration BITCOIN_CORE_VERSION [DOWNLOAD_CORE]
Example
./run_task.sh integration # Runs integration tests against bitcoind from your path.
./run_task.sh integration 0.21.0 # Downloads Core version 0.21.0 and runs integration tests againts it.
EOF
}

# Make all cargo invocations verbose.
export CARGO_TERM_VERBOSE=true

main() {
local task="${1:-usage}"
local bitcoin_version="${2:-none}"

if [ "$task" = "usage" ] || [ "$task" = "-h" ] || [ "$task" = "--help" ]; then
usage
exit 0
fi

check_required_commands

cargo --version
rustc --version
/usr/bin/env bash --version
locale
env

case $task in
stable)
build_and_test "+stable"
;;

nightly)
build_and_test "+nightly"
;;

msrv)
do_msrv_pins
build_and_test "+$MSRV"
;;

fmt)
do_fmt
;;

integration)
integration "$bitcoin_version"
;;

*)
echo ""
usage
err "Error: unknown task $task"
;;
esac
}

# Build and test workspace.
build_and_test() {
local toolchain="$1"

for crate in json client integration_test; do
pushd "$REPO_DIR/$crate" > /dev/null;

cargo "$toolchain" build
cargo "$toolchain" test

popd > /dev/null
done
}

# Pin dependencies to get the MSRV build to work.
do_msrv_pins() {
cargo update -p tempfile --precise 3.6.0
cargo update -p cc --precise 1.0.79
cargo update -p log --precise 0.4.18
cargo update -p serde_json --precise 1.0.96
cargo update -p serde --precise 1.0.156
}

# Check the workspace formatting.
do_fmt() {
cargo +stable fmt --all --check
}

# Pulls down Bitcoin Core binary and runs the integration tests.
integration() {
local core_version="$1"

cd "$REPO_DIR"

if [ "$core_version" != "none" ]; then
wget "https://bitcoincore.org/bin/bitcoin-core-$bitcoin_version/bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
tar -xzvf "bitcoin-$bitcoin_version-x86_64-linux-gnu.tar.gz"
export PATH=$PATH:"$REPO_DIR/bitcoin-$bitcoin_version/bin"
fi

need_cmd "bitcoind"

cd "$REPO_DIR/integration_test"
./run.sh
}

# Check all the commands we use are present in the current environment.
check_required_commands() {
need_cmd cargo
need_cmd rustc
}

need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
then err "need '$1' (command not found)"
fi
}

err() {
echo "$1" >&2
exit 1
}

#
# Main script
#
main "$@"
exit 0
4 changes: 2 additions & 2 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ path = "src/lib.rs"
verifymessage = ["bitcoin/base64"]

[dependencies]
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
serde = { version = "1.0.156", features = [ "derive" ] }
serde_json = "1.0.96"

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

0 comments on commit f752adc

Please sign in to comment.