diff --git a/.github/actions/checkout-maintainer-tools/action.yml b/.github/actions/checkout-maintainer-tools/action.yml new file mode 100644 index 00000000..d675edf0 --- /dev/null +++ b/.github/actions/checkout-maintainer-tools/action.yml @@ -0,0 +1,11 @@ +name: Checkout Maintainer Tools +description: Checks out the rust-bitcoin maintainer tools repo +runs: + using: "composite" + steps: + - name: Checkout maintainer tools + uses: actions/checkout@v4 + with: + repository: rust-bitcoin/rust-bitcoin-maintainer-tools + ref: f92b2766865ce5327eca5cf72f86ceaa6be58ca4 + path: maintainer-tools diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 00000000..39315c45 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,171 @@ +on: # yamllint disable-line rule:truthy + pull_request: + push: + branches: + - master + - 'test-ci/**' + +name: Continuous integration + +jobs: + Prepare: + runs-on: ubuntu-latest + outputs: + nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }} + msrv_version: ${{ steps.read_msrv.outputs.msrv_version }} + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Read nightly version" + id: read_toolchain + run: | + set -euo pipefail + version=$(cat nightly-version) + echo "nightly_version=$version" >> $GITHUB_OUTPUT + - name: Read MSRV from clippy.toml + id: read_msrv + run: | + set -euo pipefail + msrv=$(grep '^msrv *= *"' clippy.toml | sed -E 's/.*"([^"]+)".*/\1/') + echo "msrv_version=$msrv" >> "$GITHUB_OUTPUT" + + Stable: + name: Test - stable toolchain + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh stable + + Nightly: + name: Test - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh nightly + + MSRV: + name: Test - MSRV + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ needs.Prepare.outputs.msrv_version }} + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh msrv + + Lint: + name: Lint - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: Install clippy + run: rustup component add clippy + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh lint + + Docs: + name: Docs - stable toolchain + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh docs + + Docsrs: + name: Docs - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dep: [recent] + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Checkout maintainer tools" + uses: ./.github/actions/checkout-maintainer-tools + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Run test script" + run: ./maintainer-tools/ci/run_task.sh docsrs + + Format: + name: Format - nightly toolchain + needs: Prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ needs.Prepare.outputs.nightly_version }} + - name: "Install rustfmt" + run: rustup component add rustfmt + - name: "Check formatting" + run: cargo fmt --all -- --check + + Wasm: + name: Check WASM + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout Crate + uses: actions/checkout@v3 + - name: Checkout Toolchain + uses: dtolnay/rust-toolchain@stable + - run: rustup target add wasm32-unknown-unknown + - run: cargo check --target wasm32-unknown-unknown diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 219b0f81..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,154 +0,0 @@ -name: Test -on: - push: - pull_request: -jobs: - check-flake: - name: Check flake - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Check flake - run: nix flake check --all-systems - - test-stable: - name: Test - stable toolchain - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Run all checks - run: | - nix develop .#ci --command bash -c "just check" - - test-msrv: - name: Test - MSRV toolchain - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Run unit tests - run: | - nix develop .#msrv --command bash -c "just test" - - test-windows: - name: Test - stable toolchain (windows-latest) - runs-on: windows-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Install just - uses: extractions/setup-just@v2 - - - name: Run unit tests - run: just test - - test-fuzz: - name: Test - fuzzer - runs-on: ubuntu-latest - needs: test-stable - strategy: - matrix: - fuzz_target: - - compile_parse_tree - - compile_text - - display_parse_tree - - parse_value_rtt - - parse_witness_json_rtt - - parse_witness_module_rtt - - reconstruct_value - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Run fuzz target ${{ matrix.fuzz_target }} - run: | - nix develop .#fuzz --command bash -c "just fuzz ${{ matrix.fuzz_target }}" - - build-integration: - name: Build - integration tests - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Build each integration test - run: | - nix develop .#ci --command bash -c "just build_integration" - - build-wasm: - name: Build - WASM - runs-on: ubuntu-latest - needs: test-stable - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install nix - uses: cachix/install-nix-action@v24 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - name: Enable Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Build WASM library - run: | - nix develop .#wasm --command bash -c "just build_wasm" diff --git a/contrib/crates.sh b/contrib/crates.sh new file mode 100755 index 00000000..48876bab --- /dev/null +++ b/contrib/crates.sh @@ -0,0 +1,9 @@ +# Sourced by `rust-bitcoin-maintainer-tools/ci/run_task.sh`. +# +# No shebang, this file should not be executed. +# shellcheck disable=SC2148 +# +# disable verify unused vars, despite the fact that they are used when sourced +# shellcheck disable=SC2034 + +CRATES=(. codegen) \ No newline at end of file diff --git a/contrib/extra_tests.sh b/contrib/extra_tests.sh new file mode 100755 index 00000000..ad4f52be --- /dev/null +++ b/contrib/extra_tests.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -ex + +REPO_DIR=$(git rev-parse --show-toplevel) + +# Make all cargo invocations verbose. +export CARGO_TERM_VERBOSE=true + +# Set to false to turn off verbose output. +flag_verbose=true + +main() { + source_test_vars # Get feature list. + + # FIXME put bitcoind-tests in here + echo "No tests, all good." +} + +# ShellCheck can't follow non-constant source, `test_vars_script` is correct. +# shellcheck disable=SC1090 +source_test_vars() { + local test_vars_script="$REPO_DIR/contrib/test_vars.sh" + + verbose_say "Sourcing $test_vars_script" + + if [ -e "$test_vars_script" ]; then + # Set crate specific variables. + . "$test_vars_script" + else + err "Missing $test_vars_script" + fi +} + +say() { + echo "extra_tests: $1" +} + +verbose_say() { + if [ "$flag_verbose" = true ]; then + say "$1" + fi +} + +err() { + echo "$1" >&2 + exit 1 +} + +# +# Main script +# +main "$@" +exit 0 diff --git a/contrib/test_vars.sh b/contrib/test_vars.sh new file mode 100644 index 00000000..0d9e0da9 --- /dev/null +++ b/contrib/test_vars.sh @@ -0,0 +1,14 @@ +# No shebang, this file should not be executed. +# shellcheck disable=SC2148 +# +# disable verify unused vars, despite the fact that they are used when sourced +# shellcheck disable=SC2034 + +# Test all these features with "std" enabled. +FEATURES_WITH_STD="" + +# Test all these features without "std" enabled. +FEATURES_WITHOUT_STD="serde arbitrary" + +# Run these examples. +EXAMPLES="$(cargo metadata --no-deps --format-version 1 |jq -r '.packages | .[] | .targets | .[] | select(.kind == ["example"]) | .name + ":"')" diff --git a/nightly-version b/nightly-version new file mode 100644 index 00000000..d361064a --- /dev/null +++ b/nightly-version @@ -0,0 +1 @@ +nightly-2025-08-23