Skip to content

Commit e72a6fe

Browse files
committed
ci: update gh workflow
Signed-off-by: Sonu Saha <[email protected]>
1 parent 8818fa9 commit e72a6fe

File tree

1 file changed

+61
-36
lines changed

1 file changed

+61
-36
lines changed

.github/workflows/sbom.yml

+61-36
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,73 @@
1-
name: Generate GitHub SBOM and Upload as Artifact
2-
3-
# NOTE: We would probably want to run this workflow on every push to main and not on pull requests
1+
name: Download SBOM from Insights and Convert to CSV
42

53
# on:
6-
# push:
7-
# branches:
8-
# - main
4+
# workflow_dispatch:
5+
6+
7+
# # NOTE: We would probably want to run this workflow on every push to main and not on pull requests
8+
# # on:
9+
# # push:
10+
# # branches:
11+
# # - main
912

1013
on:
1114
pull_request:
1215
branches:
1316
- main
1417

1518
jobs:
16-
generate-sbom:
19+
convert-sbom:
1720
runs-on: ubuntu-latest
1821

19-
permissions:
20-
contents: read
21-
security-events: read
22-
2322
steps:
24-
# Step 1: Checkout the repository
25-
- name: Checkout repository
26-
uses: actions/checkout@v3
27-
28-
# Step 2: Generate GitHub SBOM (Dependency Snapshot)
29-
- name: Generate GitHub SBOM
30-
id: sbom
31-
uses: actions/dependency-review-action@v3
32-
with:
33-
token: ${{ secrets.GITHUB_TOKEN }}
34-
output: sbom.json # Save as JSON file
35-
36-
# Step 3: Convert SBOM to CSV
37-
- name: Convert SBOM to CSV
38-
run: |
39-
jq -r '.dependencies[] | [.package.name, .package.version, .relationship] | @csv' sbom.json > sbom.csv
40-
41-
# Step 4: Upload SBOM as GitHub Artifact
42-
- name: Upload SBOM and CSV as Artifact
43-
uses: actions/upload-artifact@v3
44-
with:
45-
name: sbom-files
46-
path: |
47-
sbom.json
48-
sbom.csv
23+
- name: Checkout Code
24+
uses: actions/checkout@v3
25+
26+
- name: Set Timestamp and Unique Filename
27+
run: |
28+
FILE_PREFIX=$(echo "${{ github.repository }}" | sed 's|/|-|g')-$(date +%Y%m%d%H%M%S)
29+
echo "FILE_PREFIX=${FILE_PREFIX}" >> $GITHUB_ENV
30+
31+
- name: Download SBOM
32+
run: |
33+
curl -L \
34+
-H "Accept: application/vnd.github+json" \
35+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
36+
-H "X-GitHub-Api-Version: 2022-11-28" \
37+
https://api.github.com/repos/${{ github.repository }}/dependency-graph/sbom \
38+
-o "${FILE_PREFIX}-sbom.json"
39+
40+
- name: Verify SBOM JSON File
41+
run: |
42+
ls -l "${FILE_PREFIX}-sbom.json"
43+
44+
- name: Preview SBOM JSON Content
45+
run: |
46+
head -n 20 "${FILE_PREFIX}-sbom.json"
47+
48+
- name: Convert SBOM to CSV using jq
49+
run: |
50+
jq -r '
51+
.sbom.packages[] | [
52+
.name,
53+
.SPDXID,
54+
.versionInfo,
55+
.downloadLocation,
56+
( .externalRefs[]? | .referenceLocator )
57+
] | @csv' "${FILE_PREFIX}-sbom.json" > "${FILE_PREFIX}-sbom.csv"
58+
59+
- name: Verify SBOM CSV File
60+
run: |
61+
ls -l "${FILE_PREFIX}-sbom.csv"
62+
63+
- name: Upload SBOM JSON as Artifact
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: sbom-json
67+
path: ${{ env.FILE_PREFIX }}-sbom.json
68+
69+
- name: Upload SBOM CSV as Artifact
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: sbom-csv
73+
path: ${{ env.FILE_PREFIX }}-sbom.csv

0 commit comments

Comments
 (0)