From bfb13cf292132d8bab448ce5d2ed8324cb3be56e Mon Sep 17 00:00:00 2001 From: muraca Date: Wed, 4 Oct 2023 21:08:02 +0200 Subject: [PATCH 1/2] CI Improvements - renamed `build.yml` to `ci.yml` - use toml-sort action in `ci.yml` - removed `toml-sort.yml` - removed cargo check job - perform tests with nextest instead of cargo test - added llvm cov for coverage ~ fixes #106 - added `--no-deps` arg to clippy - bumped version for upgraded actions - removed unmaintained actions - created `rust-toolchain.toml` with stable channel - tests and clippy are run after rustfmt and toml-sort are successful - tests and clippy's target is cached even on failure Signed-off-by: muraca --- .github/workflows/build.yml | 98 --------------------------------- .github/workflows/ci.yml | 80 +++++++++++++++++++++++++++ .github/workflows/toml-sort.yml | 22 -------- rust-toolchain.toml | 5 ++ toml-sort.toml | 8 +-- 5 files changed, 89 insertions(+), 124 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/toml-sort.yml create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index ad1b0328f..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,98 +0,0 @@ -on: - pull_request: - branches: - - main - push: - branches: - - main - -name: Continuous integration - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install tooling - run: | - sudo apt-get install -y protobuf-compiler - protoc --version - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: wasm32-unknown-unknown - override: true - - name: Rust Cache - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: check - - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install tooling - run: | - sudo apt-get install -y protobuf-compiler - protoc --version - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: wasm32-unknown-unknown - override: true - - name: Rust Cache - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: test - - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install tooling - run: | - sudo apt-get install -y protobuf-compiler - protoc --version - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: wasm32-unknown-unknown - override: true - - run: rustup component add rustfmt - - name: Rust Cache - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install tooling - run: | - sudo apt-get install -y protobuf-compiler - protoc --version - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: wasm32-unknown-unknown - override: true - - run: rustup component add clippy - - name: Rust Cache - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..2a6047b69 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +on: + pull_request: + branches: + - main + push: + branches: + - main + +name: Continuous integration + +jobs: + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install tooling + run: | + sudo apt-get install -y protobuf-compiler + protoc --version + - name: Run Rustfmt + run: cargo fmt --all -- --check + + toml-sort: + name: TOML Sort check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Off-Narrative-Labs/toml_sort@v1 + with: + all: true + + test: + name: Test and code coverage + needs: [fmt, toml-sort] + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + - name: Install tooling + run: | + sudo apt-get install -y protobuf-compiler + protoc --version + - name: Install latest nextest release + uses: taiki-e/install-action@nextest + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Run tests + run: cargo llvm-cov nextest --lcov + --ignore-filename-regex "node/" + --output-path lcov.info + - if: github.event_name == 'pull_request' + name: Report code coverage + uses: Nef10/lcov-reporter-action@v0.4.0 + with: + lcov-file: lcov.info + pr-number: ${{ github.event.pull_request.number }} + + clippy: + name: Clippy + needs: [fmt, toml-sort] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install tooling + run: | + sudo apt-get install -y protobuf-compiler + protoc --version + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Run Clippy + run: cargo clippy --no-deps -- -D warnings diff --git a/.github/workflows/toml-sort.yml b/.github/workflows/toml-sort.yml deleted file mode 100644 index bd6e8382d..000000000 --- a/.github/workflows/toml-sort.yml +++ /dev/null @@ -1,22 +0,0 @@ -on: - pull_request: - branches: - - main - push: - branches: - - main - -name: Toml Sort - -jobs: - toml-sort: - name: Toml Sort - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - - run: cargo install --git https://github.com/Moonsong-Labs/toml_sort/ - - run: find . -name Cargo.toml | xargs -L1 toml-sort --check diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..3818c8c40 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "stable" +components = [ "rustfmt", "clippy" ] +profile = "minimal" +targets = [ "wasm32-unknown-unknown" ] diff --git a/toml-sort.toml b/toml-sort.toml index 8e2692e24..812560b6e 100644 --- a/toml-sort.toml +++ b/toml-sort.toml @@ -1,9 +1,9 @@ keys = [ - "package", - "dependencies", + "package", + "dependencies", ] inline_keys = [ - "version", - "features", + "version", + "features", ] From 3f290c9cdf8d26c98d1e0ac4a08c0f30f18b0e9d Mon Sep 17 00:00:00 2001 From: muraca Date: Thu, 5 Oct 2023 17:44:34 +0200 Subject: [PATCH 2/2] updates to test action - print lines coverage to actions cli output - comment PR with report when allowed Signed-off-by: muraca --- .github/workflows/ci.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a6047b69..4354d5fc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,11 +51,18 @@ jobs: uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - - name: Run tests - run: cargo llvm-cov nextest --lcov + - name: Run tests and print coverage data + run: cargo llvm-cov nextest --json --output-path lcov.json + --ignore-filename-regex "node/" --summary-only && + echo "Lines coverage " && jq ".data[0].totals.lines.percent" lcov.json + # if the PR is on the same repo, the coverage data can be reported as a comment + - if: github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + name: Generate lcov report + run: cargo llvm-cov report --lcov --output-path lcov.info --ignore-filename-regex "node/" - --output-path lcov.info - - if: github.event_name == 'pull_request' + - if: github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository name: Report code coverage uses: Nef10/lcov-reporter-action@v0.4.0 with: