From 90277400138fa3d8730acfe479855da86097fd00 Mon Sep 17 00:00:00 2001 From: Antonio Yang Date: Tue, 23 Apr 2024 21:00:07 +0800 Subject: [PATCH] ci: update codecov with nix --- .github/workflows/codecov.yml | 38 ++++++++++------------------------- flake.nix | 14 +++++++++++++ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d8b6fa0..967bc0c 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -14,38 +14,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, llvm-tools-preview + - name: Install Nix + uses: cachix/install-nix-action@v26 - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release - env: - CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Cinstrument-coverage" - RUSTDOCFLAGS: "-Cinstrument-coverage" + run: nix develop .#codecov -c cargo build --release - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features --no-fail-fast - env: - CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Cinstrument-coverage" - RUSTDOCFLAGS: "-Cinstrument-coverage" + run: nix develop .#codecov -c cargo test --all-features --no-fail-fast - name: Install grcov - run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi + run: nix develop .#codecov -c cargo install grcov - name: Generate coverage - run: grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov + run: nix develop .#codecov -c grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: files: ./coverage.lcov flags: rust - fail_ci_if_error: true + # TODO: set true when CODECOV_TOKEN is set + fail_ci_if_error: false + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/flake.nix b/flake.nix index 2e98f00..f23f7de 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ pkg-config ]; cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + + stableWithLlvm = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ "rustfmt" "llvm-tools-preview" ]; + targets = [ ]; + }; in with pkgs; { @@ -52,6 +57,15 @@ rust-bin.nightly.latest.default ]; }; + + codecov = mkShell { + buildInputs = commonPackages ++ [ + stableWithLlvm + ]; + CARGO_INCREMENTAL = "0"; + RUSTFLAGS = "-Cinstrument-coverage"; + RUSTDOCFLAGS = "-Cinstrument-coverage"; + }; }; } );