11name : Generate SBOM
22
3- # This workflow uses cdxgen and publishes an sbom.json artifact.
3+ # This workflow uses cyclonedx-py and publishes an sbom.json artifact.
44# It runs on manual trigger or when package files change on main branch,
55# and creates a PR with the updated SBOM.
66# Internal documentation: go/sbom-scope
@@ -42,10 +42,26 @@ jobs:
4242 source .venv/bin/activate
4343 pip install -r requirements.txt
4444 pip install .
45- npx @cyclonedx/[email protected] -t python --spec-version 1.5 -o sbom.json 46- jq . sbom.json > sbom.json.tmp && mv sbom.json.tmp sbom.json
47- env :
48- FETCH_LICENSE : true
45+ pip uninstall -y pip setuptools
46+ deactivate
47+ python -m venv .venv-sbom
48+ source .venv-sbom/bin/activate
49+ pip install cyclonedx-bom==7.2.1
50+ cyclonedx-py environment --spec-version 1.5 --output-format JSON --output-file sbom.json .venv
51+ # Add PURL for django-mongodb-backend (local package doesn't get PURL automatically)
52+ jq '(.components[] | select(.name == "django-mongodb-backend" and .purl == null)) |= (. + {purl: ("pkg:pypi/django-mongodb-backend@" + .version)})' sbom.json > sbom.tmp.json && mv sbom.tmp.json sbom.json
53+
54+ - name : Download CycloneDX CLI
55+ run : |
56+ curl -L -s -o /tmp/cyclonedx "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64"
57+ chmod +x /tmp/cyclonedx
58+
59+ - name : Validate SBOM
60+ run : /tmp/cyclonedx validate --input-file sbom.json --fail-on-errors
61+
62+ - name : Cleanup
63+ if : always()
64+ run : rm -rf .venv .venv-sbom
4965
5066 - name : Upload SBOM artifact
5167 uses : actions/upload-artifact@v4
7187 - Updated `sbom.json` to reflect current dependencies
7288
7389 ### Verification
74- The SBOM was generated using cdxgen with the current Python environment.
90+ The SBOM was generated using cyclonedx-py v7.2.1 with the current Python environment.
7591
7692 ### Triggered by
7793 - Commit: ${{ github.sha }}
8298 labels : |
8399 sbom
84100 automated
85- dependencies
86-
87- - name : Cleanup
88- if : always()
89- run : rm -rf .venv
101+ dependencies
0 commit comments