Skip to content

Commit db63655

Browse files
committed
feat: modify sbom workflow to push to the repo instead of creating action's artifact
1 parent 210997d commit db63655

1 file changed

Lines changed: 49 additions & 35 deletions

File tree

.github/workflows/sbom.yml

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
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+
persist-credentials: false
23+
fetch-depth: 0
1724

18-
# Caches Gradle dependencies to avoid downloading them on every run
25+
# Cache Gradle dependencies for faster builds
1926
- name: Cache Gradle dependencies
2027
uses: actions/cache@v4
2128
with:
@@ -27,48 +34,55 @@ jobs:
2734
restore-keys: |
2835
${{ runner.os }}-gradle-
2936
37+
# Set up Java 17 for the Gradle build
3038
- name: Set up JDK 17
3139
uses: actions/setup-java@v4
3240
with:
3341
java-version: '17'
3442
distribution: 'temurin'
3543

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
44+
# Generate the SBOM file using the CycloneDX plugin
4245
- name: Generate SBOM (CycloneDX)
4346
run: ./gradlew --no-daemon cyclonedxBom
4447

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

48-
# Create a specific artifact name using the branch name and timestamp
49-
- name: Set artifact name
50-
id: vars
52+
# Remove non-deterministic fields to ensure meaningful diffs
53+
- name: Clean serialNumber and timestamp in SBOM
5154
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
55+
sudo apt-get update && sudo apt-get install -y jq
56+
jq 'del(.serialNumber, .timestamp)' sbom.json > sbom_clean.json && mv sbom_clean.json sbom.json
57+
58+
# Fetch the latest state of the master branch for comparison
59+
- name: Fetch origin/master
60+
run: git fetch origin master
5661

57-
- name: Rename SBOM XML and HTML files to match artifact name
62+
# Extract and clean the SBOM from origin/master for comparison
63+
- name: Extract clean SBOM from origin/master
5864
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"
65+
# If sbom.json does not exist on master, create an empty JSON to prevent failure
66+
git show origin/master:sbom.json > sbom_master.json || echo '{}' > sbom_master.json
67+
jq 'del(.serialNumber, .timestamp)' sbom_master.json > sbom_master_clean.json
6268
63-
- name: ZIP all the files
69+
# Compare the current SBOM with the cleaned version from master
70+
- name: Compare current SBOM with master
71+
id: diff
6472
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"
73+
if diff -q sbom.json sbom_master_clean.json; then
74+
echo "no_changes=true" >> $GITHUB_OUTPUT
75+
else
76+
echo "no_changes=false" >> $GITHUB_OUTPUT
77+
fi
6978
70-
- name: Upload SBOM artifact
71-
uses: actions/upload-artifact@v4
79+
# Commit and push the new SBOM only if it differs from master
80+
- name: Commit files
81+
if: steps.diff.outputs.no_changes == 'false'
82+
uses: GuillaumeFalourd/git-commit-push@v1.3
7283
with:
73-
name: ${{ steps.vars.outputs.artifact_name }}
74-
path: ${{ steps.vars.outputs.artifact_name }}.zip
84+
email: devops@owncloud.com
85+
name: ownClouders
86+
commit_message: "docs: SBOM updated [skip ci]"
87+
files: sbom.json
88+
access_token: ${{ github.token }}

0 commit comments

Comments
 (0)