diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2e7d3d3a..6aeb8d20 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 }} diff --git a/client/Cargo.toml b/client/Cargo.toml index cb2573d1..1ec555d2 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -25,9 +25,9 @@ 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" diff --git a/contrib/run_task.sh b/contrib/run_task.sh new file mode 100755 index 00000000..97d3dde0 --- /dev/null +++ b/contrib/run_task.sh @@ -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 < /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 diff --git a/contrib/test.sh b/contrib/test.sh deleted file mode 100755 index e308ce3c..00000000 --- a/contrib/test.sh +++ /dev/null @@ -1,35 +0,0 @@ - -set -xe - -MSRV="1\.56" - -# Just echo all the relevant env vars to help debug Travis. -echo "RUSTFMTCHECK: \"$RUSTFMTCHECK\"" -echo "BITCOINVERSION: \"$BITCOINVERSION\"" -echo "PATH: \"$PATH\"" - -if [ -n "$RUSTFMTCHECK" ]; then - rustup component add rustfmt - cargo fmt --all -- --check -fi - -# Test pinned versions. -if cargo --version | grep ${MSRV}; then - cargo update -p tempfile --precise 3.3.0 - cargo update -p log --precise 0.4.18 -fi - -# Integration test. -if [ -n "$BITCOINVERSION" ]; then - wget https://bitcoincore.org/bin/bitcoin-core-$BITCOINVERSION/bitcoin-$BITCOINVERSION-x86_64-linux-gnu.tar.gz - tar -xzvf bitcoin-$BITCOINVERSION-x86_64-linux-gnu.tar.gz - export PATH=$PATH:$(pwd)/bitcoin-$BITCOINVERSION/bin - cd integration_test - ./run.sh - exit 0 -else - # Regular build/unit test. - cargo build --verbose - cargo test --verbose - cargo build --verbose --examples -fi diff --git a/json/Cargo.toml b/json/Cargo.toml index 8f3d67cc..63a85a56 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -20,7 +20,7 @@ name = "bitcoincore_rpc_json" path = "src/lib.rs" [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"]}