Skip to content

Commit

Permalink
ci: move to Nix
Browse files Browse the repository at this point in the history
You can switch flawlessly from Rust stable, MSRV, and nightly using
either:

- `nix develop .`: Rust MRSV
- `nix develop .#msrv`: Rust MRSV
- `nix develop .#stable`: Rust latest stable
- `nix develop .#nightly`: Rust Nightly

Also you don't need to worry about installing binaries from `bitcoind`
or `electrs` crates,
since we fetch these from `nixpkgs` (with pinned versions) and add them
to your local environment.
Additionally, all the extra dependencies that you need for WASM are
handled as well.
Finally, no need to set ENV vars: they are also set all by default to
you.

If you are committing typos, or failing to adhere to our guidelines in
[CONTRIBUTING.md](CONTRIBUTING.md);
we won't let you commit or push.
This is handled by Nix's automated `pre-commit` hooks which gives
helpful error messages.

Please check the [Nix.md](Nix.md) file to learn more about Nix and what
we are aiming to do with the Nix integration into BDK.
  • Loading branch information
storopoli committed Sep 11, 2024
1 parent a4b4946 commit 8c8c1e4
Show file tree
Hide file tree
Showing 33 changed files with 6,587 additions and 194 deletions.
File renamed without changes.
13 changes: 6 additions & 7 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ name: Audit
on:
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
- "**/Cargo.toml"
- "**/Cargo.lock"
schedule:
- cron: '0 0 * * 0' # Once per week
- cron: "0 0 * * 0" # Once per week

jobs:

security_audit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
35 changes: 13 additions & 22 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ jobs:
Codecov:
name: Code Coverage
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-Cinstrument-coverage"
RUSTDOCFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "./target/coverage/%p-%m.profraw"

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install lcov tools
run: sudo apt-get install lcov -y
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: llvm-tools-preview
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/[email protected]
uses: Swatinem/rust-cache@v2
# Code Coverage
- name: Install grcov
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
run: nix develop -L ".#coverage" --command cargo install grcov
# TODO: re-enable the hwi tests
- name: Build simulator image
run: docker build -t hwi/ledger_emulator ./ci -f ci/Dockerfile.ledger
Expand All @@ -35,17 +26,17 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"
- name: Install python dependencies
run: pip install hwi==2.1.1 protobuf==3.20.1
- name: Test
run: cargo test --all-features
run: nix develop ".#coverage" -L --command cargo test --all-features
- name: Make coverage directory
run: mkdir coverage
- name: Run grcov
run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only '**/crates/**' --ignore '**/tests/**' --ignore '**/examples/**' -o ./coverage/lcov.info
run: nix develop ".#coverage" -L --command grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only '**/crates/**' --ignore '**/tests/**' --ignore '**/examples/**' -o ./coverage/lcov.info
- name: Generate HTML coverage report
run: genhtml -o coverage-report.html --ignore-errors source ./coverage/lcov.info
run: nix develop ".#coverage" -L --command genhtml -o coverage-report.html --ignore-errors source ./coverage/lcov.info
- name: Coveralls upload
uses: coverallsapp/github-action@master
with:
Expand Down
218 changes: 100 additions & 118 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,149 +3,133 @@ on: [push, pull_request]
name: CI

jobs:
self-care:
name: Flake self-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v9
with:
fail-mode: true

pre-commit-checks:
name: "Pre-commit checks: cargo fmt, typos, pgp-signed and conventional commits"
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Pre-commit checks
run: nix flake check

prepare:
clippy:
name: "Stable build, clippy and test"
runs-on: ubuntu-latest
outputs:
rust_version: ${{ steps.read_toolchain.outputs.rust_version }}
strategy:
matrix:
features:
- --no-default-features
- --all-features
steps:
- name: "Checkout repo"
- name: checkout
uses: actions/checkout@v4
- name: "Read rust version"
id: read_toolchain
run: echo "rust_version=$(cat rust-version)" >> $GITHUB_OUTPUT

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Build
run: nix develop -i -L .#stable --command cargo build ${{ matrix.features }}
- name: Clippy
run: nix develop -i -L .#stable --command cargo clippy ${{ matrix.features }} -- -D warnings
- name: Test
run: nix develop -i -L .#stable --command cargo test ${{ matrix.features }}

