Skip to content

Commit

Permalink
ci: add code coverage report job(#45)
Browse files Browse the repository at this point in the history
* ci: add build steps for test coverage reporting

* fix(ci): use nightly toolchain in test job

* ci: update deprecated codecov config fields

* ci: use test toolchain setup step from action-rs

* ci: add codecov badge to Cargo.toml

* ci: use verbose test output

* ci: add build step to main job

* ci: add updated coverage job to build workflow

* fix(ci): add missing Makefile.toml

* ci: add codecov.yml file

* ci: remove obsolete grcov.yml file

* style(ci): move comments above fields
  • Loading branch information
ekkolon committed Feb 6, 2024
1 parent eb27689 commit 499e524
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 15 deletions.
69 changes: 54 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build

on:
# Allow running this workflow manually from the Actions tab
workflow_dispatch:
push:
branches: ["main"]
pull_request:
Expand All @@ -10,40 +12,77 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo check

- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Setup Rust toolchain
run: cargo check

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy, rustfmt

- name: Run cargo fmt
run: cargo fmt --all --check

- name: Run cargo clippy
run: cargo clippy -- -D warnings

test:
name: Test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [1.75.0]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.75.0
toolchain: ${{ matrix.rust }}

- name: Run cargo test
run: cargo test

lint:
name: Lint
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy, rustfmt
components: llvm-tools

- name: Run cargo fmt
run: cargo fmt --all --check
- name: Install cargo-llvm-cov and cargo-make
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov,cargo-make

- name: Run cargo clippy
run: cargo clippy -- -D warnings
- name: Generate coverage
run: cargo make coverage

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ openssl = { version = "0.10", features = ["vendored"] }

[badges]
maintenance = { status = "experimental" }
codecov = { repository = "ekkolon/licensa", branch = "main", service = "github" }

[profile.dev]
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
Expand Down
13 changes: 13 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[config]
skip_core_tasks = true

[tasks.coverage]
description = "Generate code coverage report"
command = "cargo"
args = [
"llvm-cov",
"--lcov",
"--output-path",
"target/lcov.info",
"--no-default-features",
]
21 changes: 21 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# https://docs.codecov.com/docs/codecovyml-reference#coverage
coverage:
precision: 1 # e.g. 89.1%
round: down

# https://docs.codecov.com/docs/coverage-configuration#section-range
range: 85..100

# https://docs.codecov.com/docs/commit-status
status:
project:
default:
threshold: 1% # Avoid false negatives
ignore:
- "examples"
- "benches"

# https://docs.codecov.com/docs/pull-request-comments
comment:
# make the comments less noisy
require_changes: true

0 comments on commit 499e524

Please sign in to comment.