Skip to content

Commit 3bfa784

Browse files
Add SBOM generation workflow
Add GitHub Actions workflow to automatically generate Software Bill of Materials (SBOM) using cdxgen. The workflow: - Triggers on dependency file changes or manual dispatch - Generates SBOM using CycloneDX format - Creates a PR with updated sbom.json
1 parent 6a796c8 commit 3bfa784

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

.github/workflows/sbom.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Generate SBOM
2+
3+
# This workflow uses cdxgen and publishes an sbom.json artifact.
4+
# It runs on manual trigger or when package files change on main branch,
5+
# and creates a PR with the updated SBOM.
6+
7+
on:
8+
workflow_dispatch: {}
9+
push:
10+
branches: ['main', 'sbom']
11+
paths:
12+
- 'pyproject.toml'
13+
- 'uv.lock'
14+
- 'requirements.txt'
15+
- 'requirements/**/*.txt'
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
21+
jobs:
22+
sbom:
23+
name: Generate SBOM and Create PR
24+
runs-on: ubuntu-latest
25+
concurrency:
26+
group: sbom-${{ github.ref }}
27+
cancel-in-progress: false
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python 3.10
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.10'
37+
38+
- name: Install uv
39+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
40+
41+
- name: Sync dependencies
42+
run: |
43+
uv venv .venv
44+
uv sync --all-groups
45+
46+
- name: Generate SBOM
47+
run: npx @cyclonedx/cdxgen -t python --python-path .venv/bin/python -o sbom.json
48+
env:
49+
FETCH_LICENSE: true
50+
51+
- name: Upload SBOM artifact
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: sbom
55+
path: sbom.json
56+
if-no-files-found: error
57+
58+
- name: Create Pull Request
59+
uses: peter-evans/create-pull-request@v6
60+
with:
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
commit-message: 'chore: Update SBOM after dependency changes'
63+
branch: auto-update-sbom-${{ github.run_id }}
64+
delete-branch: true
65+
title: 'chore: Update SBOM'
66+
body: |
67+
## Automated SBOM Update
68+
69+
This PR was automatically generated because dependency manifest files changed.
70+
71+
### Changes
72+
- Updated `sbom.json` to reflect current dependencies
73+
74+
### Verification
75+
The SBOM was generated using cdxgen with the current Python environment.
76+
77+
### Triggered by
78+
- Commit: ${{ github.sha }}
79+
- Workflow run: ${{ github.run_id }}
80+
81+
---
82+
_This PR was created automatically by the [SBOM workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})_
83+
labels: |
84+
sbom
85+
automated
86+
dependencies
87+
88+
- name: Cleanup
89+
if: always()
90+
run: rm -rf .venv

0 commit comments

Comments
 (0)