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.
  • Loading branch information
tcharding committed Apr 29, 2024
1 parent 4b3ac19 commit 7b21f8d
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 92 deletions.
141 changes: 84 additions & 57 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,89 @@
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

Lint:
name: Lint - 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: Install clippy
run: rustup component add clippy
- name: "Run test script"
run: ./contrib/run_task.sh lint

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 }}
126 changes: 126 additions & 0 deletions contrib/run_task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env bash
#
# Run CI task, called by the `rust.yml` GitHub action.

set -euox 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
- lint Run clippy
- 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"
local bitcoin_version="${2:-none}"

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)
build_and_test "+$MSRV"
;;

lint)
do_lint
;;

integration)
integration "$bitcoin_version"
;;

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

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

cargo "$toolchain" build --workspace
cargo "$toolchain" test --workspace
}

# Lint the workspace.
do_lint() {
cargo +nightly clippy --workspace --all-targets --keep-going -- -D warnings
}

# 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
35 changes: 0 additions & 35 deletions contrib/test.sh

This file was deleted.

0 comments on commit 7b21f8d

Please sign in to comment.