-
Notifications
You must be signed in to change notification settings - Fork 31
INTPYTHON-821 Add SBOM update automation #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thanhnguyen-mdb
wants to merge
9
commits into
mongodb:main
Choose a base branch
from
thanhnguyen-mdb:sbom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9f57d68
Add workflow to generate SBOM and create PR on dependency changes
thanhnguyen-mdb 56db3e5
updated to main
thanhnguyen-mdb d171d2e
changed param cdx spec to 1.5
thanhnguyen-mdb 0c36d55
Updated to use cyclonedx-python
thanhnguyen-mdb 3ead999
linter fix
thanhnguyen-mdb 5e9c29e
Update actions to use latest versions and linting
thanhnguyen-mdb 4c17faf
version pinned
thanhnguyen-mdb f36203f
update hash
thanhnguyen-mdb 67deeee
Add check for changes before adding file to push for PR & change pyth…
thanhnguyen-mdb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: Generate SBOM | ||
|
|
||
| # This workflow uses cyclonedx-py and publishes an sbom.json artifact. | ||
| # It runs on manual trigger or when package files change on main branch, | ||
| # and creates a PR with the updated SBOM. | ||
| # Internal documentation: go/sbom-scope | ||
|
|
||
| on: | ||
| workflow_dispatch: {} | ||
| push: | ||
| branches: ['main'] | ||
| paths: | ||
| - 'pyproject.toml' | ||
| - 'requirements.txt' | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sbom: | ||
| name: Generate SBOM and Create PR | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: sbom-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.10" | ||
thanhnguyen-mdb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - name: Generate SBOM | ||
| run: | | ||
| python -m venv .venv | ||
| source .venv/bin/activate | ||
| pip install -r requirements.txt | ||
| pip install . | ||
| pip uninstall -y pip setuptools | ||
| deactivate | ||
| python -m venv .venv-sbom | ||
| source .venv-sbom/bin/activate | ||
| pip install cyclonedx-bom==7.2.1 | ||
thanhnguyen-mdb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cyclonedx-py environment --spec-version 1.5 --output-format JSON --output-file sbom.json .venv | ||
| # Add PURL for django-mongodb-backend (local package doesn't get PURL automatically) | ||
| 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 | ||
| - name: Download CycloneDX CLI | ||
| run: | | ||
| curl -L -s -o /tmp/cyclonedx "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64" | ||
| chmod +x /tmp/cyclonedx | ||
| - name: Validate SBOM | ||
| run: /tmp/cyclonedx validate --input-file sbom.json --fail-on-errors | ||
| - name: Cleanup | ||
| if: always() | ||
| run: rm -rf .venv .venv-sbom | ||
| - name: Upload SBOM artifact | ||
| uses: actions/upload-artifact@v5 | ||
| with: | ||
| name: sbom | ||
| path: sbom.json | ||
| if-no-files-found: error | ||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@b4733b9419fd47bbfa1807b15627e17cd70b5b22 # v7.0.9 | ||
|
||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: 'Update SBOM after dependency changes' | ||
| branch: auto-update-sbom-${{ github.run_id }} | ||
| delete-branch: true | ||
| title: 'Update SBOM' | ||
| body: | | ||
| ## Automated SBOM Update | ||
|
|
||
| This PR was automatically generated because dependency manifest files changed. | ||
|
|
||
| ### Changes | ||
| - Updated `sbom.json` to reflect current dependencies | ||
|
|
||
| ### Verification | ||
| The SBOM was generated using cyclonedx-py with the current Python environment. | ||
|
|
||
| ### Triggered by | ||
| - Commit: ${{ github.sha }} | ||
| - Workflow run: ${{ github.run_id }} | ||
|
|
||
| --- | ||
| _This PR was created automatically by the [SBOM workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})_ | ||
| labels: | | ||
| sbom | ||
| automated | ||
| dependencies | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.