Skip to content

Commit 2a93706

Browse files
committed
feat: modify sbom workflow to push to the repo instead of creating action's artifact
1 parent 2bdef05 commit 2a93706

1 file changed

Lines changed: 48 additions & 35 deletions

File tree

.github/workflows/sbom.yml

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
name: SBOM
2-
3-
permissions:
4-
contents: read
1+
name: SBOM
52

63
on:
74
workflow_dispatch:
8-
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- main
9+
10+
permissions:
11+
contents: write
912

1013
jobs:
1114
sbom:
1215
runs-on: ubuntu-latest
13-
16+
1417
steps:
18+
# Checkout the full repository history (required to access origin/master)
1519
- name: Checkout repository
1620
uses: actions/checkout@v4
21+
with:
22+
ssh-key: ${{ secrets.DEPLOYMENT_SSH_KEY }}
1723

18-
# Caches Gradle dependencies to avoid downloading them on every run
24+
# Cache Gradle dependencies for faster builds
1925
- name: Cache Gradle dependencies
2026
uses: actions/cache@v4
2127
with:
@@ -27,48 +33,55 @@ jobs:
2733
restore-keys: |
2834
${{ runner.os }}-gradle-
2935
36+
# Set up Java 17 for the Gradle build
3037
- name: Set up JDK 17
3138
uses: actions/setup-java@v4
3239
with:
3340
java-version: '17'
3441
distribution: 'temurin'
3542

36-
- name: Install xsltproc
37-
run: |
38-
sudo apt-get update
39-
sudo apt-get install -y xsltproc
40-
41-
# Use --no-daemon to prevent Gradle from running in the background
43+
# Generate the SBOM file using the CycloneDX plugin
4244
- name: Generate SBOM (CycloneDX)
4345
run: ./gradlew --no-daemon cyclonedxBom
4446

45-
- name: Convert SBOM to HTML
46-
run: xsltproc sbom/cyclonedx-xml-to-html.xslt build/reports/bom.xml > sbom.html
47+
# Move the generated SBOM to the repository root and rename it
48+
- name: Move and rename SBOM to root
49+
run: mv build/reports/bom.json ./sbom.json
4750

48-
# Create a specific artifact name using the branch name and timestamp
49-
- name: Set artifact name
50-
id: vars
51+
# Remove non-deterministic fields to ensure meaningful diffs
52+
- name: Clean serialNumber and timestamp in SBOM
5153
run: |
52-
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
53-
SAFE_BRANCH=$(echo "$BRANCH" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
54-
TIMESTAMP=$(date -u +"%Y%m%d-%H%M%S")
55-
echo "artifact_name=sbom-${SAFE_BRANCH}-${TIMESTAMP}" >> $GITHUB_OUTPUT
54+
sudo apt-get update && sudo apt-get install -y jq
55+
jq 'del(.serialNumber, .timestamp)' sbom.json > sbom_clean.json && mv sbom_clean.json sbom.json
56+
57+
# Fetch the latest state of the master branch for comparison
58+
- name: Fetch origin/master
59+
run: git fetch origin master
5660

57-
- name: Rename SBOM XML and HTML files to match artifact name
61+
# Extract and clean the SBOM from origin/master for comparison
62+
- name: Extract clean SBOM from origin/master
5863
run: |
59-
mv sbom.html "${{ steps.vars.outputs.artifact_name }}.html"
60-
mv build/reports/bom.xml "${{ steps.vars.outputs.artifact_name }}.xml"
61-
mv build/reports/bom.json "${{ steps.vars.outputs.artifact_name }}.json"
64+
# If sbom.json does not exist on master, create an empty JSON to prevent failure
65+
git show origin/master:sbom.json > sbom_master.json || echo '{}' > sbom_master.json
66+
jq 'del(.serialNumber, .timestamp)' sbom_master.json > sbom_master_clean.json
6267
63-
- name: ZIP all the files
68+
# Compare the current SBOM with the cleaned version from master
69+
- name: Compare current SBOM with master
70+
id: diff
6471
run: |
65-
zip "${{ steps.vars.outputs.artifact_name }}.zip" \
66-
"${{ steps.vars.outputs.artifact_name }}.html" \
67-
"${{ steps.vars.outputs.artifact_name }}.xml" \
68-
"${{ steps.vars.outputs.artifact_name }}.json"
72+
if diff -q sbom.json sbom_master_clean.json; then
73+
echo "no_changes=true" >> $GITHUB_OUTPUT
74+
else
75+
echo "no_changes=false" >> $GITHUB_OUTPUT
76+
fi
6977
70-
- name: Upload SBOM artifact
71-
uses: actions/upload-artifact@v4
78+
# Commit and push the new SBOM only if it differs from master
79+
- name: Commit files
80+
if: steps.diff.outputs.no_changes == 'false'
81+
uses: GuillaumeFalourd/git-commit-push@v1.3
7282
with:
73-
name: ${{ steps.vars.outputs.artifact_name }}
74-
path: ${{ steps.vars.outputs.artifact_name }}.zip
83+
email: devops@owncloud.com
84+
name: ownClouders
85+
commit_message: "docs: SBOM updated [skip ci]"
86+
files: sbom.json
87+
access_token: ${{ github.token }}

0 commit comments

Comments
 (0)