summaryrefslogtreecommitdiffstats
path: root/.github/workflows/coverage.yml
blob: 05f3d5e7df634ee84137932b50ff5230591f3bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Code coverage generation via cargo-llvm-cov, which is then uploaded to Codecov.
# Codecov will report back via a comment if run on a PR.
#
# Note that Codecov will report back the average all uploaded coverage files.

name: codecov

on:
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - master

env:
  CARGO_INCREMENTAL: 0
  CARGO_HUSKY_DONT_INSTALL_HOOKS: true

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' || github.repository != 'ClementTsang/bottom' }}

jobs:
  pre-job:
    runs-on: ubuntu-latest
    outputs:
      should_skip: ${{ steps.skip_check.outputs.should_skip }}
    steps:
      - id: skip_check
        uses: fkirc/skip-duplicate-actions@12aca0a884f6137d619d6a8a09fcc3406ced5281 # v5.3.0
        with:
          skip_after_successful_duplicate: "false"
          paths: '["tests/**", "src/**", ".github/workflows/coverage.yml", ".cargo/**", "Cargo.toml", "Cargo.lock", "build.rs"]'
          do_not_skip: '["workflow_dispatch", "push"]'

  coverage:
    needs: pre-job
    if: ${{ needs.pre-job.outputs.should_skip != 'true' }}
    runs-on: ${{ matrix.info.os }}
    timeout-minutes: 18
    strategy:
      fail-fast: false
      matrix:
        info:
          - { os: "ubuntu-latest", target: "x86_64-unknown-linux-gnu" }
          - { os: "macos-12", target: "x86_64-apple-darwin" }
          - { os: "windows-2019", target: "x86_64-pc-windows-msvc" }
    steps:
      - name: Checkout repository
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@b44cb146d03e8d870c57ab64b80f04586349ca5d
        with:
          toolchain: stable

      - name: Enable Rust cache
        uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894 # 2.4.0
        if: ${{ github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork }} # If it is a PR, only if not a fork
        with:
          key: ${{ matrix.info.target }}
          cache-all-crates: true

      - name: Install cargo-llvm-cov
        run: |
          rustup component add llvm-tools-preview
          cargo install cargo-llvm-cov --version 0.5.9 --locked

      - name: Generate code coverage
        run: |
          cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info --locked --target=${{ matrix.info.target }}

      - name: Upload to codecov.io
        uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # 3.1.1
        with:
          files: lcov.info
          fail_ci_if_error: true
          token: ${{ secrets.CODECOV_TOKEN }} # This is generally not needed, but sometimes the default shared token hits limits.
          flags: ${{ matrix.info.os }}