Skip to content

Commit 6e7576a

Browse files
authored
Merge pull request #76 from nanotaboada/ci/42-coverage-codecov-reporting
ci(workflow): add coverage reporting with Codecov (#42)
2 parents fd49dd1 + 86eead9 commit 6e7576a

4 files changed

Lines changed: 82 additions & 34 deletions

File tree

.github/workflows/rust-ci.yml

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
commitlint:
14-
name: Commitlint
13+
lint:
1514
runs-on: ubuntu-latest
16-
if: github.event_name == 'pull_request'
1715
permissions:
1816
contents: read
1917
pull-requests: read
@@ -23,38 +21,13 @@ jobs:
2321
with:
2422
fetch-depth: 0
2523

26-
- name: Run commitlint
24+
- name: Lint commit messages
2725
uses: wagoid/commitlint-github-action@v6.2.1
2826

29-
format:
30-
name: Format
31-
runs-on: ubuntu-latest
32-
needs: commitlint
33-
if: always() && (needs.commitlint.result == 'success' || needs.commitlint.result == 'skipped')
34-
steps:
35-
- name: Checkout repository
36-
uses: actions/checkout@v6.0.2
37-
3827
- name: Set up Rust
3928
uses: dtolnay/rust-toolchain@stable
4029
with:
41-
components: rustfmt
42-
43-
- name: Check formatting
44-
run: cargo fmt --all -- --check
45-
46-
lint:
47-
name: Lint
48-
runs-on: ubuntu-latest
49-
needs: format
50-
steps:
51-
- name: Checkout repository
52-
uses: actions/checkout@v6.0.2
53-
54-
- name: Set up Rust
55-
uses: dtolnay/rust-toolchain@stable
56-
with:
57-
components: clippy
30+
components: rustfmt, clippy
5831

5932
- name: Cache dependencies
6033
uses: actions/cache@v5.0.4
@@ -63,15 +36,19 @@ jobs:
6336
~/.cargo/registry
6437
~/.cargo/git
6538
target
66-
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
39+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
40+
41+
- name: Check formatting
42+
run: cargo fmt --all -- --check
6743

6844
- name: Run Clippy
6945
run: cargo clippy --all-targets --all-features -- -D warnings
7046

7147
build:
72-
name: Build
73-
runs-on: ubuntu-latest
7448
needs: lint
49+
runs-on: ubuntu-latest
50+
permissions:
51+
contents: read
7552
steps:
7653
- name: Checkout repository
7754
uses: actions/checkout@v6.0.2
@@ -92,9 +69,10 @@ jobs:
9269
run: cargo build --verbose
9370

9471
test:
95-
name: Test
9672
needs: build
9773
runs-on: ubuntu-latest
74+
permissions:
75+
contents: read
9876
steps:
9977
- name: Checkout repository
10078
uses: actions/checkout@v6.0.2
@@ -113,3 +91,36 @@ jobs:
11391

11492
- name: Run tests
11593
run: cargo test --verbose
94+
95+
coverage:
96+
needs: test
97+
runs-on: ubuntu-latest
98+
permissions:
99+
contents: read
100+
steps:
101+
- name: Checkout repository
102+
uses: actions/checkout@v6.0.2
103+
104+
- name: Set up Rust
105+
uses: dtolnay/rust-toolchain@stable
106+
107+
- name: Cache dependencies
108+
uses: actions/cache@v5.0.4
109+
with:
110+
path: |
111+
~/.cargo/registry
112+
~/.cargo/git
113+
target
114+
key: ${{ runner.os }}-cargo-tarpaulin-${{ hashFiles('**/Cargo.lock') }}
115+
116+
- name: Install cargo-tarpaulin
117+
run: cargo install cargo-tarpaulin --version 0.35.2 --locked
118+
119+
- name: Generate coverage report
120+
run: cargo tarpaulin --out xml
121+
122+
- name: Upload coverage report to Codecov
123+
uses: codecov/codecov-action@v5
124+
with:
125+
token: ${{ secrets.CODECOV_TOKEN }}
126+
slug: nanotaboada/rust-samples-rocket-restful

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Coverage reporting with `cargo-tarpaulin` and Codecov integration (#42)
13+
- `codecov.yml` with 80% minimum threshold on `src/services/`, `src/routes/`, `src/repositories/` (#42)
14+
- Codecov badge in `README.md` (#42)
15+
1216
### Changed
1317

18+
- Consolidated `commitlint`, `format`, and `lint` CI jobs into a single `lint` job (#42)
19+
1420
### Fixed
1521

1622
### Removed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Rust CI](https://github.com/nanotaboada/rust-samples-rocket-restful/actions/workflows/rust-ci.yml/badge.svg)](https://github.com/nanotaboada/rust-samples-rocket-restful/actions/workflows/rust-ci.yml)
44
[![Rust CD](https://github.com/nanotaboada/rust-samples-rocket-restful/actions/workflows/rust-cd.yml/badge.svg)](https://github.com/nanotaboada/rust-samples-rocket-restful/actions/workflows/rust-cd.yml)
5+
[![codecov](https://codecov.io/gh/nanotaboada/rust-samples-rocket-restful/branch/master/graph/badge.svg)](https://codecov.io/gh/nanotaboada/rust-samples-rocket-restful)
56
[![License: MIT](https://img.shields.io/badge/License-MIT-3DA639.svg)](https://opensource.org/licenses/MIT)
67
![Dependabot](https://img.shields.io/badge/Dependabot-contributing-025E8C?logo=dependabot&logoColor=white&labelColor=181818)
78
![Copilot](https://img.shields.io/badge/Copilot-contributing-8662C5?logo=githubcopilot&logoColor=white&labelColor=181818)

codecov.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Codecov Configuration
2+
# Goal: 80% minimum coverage on services/, routes/, repositories/ only
3+
4+
coverage:
5+
status:
6+
project:
7+
default:
8+
target: 80%
9+
paths:
10+
- "src/services/"
11+
- "src/routes/"
12+
- "src/repositories/"
13+
14+
patch:
15+
default:
16+
target: 80%
17+
18+
ignore:
19+
- ".github/**/*"
20+
- ".vscode/**/*"
21+
- "migrations/**/*"
22+
- "tests/**/*"
23+
- "src/models/**/*"
24+
- "src/schema.rs"
25+
- "src/state/**/*"
26+
- "src/main.rs"
27+
- "**/*.toml"
28+
- "**/*.yml"
29+
- "**/*.yaml"
30+
- "**/*.md"

0 commit comments

Comments
 (0)