-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ci(NODE-7025): New SBOM generation workflow on dependencies change #4807
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
Draft
ekovalets
wants to merge
6
commits into
mongodb:main
Choose a base branch
from
ekovalets:main
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.
+180
−0
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74b341c
NODE-7025: New SBOM generation workflow on dependencies change
ekovalets c32122b
NODE-7025: Using cyclone npm
ekovalets 46659ee
NODE-7025: Shell use fix
ekovalets e5f5aac
NODE-7025: Excluding dev dependencies
ekovalets 6908e91
NODE-7025: Only looking at package lock
ekovalets 856c1fd
NODE-7025: Fix typo
ekovalets 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,27 @@ | ||
| name: Generate SBOM | ||
| description: Generates CycloneDX SBOM using cdxgen | ||
| inputs: | ||
| output-file: | ||
| description: "Output filename for the SBOM" | ||
| required: false | ||
| default: "sbom.json" | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Generate SBOM | ||
| shell: bash | ||
| working-directory: ${{ inputs.working-directory }} | ||
| run: | | ||
| echo "Generating SBOM for 'node' project..." | ||
| npx @cyclonedx/cyclonedx-npm --package-lock-only --omit dev --output-file sbom.json --output-format json --spec-version 1.5 | ||
|
|
||
| - name: Validate SBOM | ||
| shell: bash | ||
| run: | | ||
| if [ ! -f "${{ inputs.output-file }}" ]; then | ||
| echo "Error: SBOM file not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "SBOM file validated: ${{ inputs.output-file }}" | ||
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,19 @@ | ||
| name: Setup PHP SBOM | ||
| description: Sets up environment for generating SBOM in PHP projects | ||
| inputs: | ||
| working-directory: | ||
| description: "The directory where composer.json is located" | ||
| required: false | ||
| default: "." | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Setup Node.js (for cdxgen) | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
| run: npm ci |
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,19 @@ | ||
| name: Setup Node SBOM | ||
| description: Sets up environment for generating SBOM in Node.js projects | ||
| inputs: | ||
| working-directory: | ||
| description: "The directory where package.json is located" | ||
| required: false | ||
| default: "." | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Setup Node.js (for cdxgen) | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
|
|
||
| - name: Install cdxgen | ||
| shell: bash | ||
| run: npm install -g @cyclonedx/cdxgen |
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,115 @@ | ||
| name: Post-Merge SBOM Update | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'package.json' | ||
| - 'package-lock.json' | ||
| workflow_dispatch: | ||
| env: | ||
| SBOM_FILE: "sbom.json" | ||
| 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 (Base Branch) | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref || github.ref }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Install Node and dependencies | ||
| uses: mongodb-labs/drivers-github-tools/node/setup@v3 | ||
| with: | ||
| ignore_install_scripts: false | ||
|
|
||
| - name: Load version and package info | ||
| uses: mongodb-labs/drivers-github-tools/node/get_version_info@v3 | ||
| with: | ||
| npm_package_name: mongodb | ||
|
|
||
| - name: Generate/Update package-lock.json | ||
| run: | | ||
| echo "Resolving dependencies and generating package-lock.json..." | ||
| npm install --package-lock-only | ||
| echo "package-lock.json generated with resolved versions" | ||
|
|
||
| - name: Setup SBOM environment | ||
| uses: ./.github/actions/setup-sbom | ||
|
|
||
| - name: Generate SBOM | ||
| uses: ./.github/actions/sbom-update | ||
| with: | ||
| output-file: ${SBOM_FILE} | ||
|
|
||
| - name: Check for Changes in sbom.json | ||
| id: git_status | ||
| run: | | ||
| # Filter to remove/normalize serialNumber and timestamp fields | ||
| JQ_NORMALIZER='del(.serialNumber) | del(.metadata.timestamp) | walk(if type == "object" and .timestamp then .timestamp = "TIMESTAMP_NORMALIZED" else . end)' | ||
|
|
||
| # Check if the base file exists in Git (to prevent errors on first commit) | ||
| if ! git show HEAD:$SBOM_FILE > /dev/null 2>&1; then | ||
| echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Compare the normalized committed version vs. the normalized current version | ||
| if diff -q \ | ||
| <(git show HEAD:$SBOM_FILE | jq -r "$JQ_NORMALIZER") \ | ||
| <(cat $SBOM_FILE | jq -r "$JQ_NORMALIZER"); then | ||
|
|
||
| echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT | ||
| echo "No changes detected in sbom.json" | ||
| else | ||
| echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT | ||
| echo "Changes detected in sbom.json" | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.git_status.outputs.HAS_CHANGES == 'true' | ||
| uses: peter-evans/create-pull-request@v6 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: 'chore: update SBOM after dependency changes' | ||
| add-paths: | | ||
| sbom.json | ||
| branch: auto-update-sbom-${{ github.run_id }} | ||
| delete-branch: true | ||
| title: 'chore: Update SBOM' | ||
| body: | | ||
| ## Automated SBOM Update | ||
|
|
||
| This PR was automatically generated because package files changed. | ||
|
|
||
| ### Environment | ||
| - Node.js version: ${{ steps.versions.outputs.node-version }} | ||
|
|
||
| ### Changes | ||
| - Updated `sbom.json` to reflect current dependencies | ||
|
|
||
| ### Verification | ||
| The SBOM was generated using CycloneDX NPM. | ||
|
|
||
| ### 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto-opening a PR after another PR merges is just likely to be forgotten by our team. Could we instead add a PR check that blocks a PR from merging if there is a diff in the generated SBOM (and include tooling so that we can generate the SBOM locally)?
This does requires manual generation from us but this works better for our workflow.