1- name : SBOM
2-
3- permissions :
4- contents : read
1+ name : SBOM
52
63on :
74 workflow_dispatch :
8- pull_request :
5+ push :
6+ branches :
7+ - master
8+
9+ permissions :
10+ contents : write
911
1012jobs :
1113 sbom :
1214 runs-on : ubuntu-latest
13-
15+
1416 steps :
17+ # Checkout the full repository history (required to access origin/master)
1518 - name : Checkout repository
1619 uses : actions/checkout@v4
20+ with :
21+ ssh-key : ${{ secrets.DEPLOYMENT_SSH_KEY }}
1722
18- # Caches Gradle dependencies to avoid downloading them on every run
23+ # Cache Gradle dependencies for faster builds
1924 - name : Cache Gradle dependencies
2025 uses : actions/cache@v4
2126 with :
@@ -27,48 +32,55 @@ jobs:
2732 restore-keys : |
2833 ${{ runner.os }}-gradle-
2934
35+ # Set up Java 17 for the Gradle build
3036 - name : Set up JDK 17
3137 uses : actions/setup-java@v4
3238 with :
3339 java-version : ' 17'
3440 distribution : ' temurin'
3541
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
42+ # Generate the SBOM file using the CycloneDX plugin
4243 - name : Generate SBOM (CycloneDX)
4344 run : ./gradlew --no-daemon cyclonedxBom
4445
45- - name : Convert SBOM to HTML
46- run : xsltproc sbom/cyclonedx-xml-to-html.xslt build/reports/bom.xml > sbom.html
46+ # Move the generated SBOM to the repository root and rename it
47+ - name : Move and rename SBOM to root
48+ run : mv build/reports/bom.json ./sbom.json
4749
48- # Create a specific artifact name using the branch name and timestamp
49- - name : Set artifact name
50- id : vars
50+ # Remove non-deterministic fields to ensure meaningful diffs
51+ - name : Clean serialNumber and timestamp in SBOM
5152 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
53+ sudo apt-get update && sudo apt-get install -y jq
54+ jq 'del(.serialNumber, .timestamp)' sbom.json > sbom_clean.json && mv sbom_clean.json sbom.json
55+
56+ # Fetch the latest state of the master branch for comparison
57+ - name : Fetch origin/master
58+ run : git fetch origin master
5659
57- - name : Rename SBOM XML and HTML files to match artifact name
60+ # Extract and clean the SBOM from origin/master for comparison
61+ - name : Extract clean SBOM from origin/master
5862 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"
63+ # If sbom.json does not exist on master, create an empty JSON to prevent failure
64+ git show origin/master:sbom.json > sbom_master.json || echo '{}' > sbom_master.json
65+ jq 'del(.serialNumber, .timestamp)' sbom_master. json > sbom_master_clean. json
6266
63- - name : ZIP all the files
67+ # Compare the current SBOM with the cleaned version from master
68+ - name : Compare current SBOM with master
69+ id : diff
6470 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"
71+ if diff -q sbom.json sbom_master_clean.json; then
72+ echo "no_changes=true" >> $GITHUB_OUTPUT
73+ else
74+ echo "no_changes=false" >> $GITHUB_OUTPUT
75+ fi
6976
70- - name : Upload SBOM artifact
71- uses : actions/upload-artifact@v4
77+ # Commit and push the new SBOM only if it differs from master
78+ - name : Commit files
79+ if : steps.diff.outputs.no_changes == 'false'
80+ uses : GuillaumeFalourd/git-commit-push@v1.3
7281 with :
73- name : ${{ steps.vars.outputs.artifact_name }}
74- path : ${{ steps.vars.outputs.artifact_name }}.zip
82+ email : devops@owncloud.com
83+ name : ownClouders
84+ commit_message : " docs: SBOM updated [skip ci]"
85+ files : sbom.json
86+ access_token : ${{ github.token }}
0 commit comments