|
1 | 1 | name: Generate SBOM |
2 | 2 |
|
3 | | -# This workflow uses cdxgen and publishes an sbom.json artifact. |
| 3 | +# This workflow uses cyclonedx-py and publishes an sbom.json artifact. |
4 | 4 | # It runs on manual trigger or when package files change on main branch, |
5 | 5 | # and creates a PR with the updated SBOM. |
6 | 6 | # Internal documentation: go/sbom-scope |
|
42 | 42 | source .venv/bin/activate |
43 | 43 | pip install -r requirements.txt |
44 | 44 | pip install . |
45 | | - npx @cyclonedx/cdxgen -t python --exclude "uv.lock" --exclude "requirements/**" --exclude "requirements.txt" --spec-version 1.5 --no-validate --json-pretty -o sbom.json |
46 | | - env: |
47 | | - 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 pymongo (local package doesn't get PURL automatically) |
| 52 | + jq '(.components[] | select(.name == "pymongo" and .purl == null)) |= (. + {purl: ("pkg:pypi/pymongo@" + .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 |
48 | 65 |
|
49 | 66 | - name: Upload SBOM artifact |
50 | 67 | uses: actions/upload-artifact@v4 |
|
70 | 87 | - Updated `sbom.json` to reflect current dependencies |
71 | 88 |
|
72 | 89 | ### Verification |
73 | | - 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. |
74 | 91 |
|
75 | 92 | ### Triggered by |
76 | 93 | - Commit: ${{ github.sha }} |
|
82 | 99 | sbom |
83 | 100 | automated |
84 | 101 | dependencies |
85 | | -
|
86 | | - - name: Cleanup |
87 | | - if: always() |
88 | | - run: rm -rf .venv |
|
0 commit comments