Skip to content

Commit 10c9766

Browse files
authored
ci(SBOM): better SBOM maintenance (#2481)
* ci(SBOM): add manual trigger to SBOM workflow * ci(SBOM): simplify dependencies setup * ci(SBOM): update SBOM through PR * ci(SBOM): split SBOMs for different Pythons * ci(SBOM): add copies for different Pythons
1 parent 806ab67 commit 10c9766

11 files changed

+9405
-182
lines changed

.github/workflows/sbom.yml

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: SBOM generation
22

33
on:
4+
workflow_dispatch:
45
schedule:
56
# Runs at 02:00 UTC every Monday
67
- cron: '2 0 * * 1'
@@ -9,45 +10,51 @@ jobs:
910
sbom_gen:
1011
name: Generate SBOM
1112
runs-on: ubuntu-latest
12-
timeout-minutes: 10
13-
continue-on-error: true
13+
strategy:
14+
matrix:
15+
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
1416
steps:
1517
- uses: actions/checkout@v3
1618
- uses: actions/setup-python@v4
1719
with:
18-
python-version: '3.x'
20+
python-version: ${{ matrix.python }}
1921
cache: 'pip'
2022
cache-dependency-path: '**/requirements.txt'
21-
- name: Get date
22-
id: get-date
23-
run: |
24-
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
25-
- name: Get cached database
26-
uses: actions/cache@v3
27-
with:
28-
path: ~/.cache/cve-bin-tool
29-
key: ${{ runner.os }}-cve-bin-tool-${{ steps.get-date.outputs.date }}
3023
- name: Install dependencies and cve-bin-tool
3124
run: |
3225
python -m pip install --upgrade pip
3326
python -m pip install --upgrade setuptools
3427
python -m pip install --upgrade wheel
35-
python -m pip install --upgrade pytest
3628
python -m pip install --upgrade sbom4python
37-
pip install . -r doc/requirements.txt
29+
pip install . --upgrade --upgrade-strategy=eager
3830
- name: Generate SBOM for cve-bin-tool
3931
run: |
40-
sbom4python --module cve-bin-tool --output sbom/cve-bin-tool.spdx
41-
sbom4python --module cve-bin-tool --sbom cyclonedx --format json --output sbom/cve-bin-tool.json
42-
# - name: Compare SBOM for cve-bin-tool
43-
# # This would fail due to time/date of SBOM generation in SBOM header
44-
# # Therefore ignore first 10 lines of file in comparison which is SBOM header
45-
# run: |
46-
# /bin/tail -n +10 sbom/cve-bin-tool.spdx > orig
47-
# /bin/tail -n +10 cve-bin-tool.spdx > new
48-
# /bin/diff -b orig new
49-
# - name: Display generated SBOM if difference detected
50-
# if: ${{ failure() }}
51-
# run: |
52-
# /bin/cat cve-bin-tool.spdx
53-
32+
sbom4python --module cve-bin-tool --output cve-bin-tool-py${{ matrix.python }}.spdx
33+
sbom4python --module cve-bin-tool --sbom cyclonedx --format json --output cve-bin-tool-py${{ matrix.python }}.json
34+
- name: Compare SBOM for cve-bin-tool
35+
id: diff-sbom
36+
# This would fail due to time/date of SBOM generation in SBOM header
37+
# Therefore ignore first 10 lines of file in comparison which is SBOM header
38+
run: |
39+
/bin/tail -n +10 sbom/cve-bin-tool-py${{ matrix.python }}.spdx > orig
40+
/bin/tail -n +10 cve-bin-tool-py${{ matrix.python }}.spdx > new
41+
echo "changed=$(/bin/diff -q orig new)" >> $GITHUB_OUTPUT
42+
- name: Display generated SBOM if difference detected
43+
if: ${{ steps.diff-sbom.outputs.changed }}
44+
run: |
45+
/bin/cat cve-bin-tool-py${{ matrix.python }}.spdx
46+
- name: Update existing SBOM if difference detected
47+
if: ${{ steps.diff-sbom.outputs.changed }}
48+
run: |
49+
cp cve-bin-tool-py${{ matrix.python }}.spdx sbom/cve-bin-tool-py${{ matrix.python }}.spdx
50+
cp cve-bin-tool-py${{ matrix.python }}.json sbom/cve-bin-tool-py${{ matrix.python }}.json
51+
- name: Create Pull Request
52+
if: ${{ steps.diff-sbom.outputs.changed }}
53+
uses: peter-evans/create-pull-request@v4
54+
with:
55+
commit-message: "chore: update SBOM for Python ${{ matrix.python }}"
56+
title: "chore: update SBOM for Python ${{ matrix.python }}"
57+
branch: chore-sbom-py${{ matrix.python }}
58+
delete-branch: true
59+
author: GitHub <[email protected]>
60+
add-paths: sbom

0 commit comments

Comments
 (0)