| 1 |
# Copyright (C) 2025 Siemens |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: MIT |
| 4 |
|
| 5 |
name: Tests |
| 6 |
|
| 7 |
on: |
| 8 |
push: |
| 9 |
branches: |
| 10 |
- main |
| 11 |
pull_request: |
| 12 |
|
| 13 |
jobs: |
| 14 |
test-minimal-deps: |
| 15 |
runs-on: ubuntu-24.04 |
| 16 |
strategy: |
| 17 |
matrix: |
| 18 |
sbom-type: ["cdx", "spdx"] |
| 19 |
steps: |
| 20 |
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 21 |
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 22 |
with: |
| 23 |
python-version: 3.14 |
| 24 |
|
| 25 |
- name: Install required dependencies for ${{ matrix.sbom-type }} |
| 26 |
shell: bash |
| 27 |
run: | |
| 28 |
python -m pip install --upgrade pip |
| 29 |
pip install .[${{ matrix.sbom-type }}] |
| 30 |
|
| 31 |
- name: Test the generate command with minimal dependencies for ${{ matrix.sbom-type }} |
| 32 |
shell: bash |
| 33 |
run: $(which debsbom) -v generate -t ${{ matrix.sbom-type }} -o sbom --root tests/root/tree --validate |
| 34 |
|
| 35 |
- name: Install test dependencies for ${{ matrix.sbom-type }} |
| 36 |
shell: bash |
| 37 |
run: pip install .[mindev] |
| 38 |
- name: Test pytest for subset ${{ matrix.sbom-type }} |
| 39 |
shell: bash |
| 40 |
run: pytest |
| 41 |
|
| 42 |
test: |
| 43 |
runs-on: ubuntu-24.04 |
| 44 |
strategy: |
| 45 |
matrix: |
| 46 |
python-version: ["3.11.2", "3.11", "3.12", "3.13.5", "3.13", "3.14"] |
| 47 |
steps: |
| 48 |
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 49 |
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 50 |
with: |
| 51 |
python-version: ${{ matrix.python-version }} |
| 52 |
|
| 53 |
- uses: ./.github/actions/pytest |
| 54 |
with: |
| 55 |
artifact-identifier: "${{ matrix.python-version }}" |
| 56 |
|
| 57 |
test-python-apt: |
| 58 |
runs-on: ubuntu-24.04 |
| 59 |
steps: |
| 60 |
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 61 |
- name: Check if python-apt is available |
| 62 |
run: python -c "import apt" |
| 63 |
- uses: ./.github/actions/pytest |
| 64 |
with: |
| 65 |
artifact-identifier: "python-apt" |
| 66 |
|
| 67 |
test-debian-trixie-compat: |
| 68 |
runs-on: ubuntu-24.04 |
| 69 |
steps: |
| 70 |
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 71 |
- name: Install dependencies as found in Debian trixie |
| 72 |
run: | |
| 73 |
python -m pip install --upgrade pip |
| 74 |
pip install -r requirements-trixie.txt |
| 75 |
- uses: ./.github/actions/pytest |
| 76 |
with: |
| 77 |
artifact-identifier: "debian-trixie-compat" |
| 78 |
|
| 79 |
coverage: |
| 80 |
name: Check coverage |
| 81 |
needs: test |
| 82 |
runs-on: ubuntu-24.04 |
| 83 |
steps: |
| 84 |
- name: Check out the repo |
| 85 |
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 86 |
|
| 87 |
- name: Set up Python |
| 88 |
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 |
| 89 |
with: |
| 90 |
python-version: 3.14 |
| 91 |
|
| 92 |
- name: Install dependencies |
| 93 |
run: | |
| 94 |
python -m pip install --upgrade coverage[toml] |
| 95 |
pip install .[dev] |
| 96 |
|
| 97 |
- name: Download coverage data |
| 98 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 99 |
with: |
| 100 |
pattern: coverage-data-* |
| 101 |
merge-multiple: true |
| 102 |
|
| 103 |
- name: Check coverage and fail it it’s under 85% |
| 104 |
run: | |
| 105 |
cat >.coveragerc <<EOF |
| 106 |
[run] |
| 107 |
source = debsbom |
| 108 |
[paths] |
| 109 |
source = |
| 110 |
src/debsbom |
| 111 |
*/site-packages/debsbom |
| 112 |
*/runner/work/debsbom/src/debsbom |
| 113 |
EOF |
| 114 |
|
| 115 |
python -m coverage combine |
| 116 |
python -m coverage html --skip-covered --skip-empty |
| 117 |
|
| 118 |
# Report and write to summary. |
| 119 |
python -m coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY |
| 120 |
|
| 121 |
# Report again and fail if under 85%. |
| 122 |
python -Im coverage report --fail-under=85 |
| 123 |
|
| 124 |
- name: Upload HTML report if check failed |
| 125 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 126 |
with: |
| 127 |
name: html-report |
| 128 |
path: htmlcov |
| 129 |
if: ${{ failure() }} |