build-test:
name: Build and test
name: "MSRV build and test"
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- version: stable
clippy: true
- version: 1.63.0 # MSRV
features:
- --no-default-features
- --all-features
steps:
- name: checkout
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust.version }}
override: true
profile: minimal
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/[email protected]
- name: Pin dependencies for MSRV
if: matrix.rust.version == '1.63.0'
run: |
cargo update -p zstd-sys --precise "2.0.8+zstd.1.5.5"
cargo update -p time --precise "0.3.20"
cargo update -p home --precise "0.5.5"
cargo update -p proptest --precise "1.2.0"
cargo update -p url --precise "2.5.0"
cargo update -p cc --precise "1.0.105"
cargo update -p tokio --precise "1.38.1"
cargo update -p tokio-util --precise "0.7.11"
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build ${{ matrix.features }}
run: nix develop -i -L .#msrv --command cargo build ${{ matrix.features }}
- name: Test
run: cargo test ${{ matrix.features }}
run: nix develop -i -L .#msrv --command cargo test ${{ matrix.features }}

check-no-std:
name: Check no_std
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- msrv
- stable
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
# target: "thumbv6m-none-eabi"
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/[email protected]
uses: Swatinem/rust-cache@v2
# TODO "--target thumbv6m-none-eabi" should work but currently does not
- name: Check bdk_chain
working-directory: ./crates/chain
# TODO "--target thumbv6m-none-eabi" should work but currently does not
run: cargo check --no-default-features --features miniscript/no-std,hashbrown
- name: Check bdk wallet
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check --no-default-features --features miniscript/no-std,hashbrown
- name: Check bdk_wallet
working-directory: ./crates/wallet
# TODO "--target thumbv6m-none-eabi" should work but currently does not
run: cargo check --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check esplora
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check bdk_esplora
working-directory: ./crates/esplora
# TODO "--target thumbv6m-none-eabi" should work but currently does not
run: cargo check --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check --no-default-features --features miniscript/no-std,bdk_chain/hashbrown

check-wasm:
name: Check WASM
runs-on: ubuntu-20.04
env:
CC: clang-10
CFLAGS: -I/usr/include
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- msrv
- stable
target:
- wasm32-unknown-unknown
steps:
- name: Checkout
uses: actions/checkout@v2
# Install a recent version of clang that supports wasm32
- run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - || exit 1
- run: sudo apt-get update || exit 1
- run: sudo apt-get install -y libclang-common-10-dev clang-10 libc6-dev-i386 || exit 1
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
target: "wasm32-unknown-unknown"
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
- name: Check bdk wallet
uses: Swatinem/rust-cache@v2
- name: Check bdk_wallet
working-directory: ./crates/wallet
run: cargo check --target wasm32-unknown-unknown --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check esplora
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check --target ${{ matrix.target }} --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check bdk_esplora
working-directory: ./crates/esplora
run: cargo check --target wasm32-unknown-unknown --no-default-features --features miniscript/no-std,bdk_chain/hashbrown,async

fmt:
name: Rust fmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt
- name: Check fmt
run: cargo fmt --all -- --config format_code_in_doc_comments=true --check

clippy_check:
needs: prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ needs.prepare.outputs.rust_version }}
components: clippy
override: true
- name: Rust Cache
uses: Swatinem/[email protected]
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check --target ${{ matrix.target }} --no-default-features --features miniscript/no-std,bdk_chain/hashbrown,async

build-examples:
name: Build Examples
name: Build examples
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -160,15 +144,13 @@ jobs:
- wallet_rpc
steps:
- name: checkout
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
- name: Build
uses: Swatinem/rust-cache@v2
- name: Build examples
working-directory: example-crates/${{ matrix.example-dir }}
run: cargo build
run: nix develop -i -L .#stable --command cargo build
Loading

0 comments on commit 8c8c1e4

Please sign in to comment.