From 02de718174920491afd7905bd82ca7494db2e4af Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 11 Nov 2024 17:24:18 -0500 Subject: [PATCH 1/5] Upgrade github actions Upgrade github checkout and rust-cache actions to latest versions and add names to each step where missing. Also move rust-cache step to happen after the toolchain is installed, as recommended by https://github.com/Swatinem/rust-cache?tab=readme-ov-file#example-usage. --- .github/workflows/rust.yml | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e7b6ed39..86d14c2c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,10 +1,9 @@ -name: Test and Build +name: Continuous integration on: [push, pull_request] jobs: - - test: + Test: runs-on: ubuntu-latest strategy: fail-fast: false @@ -13,42 +12,47 @@ jobs: - 1.63.0 # MSRV - stable - nightly - steps: - - uses: actions/checkout@v2 - - uses: Swatinem/rust-cache@v1.2.0 - - uses: actions-rs/toolchain@v1 + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Install ${{ matrix.rust }} toolchain" + uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust }} override: true + - name: "Use cache" + uses: Swatinem/rust-cache@v2 - name: Run tests run: RUST_LOG=debug bash contrib/test.sh - rustfmt: + Format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: Swatinem/rust-cache@v1.2.0 - - uses: actions-rs/toolchain@v1 + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Install nightly toolchain" + uses: actions-rs/toolchain@v1 with: toolchain: nightly override: true + - name: "Use cache" + uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu - - name: fmt check + - name: "Run formatting check" run: cargo fmt --all -- --check - clippy: + Lint: runs-on: ubuntu-latest steps: - name: "Checkout repo" uses: actions/checkout@v4 - - name: "Use caching" - uses: Swatinem/rust-cache@v1.2.0 - name: "Install nightly toolchain" uses: actions-rs/toolchain@v1 with: toolchain: nightly override: true + - name: "Use cache" + uses: Swatinem/rust-cache@v2 - name: "Install clippy" run: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu - name: "Run linting" From f762fe69de64ead16e59ee01b9b8c7ac5a00e0bb Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 11 Nov 2024 17:32:00 -0500 Subject: [PATCH 2/5] Upgrade rust toolchain installer in github actions actions-rs is no longer maintained and rust-bitcoin is using dtolnay/rust-toolchain in their CI. --- .github/workflows/rust.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 86d14c2c..d3a3832e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,10 +16,10 @@ jobs: - name: "Checkout repo" uses: actions/checkout@v4 - name: "Install ${{ matrix.rust }} toolchain" - uses: actions-rs/toolchain@v1 + # https://github.com/dtolnay/rust-toolchain?tab=readme-ov-file#inputs + uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust }} - override: true - name: "Use cache" uses: Swatinem/rust-cache@v2 - name: Run tests @@ -31,10 +31,7 @@ jobs: - name: "Checkout repo" uses: actions/checkout@v4 - name: "Install nightly toolchain" - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true + uses: dtolnay/rust-toolchain@nightly - name: "Use cache" uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu @@ -47,10 +44,7 @@ jobs: - name: "Checkout repo" uses: actions/checkout@v4 - name: "Install nightly toolchain" - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true + uses: dtolnay/rust-toolchain@nightly - name: "Use cache" uses: Swatinem/rust-cache@v2 - name: "Install clippy" From 34a9c60551211dd9340834aa159af5432213614f Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 11 Nov 2024 17:47:48 -0500 Subject: [PATCH 3/5] Add code coverage to CI Following rust-bitcoin's example, run code coverage in CI with cargo llvm-cov and upload the results to Coveralls. --- .github/workflows/rust.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d3a3832e..a0d28964 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -51,3 +51,23 @@ jobs: run: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu - name: "Run linting" run: bash contrib/lint.sh + + Coverage: + name: Code coverage + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Install toolchain" + # https://github.com/dtolnay/rust-toolchain + uses: dtolnay/rust-toolchain@stable + - name: "Use cache" + uses: Swatinem/rust-cache@v2 + - name: "Install cargo-llvm-cov" + uses: taiki-e/install-action@cargo-llvm-cov + - name: "Generate code coverage for tests" + run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + - name: "Upload report to coveralls" + uses: coverallsapp/github-action@v2 From 9766e3958b8d011be7759cd90805231a6abdcd96 Mon Sep 17 00:00:00 2001 From: spacebear Date: Mon, 11 Nov 2024 18:15:40 -0500 Subject: [PATCH 4/5] Merge coverages generated under v1 and v2 --- .github/workflows/rust.yml | 2 +- contrib/coverage.sh | 8 ++++++++ contrib/lint.sh | 0 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 contrib/coverage.sh mode change 100644 => 100755 contrib/lint.sh diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a0d28964..2730b0d6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -68,6 +68,6 @@ jobs: - name: "Install cargo-llvm-cov" uses: taiki-e/install-action@cargo-llvm-cov - name: "Generate code coverage for tests" - run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + run: bash contrib/coverage.sh - name: "Upload report to coveralls" uses: coverallsapp/github-action@v2 diff --git a/contrib/coverage.sh b/contrib/coverage.sh new file mode 100755 index 00000000..2d453b67 --- /dev/null +++ b/contrib/coverage.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions +cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results +cargo llvm-cov --no-report --features=send,receive +cargo llvm-cov --no-report --features=v2,danger-local-https,io +cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests diff --git a/contrib/lint.sh b/contrib/lint.sh old mode 100644 new mode 100755 From 6554d2a9a20d286e33918930ff313162a7b1cd11 Mon Sep 17 00:00:00 2001 From: spacebear Date: Tue, 12 Nov 2024 00:03:13 -0500 Subject: [PATCH 5/5] Update README for coverage measurement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dda8df89..a59b7f27 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Seeking review of the code that verifies there is no overpayment. Contributions - [x] CI - [x] Integration tests - [ ] Fuzzing -- [ ] Coverage measurement +- [x] Coverage measurement ## Minimum Supported Rust Version (MSRV)