Merge pull request #40 from Apocentre/chore/update_rust_toolset #121
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
env: | |
# https://doc.rust-lang.org/cargo/reference/profiles.html#release | |
RUSTFLAGS: -Coverflow-checks=y -Cdebug-assertions=y | |
# https://doc.rust-lang.org/cargo/reference/profiles.html#incremental | |
CARGO_INCREMENTAL: 1 | |
# https://nexte.st/book/pre-built-binaries.html#using-nextest-in-github-actions | |
CARGO_TERM_COLOR: always | |
jobs: | |
run_checks: | |
runs-on: ubuntu-latest | |
name: Run some basic checks and tests | |
steps: | |
# | |
# Setup | |
# | |
- name: Checkout PR | |
uses: actions/checkout@v2 | |
- name: Set up cargo/rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: "1.76.0" | |
components: rustfmt, clippy | |
# https://github.com/Swatinem/rust-cache | |
- name: Cache Rust stuff | |
uses: Swatinem/rust-cache@v1 | |
- name: Install latest nextest release | |
uses: taiki-e/install-action@nextest | |
- name: Run Bitcoin Core in regtest mode | |
run: | | |
set -eE | |
docker run -d --rm \ | |
--name bitcoind \ | |
-p 18443:18443 lncm/bitcoind:v26.0 \ | |
-chain=regtest \ | |
-rpcuser=hello -rpcpassword=world \ | |
-rpcbind=0.0.0.0 -rpcallowip=0.0.0.0/0 \ | |
-fallbackfee=0.00001 | |
until curl http://127.0.0.1:18443/ --user hello:world --fail -d '{"jsonrpc":"1.0","id":1,"method":"createwallet","params":["getblockchaininfo"]}' -H 'Content-Type: text/plain' > /dev/null 2>&1; do | |
echo "Waiting for bitcoind to be ready" | |
sleep 1 | |
done | |
echo "bitcoind is ready" | |
# Creates `mywallet` | |
curl http://127.0.0.1:18443/ --user hello:world --fail -d '{"jsonrpc":"1.0","id":1,"method":"createwallet","params":["mywallet"]}' -H 'Content-Type: text/plain' 2>/dev/null | jq | |
# Creates a new address | |
WALLET_ADDRESS=$(curl http://127.0.0.1:18443/wallet/mywallet --user hello:world --fail -d '{"jsonrpc":"1.0","id":1,"method":"getnewaddress","params":[""]}' -H 'Content-Type: text/plain' 2>/dev/null | jq -r '.result') | |
echo "Wallet address: $WALLET_ADDRESS" | |
# Funds the new address by creating 101 blocks (https://developer.bitcoin.org/examples/testing.html#regtest-mode) | |
curl http://127.0.0.1:18443/ --user hello:world --fail -d '{"jsonrpc":"1.0","id":1,"method":"generatetoaddress","params":[101,"'$WALLET_ADDRESS'"]}' -H 'Content-Type: text/plain' 2>/dev/null | jq | |
# Populates test env vars | |
echo "BITCOIN_JSON_RPC_ENDPOINT=http://localhost:18443" >> $GITHUB_ENV | |
echo "BITCOIN_JSON_RPC_AUTH=hello:world" >> $GITHUB_ENV | |
echo "BITCOIN_JSON_RPC_WALLET=mywallet" >> $GITHUB_ENV | |
# | |
# Tests | |
# | |
- name: Test with latest nextest release (faster than cargo test) | |
uses: actions-rs/cargo@v1 | |
with: | |
command: nextest | |
# Test `get_zkapps` is skipped on CI for now as it uses a hard-coded testnet address | |
# TODO: remove this exclusion once the test becomes end-to-end | |
args: run --all-features --release -E "package(zkbitcoin) - test(get_zkapps)" | |
# | |
# Coding guidelines | |
# | |
- name: Enforce formating | |
uses: actions-rs/cargo@v1 | |
with: | |
command: fmt | |
args: -- --check | |
- name: Lint (clippy) | |
uses: actions-rs/cargo@v1 | |
with: | |
command: clippy | |
args: --all-features -- -D warnings |