-
Notifications
You must be signed in to change notification settings - Fork 0
Add SBOM quality gate with PR reporting and regression detection #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,16 @@ | ||
| name: Setup Nix | ||
| description: Install Nix with Determinate Systems and configure Nix store cache | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install Nix | ||
| uses: DeterminateSystems/determinate-nix-action@v3 | ||
| with: | ||
| diagnostic-endpoint: "" | ||
|
|
||
| - name: Cache Nix store | ||
| uses: nix-community/cache-nix-action@v7 | ||
| with: | ||
| primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock') }} | ||
| restore-prefixes-first-match: nix-${{ runner.os }}- |
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,7 @@ | ||
| { | ||
| "max_added": 50, | ||
| "max_removed": 50, | ||
| "deny_licenses": [], | ||
| "require_licenses": true, | ||
| "deny_duplicates": true | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| name: SBOM quality gate | ||
|
|
||
| # Scores the PR's SBOMs and compares against the baseline from main. | ||
| # Blocks merging if any image's quality score regresses. | ||
| # | ||
| # Requires the "Generate SBOMs" workflow to have run first on this PR | ||
| # (it produces the enriched SBOM artifacts we score here). | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Generate SBOMs"] | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| score: | ||
| if: >- | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' | ||
| runs-on: blacksmith-2vcpu-ubuntu-2404 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| image: | ||
| - name: postgres | ||
| - name: redis | ||
| - name: minio | ||
| - name: minio-client | ||
| - name: sbomify-app | ||
| - name: sbomify-keycloak | ||
| - name: sbomify-caddy-dev | ||
| - name: sbomify-minio-init | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Nix | ||
| uses: ./.github/actions/setup-nix | ||
|
|
||
| - name: Build sbomqs and sbomlyze | ||
| run: | | ||
| nix build .#sbomqs -o sbomqs-bin | ||
| nix build .#sbomlyze -o sbomlyze-bin | ||
| echo "$PWD/sbomqs-bin/bin" >> "$GITHUB_PATH" | ||
| echo "$PWD/sbomlyze-bin/bin" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Download PR SBOM | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: sbom-${{ matrix.image.name }} | ||
| path: current/ | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ github.token }} | ||
|
|
||
| - name: Score current SBOM | ||
| run: | | ||
| mkdir -p results | ||
| SBOM=$(ls current/*.cdx.json | head -1) | ||
| bin/sbom-score --image "${{ matrix.image.name }}" "$SBOM" \ | ||
| > results/score-${{ matrix.image.name }}.json | ||
|
|
||
| - name: Fetch baseline SBOM | ||
| id: baseline | ||
| continue-on-error: true | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| # Find the latest successful Generate SBOMs run on main | ||
| RUN_ID=$(gh run list \ | ||
| --workflow="Generate SBOMs" \ | ||
| --branch=main \ | ||
| --status=success \ | ||
| --limit=1 \ | ||
| --json databaseId \ | ||
| --jq '.[0].databaseId') | ||
|
|
||
| if [ -z "$RUN_ID" ] || [ "$RUN_ID" = "null" ]; then | ||
| echo "has_baseline=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| gh run download "$RUN_ID" \ | ||
| --name "sbom-${{ matrix.image.name }}" \ | ||
| --dir baseline/ || { | ||
| echo "has_baseline=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| } | ||
|
|
||
| echo "has_baseline=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Score baseline SBOM | ||
| if: steps.baseline.outputs.has_baseline == 'true' | ||
| run: | | ||
| SBOM=$(ls baseline/*.cdx.json | head -1) | ||
| bin/sbom-score --image "${{ matrix.image.name }}" "$SBOM" \ | ||
| > results/baseline-${{ matrix.image.name }}.json | ||
|
|
||
| - name: Compare SBOMs | ||
| if: steps.baseline.outputs.has_baseline == 'true' | ||
| run: | | ||
| BASELINE=$(ls baseline/*.cdx.json | head -1) | ||
| CURRENT=$(ls current/*.cdx.json | head -1) | ||
| bin/sbom-compare \ | ||
| --baseline "$BASELINE" \ | ||
| --current "$CURRENT" \ | ||
| --image "${{ matrix.image.name }}" \ | ||
| --policy .github/sbom-policy.json \ | ||
| > results/compare-${{ matrix.image.name }}.json | ||
|
|
||
| - name: Upload results | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: sbom-quality-gate-${{ matrix.image.name }} | ||
| path: results/ | ||
|
|
||
| report: | ||
| needs: score | ||
| # Run even if some score jobs failed, but not if the entire score job | ||
| # was skipped (which happens on direct pushes to main where there's no PR). | ||
| if: always() && needs.score.result != 'skipped' | ||
mrdavidlaing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| runs-on: blacksmith-2vcpu-ubuntu-2404 | ||
| permissions: | ||
| pull-requests: write | ||
| actions: read | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Download all results | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: sbom-quality-gate-* | ||
| merge-multiple: true | ||
| path: results/ | ||
|
|
||
| - name: Generate report | ||
| id: report | ||
| run: | | ||
| bin/sbom-report --scores-dir results/ > pr-comment.md 2>report-stderr.txt || { | ||
| cat report-stderr.txt >&2 | ||
| echo "failed=true" >> "$GITHUB_OUTPUT" | ||
| } | ||
|
|
||
| - name: Resolve PR number | ||
| id: pr | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| # The workflow_run event doesn't directly give us the PR number. | ||
| # Look it up from the head branch. | ||
| HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" | ||
| PR_NUMBER=$(gh pr list --head "$HEAD_BRANCH" --json number --jq '.[0].number') | ||
| echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Post PR comment | ||
| if: steps.pr.outputs.number | ||
| uses: marocchino/sticky-pull-request-comment@v3 | ||
| with: | ||
| header: sbom-quality-gate | ||
| number: ${{ steps.pr.outputs.number }} | ||
| path: pr-comment.md | ||
|
|
||
| - name: Fail on regression | ||
| if: steps.report.outputs.failed == 'true' | ||
| run: | | ||
| echo "SBOM quality regression detected. See PR comment for details." | ||
| exit 1 | ||
Oops, something went wrong.
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.