Skip to content

Commit be0b4ad

Browse files
committed
ci: add coverage reports
Add a coverage report when we run the tests. In a second step, merge all reports and make sure we score above 75%. This is not a hard goal, but we have aroudn 80% right now, which is a good starting point. Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com>
1 parent 61c100f commit be0b4ad

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

.github/workflows/coverage.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (C) 2025 Siemens
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Check coverage
6+
7+
on:
8+
pull_request:
9+
branches:
10+
- main
11+
push:
12+
13+
jobs:
14+
coverage:
15+
name: Combine and check coverage
16+
needs: test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out the repo
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.13
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade coverage[toml]
30+
31+
- name: Download coverage data
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: coverage-data
35+
36+
- name: Combine coverage and fail it it’s under 75%
37+
run: |
38+
python -m coverage combine
39+
python -m coverage html --skip-covered --skip-empty
40+
41+
# Report and write to summary.
42+
python -m coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
43+
44+
# Report again and fail if under 75%.
45+
python -Im coverage report --fail-under=100
46+
47+
- name: Upload HTML report if check failed
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: html-report
51+
path: htmlcov
52+
if: ${{ failure() }}

.github/workflows/test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
name: Run Tests
5+
name: Tests
66

77
on:
88
pull_request:
@@ -32,6 +32,14 @@ jobs:
3232
- name: Run pytest
3333
run: pytest
3434

35+
- name: Upload coverage data
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: coverage-data
39+
path: .coverage.*
40+
include-hidden-files: true
41+
if-no-files-found: ignore
42+
3543
- name: smoke test generate
3644
run: |
3745
debsbom -vv generate -t spdx -t cdx -o sbom --validate

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/__pycache__
22
*.json
33
*.egg-info
4+
.coverage
45
downloads/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Tests](https://github.com/siemens/debsbom/actions/workflows/test.yml/badge.svg)](https://github.com/siemens/debsbom/actions/workflows/test.yml)
2+
13
# debsbom - SBOM generator for Debian-based distributions
24

35
`debsbom` generates SBOMs (Software Bill of Materials) for distributions based on Debian in the two standard formats [SPDX](https://www.spdx.org) and [CycloneDX](https://www.cyclonedx.org).

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Repository = "https://github.com/siemens/debsbom.git"
3636
[project.optional-dependencies]
3737
dev = [
3838
"pytest>=6.0",
39+
"pytest-cov>=6",
3940
"black",
4041
"beartype>=0.20",
4142
"debsbom[download]",

0 commit comments

Comments
 (0)