Skip to content

Commit a8748ce

Browse files
RUBY-3682 Automated SBOM Generation (#2968)
* Added workflow for sbom automation * Fixing silkbomb compatability * Fix comment
1 parent 60c1e68 commit a8748ce

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

.github/workflows/sbom.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Generate SBOM
2+
3+
# This workflow uses cyclonedx/cdxgen and publishes an sbom.json artifact.
4+
# It runs on manual trigger or when package files change on master branch,
5+
# and creates a PR with the updated SBOM.
6+
# Internal documentation: go/sbom-scope
7+
8+
on:
9+
workflow_dispatch: {}
10+
push:
11+
branches: ['master']
12+
paths:
13+
- 'Gemfile'
14+
- 'Gemfile.lock'
15+
- 'mongo.gemspec'
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
21+
jobs:
22+
sbom:
23+
name: Generate SBOM and Create PR
24+
runs-on: ubuntu-latest
25+
concurrency:
26+
group: sbom-${{ github.ref }}
27+
cancel-in-progress: false
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
persist-credentials: false
34+
35+
- name: Set up Ruby
36+
uses: ruby/setup-ruby@v1
37+
with:
38+
ruby-version: "3.2"
39+
40+
- name: Install dependencies
41+
run: bundle install --standalone
42+
43+
- name: Generate SBOM
44+
run: |
45+
# Generate SBOM with license fetching and required-only flag
46+
FETCH_LICENSE=true npx -y -p "@cyclonedx/cdxgen@11.0.0" \
47+
cdxgen \
48+
--type ruby \
49+
--spec-version 1.5 \
50+
--required-only \
51+
--output sbom.json
52+
53+
# Post-process SBOM: remove incompatible fields and fix licenses
54+
jq '
55+
# Remove incompatible fields for silkbomb compatibility
56+
del(.metadata.lifecycles) |
57+
walk(if type == "object" then del(.evidence) else . end) |
58+
59+
# Fix missing licenses
60+
.components |= map(
61+
if .name == "yard-solargraph" and
62+
(.licenses == null or .licenses == []) then
63+
. + {licenses: [{license: {
64+
id: "MIT",
65+
url: "https://opensource.org/licenses/MIT"
66+
}}]}
67+
else
68+
.
69+
end
70+
)
71+
' sbom.json > sbom.tmp.json && mv sbom.tmp.json sbom.json
72+
73+
- name: Download CycloneDX CLI
74+
run: |
75+
curl -L -s -o /tmp/cyclonedx \
76+
"https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64"
77+
chmod +x /tmp/cyclonedx
78+
79+
- name: Validate SBOM
80+
run: |
81+
/tmp/cyclonedx validate --input-file sbom.json \
82+
--fail-on-errors
83+
84+
- name: Cleanup vendor directory
85+
if: always()
86+
run: |
87+
# Remove vendor directory if it was created during bundle install
88+
rm -rf vendor/
89+
90+
- name: Upload SBOM artifact
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: sbom
94+
path: sbom.json
95+
if-no-files-found: error
96+
97+
- name: Create Pull Request
98+
# peter-evans/create-pull-request v7.0.6
99+
uses: peter-evans/create-pull-request@b4733b9419fd47bbfa1807b15627e17cd70b5b22
100+
with:
101+
token: ${{ secrets.GITHUB_TOKEN }}
102+
commit-message: 'chore: Update SBOM after dependency changes'
103+
branch: auto-update-sbom-${{ github.run_id }}
104+
delete-branch: true
105+
title: 'chore: Update SBOM'
106+
add-paths: |
107+
sbom.json
108+
body: |
109+
## Automated SBOM Update
110+
111+
This PR was automatically generated because dependency
112+
manifest files changed.
113+
114+
### Changes
115+
- Updated `sbom.json` to reflect current dependencies
116+
117+
### Verification
118+
The SBOM was generated using @cyclonedx/cdxgen v11.0.0 with
119+
the ruby type.
120+
121+
### Triggered by
122+
- Commit: ${{ github.sha }}
123+
- Workflow run: ${{ github.run_id }}
124+
125+
---
126+
_This PR was created automatically by the [SBOM workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})_
127+
labels: |
128+
sbom
129+
automated
130+
dependencies

0 commit comments

Comments
 (0)