From 9484af22f0ed3292009d7da379652f135f9e9fe2 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 18 Jan 2021 23:00:20 +0100 Subject: [PATCH] CI & README --- .github/workflows/build.yml | 189 ++++++++++++++++++++++++++++++ .github/workflows/codecov.yml | 38 ++++++ .github/workflows/lint.yml | 27 +++++ .github/workflows/pre-publish.yml | 26 ++++ .github/workflows/publication.yml | 18 +++ .github/workflows/test.yml | 26 ++++ README.md | 26 +++- contrib/depCargo.toml | 6 + contrib/test.sh | 76 ++++++++++++ 9 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/codecov.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/pre-publish.yml create mode 100644 .github/workflows/publication.yml create mode 100644 .github/workflows/test.yml create mode 100644 contrib/depCargo.toml create mode 100755 contrib/test.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0b8bfd0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,189 @@ +name: Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + features: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + feature: + - serde + steps: + - uses: actions/checkout@v2 + - name: Install rust stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Feature ${{ matrix.feature }} + uses: actions-rs/cargo@v1 + with: + command: check + args: --no-default-features --features=${{ matrix.feature }} + - name: Defaults + ${{ matrix.feature }} + uses: actions-rs/cargo@v1 + with: + command: check + args: --features=${{ matrix.feature }} + platforms: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2019 ] + steps: + - uses: actions/checkout@v2 + - name: Install macos dependencies + if: startsWith(matrix.os, 'macos') + run: brew install pkg-config + - name: Install rust stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build with no features + uses: actions-rs/cargo@v1 + with: + command: check + args: --no-default-features + - name: Build with defaults + uses: actions-rs/cargo@v1 + with: + command: check + args: --all-features + toolchains: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + toolchain: [ nightly, beta, stable, 1.41.1 ] + steps: + - uses: actions/checkout@v2 + - name: Install rust ${{ matrix.toolchain }} + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + override: true + - name: All features + uses: actions-rs/cargo@v1 + with: + command: check + args: --workspace --all-targets --all-features + dependency: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Create dependency + run: | + cargo new dep_test + cp contrib/depCargo.toml dep_test/Cargo.toml + cd dep_test + - name: Build dependency + uses: actions-rs/cargo@v1 + with: + command: check + args: --verbose + - name: Clean up + run: | + cd .. + rm -rf dep_test + android: + runs-on: ubuntu-latest + env: + NDK_VERSION: 20.1.5948944 + ANDROID_CLI_ZIP: commandlinetools-linux-6858069_latest.zip + ANDROID_CLI_SHA256: 87f6dcf41d4e642e37ba03cb2e387a542aa0bd73cb689a9e7152aad40a6e7a08 + steps: + - uses: actions/checkout@v2 + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: set environment variables + run: | + ANDROID_SDK_ROOT="$GITHUB_WORKSPACE/sdk" + NDK_HOME="$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" + echo "ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> $GITHUB_ENV + echo "NDK_HOME=$NDK_HOME" >> $GITHUB_ENV + echo "PATH=$PATH:$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_ENV + - name: Install NDK + run: | + wget -nv https://dl.google.com/android/repository/$ANDROID_CLI_ZIP + echo "$ANDROID_CLI_SHA256 $ANDROID_CLI_ZIP" > SHA256SUMS + sha256sum -c SHA256SUMS + unzip $ANDROID_CLI_ZIP + mkdir -p $ANDROID_SDK_ROOT/cmdline-tools && mv cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/3.0 + yes 2>/dev/null | $ANDROID_SDK_ROOT/cmdline-tools/3.0/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT \ + "build-tools;29.0.3" "platforms;android-29" "ndk;$NDK_VERSION" |grep -v '\[='; true + - name: Add rust targets + run: | + rustup target add aarch64-linux-android x86_64-linux-android armv7-linux-androideabi i686-linux-android + - name: Build for aarch64-linux-android + run: | + export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang" + export CC="aarch64-linux-android21-clang" + export CFLAGS="--sysroot=$NDK_HOME/sysroot -I$NDK_HOME/sysroot/usr/include -I$NDK_HOME/sysroot/usr/include/aarch64-linux-android" + export CXX="aarch64-linux-android21-clang++" + export CXXFLAGS="$CFLAGS -nostdlib++ -I$NDK_HOME/sources/cxx-stl/llvm-libc++/include" + export LDFLAGS="--sysroot=$NDK_HOME/platforms/android-21/arch-arm64" + cargo check --all-features --target=aarch64-linux-android + - name: Build for x86_64-linux-android + run: | + export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android26-clang" + export CC="x86_64-linux-android21-clang" + export CFLAGS="--sysroot=$NDK_HOME/sysroot -I$NDK_HOME/sysroot/usr/include -I$NDK_HOME/sysroot/usr/include/x86_64-linux-android" + export CXX="x86_64-linux-android21-clang++" + export CXXFLAGS="$CFLAGS -nostdlib++ -I$NDK_HOME/sources/cxx-stl/llvm-libc++/include" + export LDFLAGS="--sysroot=$NDK_HOME/platforms/android-21/arch-x86_64" + cargo check --all-features --target=x86_64-linux-android + - name: Build for armv7-linux-androideabi + run: | + export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang" + export CC="armv7a-linux-androideabi21-clang" + export CFLAGS="--sysroot=$NDK_HOME/sysroot -I$NDK_HOME/sysroot/usr/include -I$NDK_HOME/sysroot/usr/include/arm-linux-androideabi" + export CXX="armv7a-linux-androideabi21-clang++" + export CXXFLAGS="$CFLAGS -nostdlib++ -I$NDK_HOME/sources/cxx-stl/llvm-libc++/include" + export LDFLAGS="--sysroot=$NDK_HOME/platforms/android-21/arch-arm -L$NDK_HOME/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a" + cargo check --all-features --target=armv7-linux-androideabi + - name: Build for i686-linux-android + run: | + export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android26-clang" + export CC="i686-linux-android21-clang" + export CFLAGS="--sysroot=$NDK_HOME/sysroot -I$NDK_HOME/sysroot/usr/include -I$NDK_HOME/sysroot/usr/include/i686-linux-android" + export CXX="i686-linux-android21-clang++" + export CXXFLAGS="$CFLAGS -nostdlib++ -I$NDK_HOME/sources/cxx-stl/llvm-libc++/include" + export LDFLAGS="--sysroot=$NDK_HOME/platforms/android-21/arch-x86" + cargo check --all-features --target=i686-linux-android + ios: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Dependencies and targets + run: | + rustup target add aarch64-apple-ios x86_64-apple-ios + cargo install cargo-lipo + - name: build + uses: actions-rs/cargo@v1 + with: + command: lipo + args: --all-features --verbose diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..390a6e9 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,38 @@ +name: Codecov + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + codecov: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Build & test + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --all-features --no-fail-fast + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off' + - id: coverage + name: Generate coverage + uses: actions-rs/grcov@v0.1.5 + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ${{ steps.coverage.outputs.report }} + directory: ./coverage/reports/ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..05c066d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lints + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + name: Lints + with: + command: fmt + args: --all -- --check diff --git a/.github/workflows/pre-publish.yml b/.github/workflows/pre-publish.yml new file mode 100644 index 0000000..3a1b53f --- /dev/null +++ b/.github/workflows/pre-publish.yml @@ -0,0 +1,26 @@ +name: Pre-publishing check + +on: + pull_request: + branches: [ master ] + tags: + - 'pre-publish' + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install rust stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: publish + uses: actions-rs/cargo@v1 + with: + command: publish + args: --dry-run diff --git a/.github/workflows/publication.yml b/.github/workflows/publication.yml new file mode 100644 index 0000000..d9b7e9a --- /dev/null +++ b/.github/workflows/publication.yml @@ -0,0 +1,18 @@ +name: Publication + +on: + push: + tags: + - 'v*' + +env: + CARGO_TERM_COLOR: always + +jobs: + publication: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + - run: cd derive && cargo publish --all-features; sleep 30 + - run: cargo publish --all-features; sleep 30 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3705ca1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build & test + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --all-features --no-fail-fast diff --git a/README.md b/README.md index 1db3700..c35c185 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,27 @@ # Descriptor wallet library -Library for building descriptor-based bitcoin wallets +![Build](https://github.com/LNP-BP/descriptor-wallet/workflows/Build/badge.svg) +![Tests](https://github.com/LNP-BP/descriptor-wallet/workflows/Tests/badge.svg) +![Lints](https://github.com/LNP-BP/descriptor-wallet/workflows/Lints/badge.svg) +[![codecov](https://codecov.io/gh/LNP-BP/descriptor-wallet/branch/master/graph/badge.svg)](https://codecov.io/gh/LNP-BP/descriptor-wallet) + +[![crates.io](https://meritbadge.herokuapp.com/descriptor-wallet)](https://crates.io/crates/descriptor-wallet) +[![Docs](https://docs.rs/descriptor-wallet/badge.svg)](https://docs.rs/descriptor-wallet) +[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) +[![MIT licensed](https://img.shields.io/github/license/LNP-BP/descriptor-wallet)](./LICENSE) + +Library for building descriptor-based bitcoin wallets. Previously was a part of +[LNP/BP Core Library](https://github.com/LNP-BP/rust-lnpbp). + +Components: +- More efficient manipulations with BIP-32 derivation paths +- Universal miniscript/classical bitcoin descriptors +- Script templates allowing embedding extended pubkeys into bitcoin script + assembly +- Lexicographic ordering of transaction & PSBT inputs & oututs +- Script type system +- Helper types for working with hash-lock contracts +- PSBT utility functions (retrieving previous output, computing fee) + +Includes separate crate for SLIP-132 functionality in [`/slip132`](./slip132) +subdirectory. diff --git a/contrib/depCargo.toml b/contrib/depCargo.toml new file mode 100644 index 0000000..eb58d61 --- /dev/null +++ b/contrib/depCargo.toml @@ -0,0 +1,6 @@ +# This is an add-on that must be added to any dependency using this library + +derive-wallet = { path = "..", features = ["serde"] } +slip132 = { path = "../slip132" } + +[workspace] diff --git a/contrib/test.sh b/contrib/test.sh new file mode 100755 index 0000000..7c37da8 --- /dev/null +++ b/contrib/test.sh @@ -0,0 +1,76 @@ +#!/bin/sh -ex + +AS_DEPENDENCY=true +DO_LINT=true + +FEATURES="serde" + +if [ "$DO_COV" = true ] +then + export RUSTFLAGS="-C link-dead-code" +fi + + +# Use toolchain if explicitly specified +if [ -n "$TOOLCHAIN" ] +then + alias cargo="cargo +$TOOLCHAIN" +fi + +# Check that we can build w/o features +cargo check --verbose --all-targets --workspace +cargo check --verbose --no-default-features --all-targets --workspace + +# Check that we can build with each feature +for feature in ${FEATURES} +do + cargo check --verbose --features="$feature" --all-targets +done + +# Check that we can build services with different features +cargo check --manifest-path slip132/Cargo.toml --verbose --all-targets +cargo check --manifest-path slip132/Cargo.toml --verbose --no-default-features --all-targets +for feature in "serde" +do + cargo check --manifest-path slip132/Cargo.toml --verbose --features="$feature" --all-targets +done + +# Fuzz if told to +if [ "$DO_FUZZ" = true ] +then + ( + cd fuzz + cargo test --verbose --all-targets + ./travis-fuzz.sh + ) +fi + +# Bench if told to +if [ "$DO_BENCH" = true ] +then + cargo bench --features unstable --all-targets +fi + +# Use as dependency if told to +if [ -n "$AS_DEPENDENCY" ] +then + rm -rf dep_test + cargo new dep_test + cd dep_test + cat ../contrib/depCargo.toml >> Cargo.toml + cargo build --verbose + cd .. + rm -rf dep_test +fi + +# Test all features +cargo test --verbose --all-features --all-targets --workspace + +# Lint if told to +if [ "$DO_LINT" = true ] +then + ( + rustup component add rustfmt + cargo fmt --all -- --check + ) +fi