forked from siemens/cmp-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Add SBOM #19
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
Guiliano99
wants to merge
10
commits into
main
Choose a base branch
from
AddSBOM
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
Add SBOM #19
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b70885
feat(makefile): Add `sbom` target to generate Software Bill of Materi…
Guiliano99 711aaa9
feat(ci): Add GitHub workflow to generate CycloneDX 1.5 SBOM on push …
Guiliano99 89ae96b
feat(ci): Trigger SBOM generation workflow on pull request to main
Guiliano99 060c464
fix(ci): Remove outdated `--locked` flag from SBOM workflow
Guiliano99 31e8b6c
fix(ci): Update SBOM workflow to use correct checkout version and rem…
Guiliano99 bdfe91c
fix(ci): Update SBOM workflow to fix output path and adjust `uv` comm…
Guiliano99 34908dd
fix(ci): Add path filters for SBOM workflow triggers
Guiliano99 3a447a7
feat(ci): Enhance SBOM workflow to include commit back and release at…
Guiliano99 afb30c1
fix(reuse): Add `sbom.cdx.json` to excluded files list in REUSE confi…
Guiliano99 df1f124
fix(ci): Adjust SBOM workflow to reuse lockfile from container image
Guiliano99 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,139 @@ | ||
| # SPDX-FileCopyrightText: Copyright 2025 Siemens AG | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Generates a CycloneDX SBOM from the locked dependencies and publishes it so it | ||
| # can always be fetched for analysis: on push to main the SBOM is committed back | ||
| # to the repository, and on a published release it is attached as a release asset. | ||
|
|
||
| name: Generate SBOM | ||
|
|
||
| # Triggered when the dependencies (pyproject.toml) or this workflow change, on | ||
| # every published release, and manually. | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - pyproject.toml | ||
| - .github/workflows/generate_sbom.yml | ||
| pull_request: | ||
| paths: | ||
| - pyproject.toml | ||
| - .github/workflows/generate_sbom.yml | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # Serialize runs per ref so two commits to main can't race their git push. | ||
| # Releases and PRs use separate groups; a run is never cancelled mid push. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| # Generate a docker image URL where all the characters are lower-case, for situations where an external contributor | ||
| # has a username that begins with a capital letter. This is a limitation of GHCR, which only allows lower-case | ||
| # characters. Subsequent jobs use this URL. | ||
| prepare_env: | ||
| runs-on: ubuntu-24.04 | ||
| outputs: | ||
| image_url: ${{ steps.setenv.outputs.image_url }} | ||
| steps: | ||
| - name: Set lowercase image name | ||
| id: setenv | ||
| # Pass via env, not inline ${{ }}, so the value can't be parsed as shell. | ||
| env: | ||
| REPO_OWNER: ${{ github.repository_owner }} | ||
| run: | | ||
| OWNER_LC=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]') | ||
| echo "image_url=ghcr.io/${OWNER_LC}/cmp-test-dev:latest" >> "$GITHUB_OUTPUT" | ||
|
|
||
| generate_sbom: | ||
| needs: prepare_env | ||
| name: Generate CycloneDX SBOM | ||
| runs-on: ubuntu-24.04 | ||
| container: | ||
| image: ${{ needs.prepare_env.outputs.image_url }} | ||
| steps: | ||
| - uses: actions/checkout@v6.0.3 | ||
| with: | ||
| # Read-only job: don't leave the token in git config for later steps. | ||
| persist-credentials: false | ||
|
|
||
| - name: Generate SBOM in CycloneDX 1.5 format | ||
| # The container image already resolves and locks the dependencies at build | ||
| # time (data/dockerfiles/Dockerfile.dev: `WORKDIR /app` + `uv sync`, which | ||
| # writes /app/uv.lock). The checked-out workspace has no committed uv.lock, | ||
| # so point --project at /app to reuse the image's lockfile. Output still | ||
| # goes to the workspace so the upload-artifact step can find it. | ||
| run: uv --project /app export --format cyclonedx1.5 --locked -o "$GITHUB_WORKSPACE/sbom.cdx.json" | ||
|
|
||
| - name: Upload SBOM artifact | ||
| uses: actions/upload-artifact@v7.0.1 | ||
| with: | ||
| name: sbom-cdx | ||
| path: ${{ github.workspace }}/sbom.cdx.json | ||
| retention-days: 30 | ||
|
|
||
| # Only on direct pushes to main, never from PRs/forks (which get a read-only | ||
| # token), so the committed-back SBOM always reflects merged dependencies. | ||
| commit_sbom: | ||
| needs: generate_sbom | ||
| name: Commit SBOM to main | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v6.0.3 | ||
| with: | ||
| ref: main | ||
|
|
||
| - name: Download SBOM artifact | ||
| uses: actions/download-artifact@v8.0.1 | ||
| with: | ||
| name: sbom-cdx | ||
| path: . | ||
|
|
||
| - name: Commit and push updated SBOM | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add sbom.cdx.json | ||
| if git diff --staged --quiet; then | ||
| echo "SBOM unchanged, nothing to commit" | ||
| else | ||
| # [skip ci] keeps the bot commit from re-triggering CI. | ||
| git commit -m "chore: update SBOM [skip ci]" | ||
| # Rebase in case main advanced since checkout; only this job edits | ||
| # the SBOM, so the rebase can't conflict. | ||
| git pull --rebase origin main | ||
| git push | ||
| fi | ||
|
|
||
| # Only on published releases; attaches the SBOM to that release's assets. | ||
| release_sbom: | ||
| needs: generate_sbom | ||
| name: Attach SBOM to release | ||
| if: github.event_name == 'release' | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Download SBOM artifact | ||
| uses: actions/download-artifact@v8.0.1 | ||
| with: | ||
| name: sbom-cdx | ||
| path: . | ||
|
|
||
| - name: Upload SBOM to GitHub release | ||
| # Pass the tag via env, not inline ${{ }}, to avoid shell injection; | ||
| # --clobber lets re-runs replace the asset instead of failing. | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| TAG: ${{ github.event.release.tag_name }} | ||
| run: gh release upload "$TAG" sbom.cdx.json --clobber --repo "$GITHUB_REPOSITORY" |
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
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
Oops, something went wrong.
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.