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 Aug 1, 2024
1 parent 785371e commit b1ca648
Show file tree
Hide file tree
Showing 33 changed files with 6,572 additions and 184 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 }}
37 changes: 14 additions & 23 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@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- 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,23 +26,23 @@ 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:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage-report.html
194 changes: 93 additions & 101 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,122 @@ 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@v7
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@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Pre-commit checks
run: nix develop -i -L .#stable --command pre-commit run --all-files

clippy:
name: "Stable build, clippy and test"
runs-on: ubuntu-latest
strategy:
matrix:
features:
- --no-default-features
- --all-features
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- 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@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- 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"
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@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- 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
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
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 -p bdk_chain --no-default-features --features miniscript/no-std,hashbrown
- name: Check bdk_wallet
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check -p bdk_wallet --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check bdk_esplora
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check -p bdk_esplora --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
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: Rust Cache
uses: Swatinem/[email protected]
- 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
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:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- msrv
- stable
target:
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.78.0
components: clippy
override: true
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
uses: Swatinem/rust-cache@v2
- name: Check bdk_wallet
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check -p bdk_wallet --target ${{ matrix.target }} --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
- name: Check bdk_esplora
run: nix develop -i -L ".#${{ matrix.rust }}" --command cargo check -p bdk_esplora --target ${{ matrix.target }} --no-default-features --features miniscript/no-std,bdk_chain/hashbrown,async
30 changes: 13 additions & 17 deletions .github/workflows/nightly_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@ jobs:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Set default toolchain
run: rustup default nightly-2024-05-12
- name: Set profile
run: rustup set profile minimal
- name: Update toolchain
run: rustup update
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
uses: Swatinem/rust-cache@v2
- name: Build docs
run: cargo doc --no-deps
env:
RUSTDOCFLAGS: '--cfg docsrs -Dwarnings'
run: nix develop -L '.#nightly' --command cargo doc --no-deps
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: built-docs
path: ./target/doc/*

publish_docs:
name: 'Publish docs'
name: "Publish docs"
if: github.ref == 'refs/heads/master'
needs: [build_docs]
runs-on: ubuntu-latest
steps:
- name: Checkout `bitcoindevkit.org`
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.DOCS_PUSH_SSH_KEY }}
repository: bitcoindevkit/bitcoindevkit.org
Expand All @@ -44,14 +40,14 @@ jobs:
- name: Remove old latest
run: rm -rf ./docs/.vuepress/public/docs-rs/bdk/nightly/latest
- name: Download built docs
uses: actions/download-artifact@v1
uses: actions/download-artifact@v3
with:
name: built-docs
path: ./docs/.vuepress/public/docs-rs/bdk/nightly/latest
- name: Configure git
run: git config user.email "[email protected]" && git config user.name "github-actions"
- name: Commit
continue-on-error: true # If there's nothing to commit this step fails, but it's fine
continue-on-error: true # If there's nothing to commit this step fails, but it's fine
run: git add ./docs/.vuepress/public/docs-rs && git commit -m "Publish autogenerated nightly docs"
- name: Push
run: git push origin master
21 changes: 21 additions & 0 deletions .github/workflows/update_flake_lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update Flake Lock File
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: "0 0 1 * *" # runs monthly on day 1 at 00:00

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@v21
with:
pr-title: "ci: update flake.lock" # Title of PR to be created
pr-labels: | # Labels to be set on the PR
dependencies
automated
Loading

0 comments on commit b1ca648

Please sign in to comment.