@@ -11,6 +11,7 @@ permissions:
1111
1212jobs :
1313 sbom :
14+ if : " !contains(github.event.head_commit.message, 'SBOM updated')"
1415 runs-on : ubuntu-latest
1516
1617 steps :
@@ -73,29 +74,43 @@ jobs:
7374 - name : Fetch origin/master
7475 run : git fetch origin master_fake
7576
76- # Extract, clean, and normalize the SBOM file from origin/master
77- - name : Extract and normalize SBOM from origin/master
77+ # Prepare common JQ filter in a script
78+ - name : Prepare normalize script
79+ run : |
80+ cat <<'EOF' > normalize-sbom.sh
81+ jq -S '
82+ del(.serialNumber, .timestamp, .metadata.timestamp, .metadata.authors, .metadata.tools)
83+ | .components |= (if type=="array" then sort_by(.["bom-ref"] // "") else . end)
84+ | .dependencies |= (if type=="array" then sort_by(.ref // "") else . end)
85+ ' "$1" > "$2"
86+ EOF
87+ chmod +x normalize-sbom.sh
88+
89+ # Extract & normalize both SBOMs
90+ - name : Extract and normalize both SBOMs
7891 run : |
7992 git show origin/master_fake:sbom.json > sbom_master.json || echo '{}' > sbom_master.json
80- jq -S 'del(.serialNumber, .timestamp, .metadata.timestamp, .metadata.authors, .metadata.tools)' sbom_master.json > sbom_master_normalized.json
93+ ./normalize-sbom.sh sbom_master.json sbom_master_normalized.json
94+ ./normalize-sbom.sh sbom.json sbom_normalized.json
8195
82- # Normalize current SBOM and compare with normalized master SBOM
83- - name : Compare current SBOM with master
84- id : diff
96+ # Compare normalized SBOMs
97+ - name : Compare SBOMs and show diff
98+ id : diff_sbom
8599 run : |
86- jq -S 'del(.serialNumber, .timestamp, .metadata.timestamp, .metadata.authors, .metadata.tools)' sbom.json > sbom_normalized.json
87- if diff -q sbom_normalized.json sbom_master_normalized.json; then
100+ if diff -u sbom_master_normalized.json sbom_normalized.json > sbom_diff.txt; then
88101 echo "no_changes=true" >> $GITHUB_OUTPUT
89102 else
90103 echo "no_changes=false" >> $GITHUB_OUTPUT
104+ echo "Differences found in SBOM:"
105+ cat sbom_diff.txt
91106 fi
92107
93108 # Commit the SBOM file only if it differs from master to avoid unnecessary commits
94109 - name : Commit files
95- if : steps.diff .outputs.no_changes == 'false'
110+ if : steps.diff_sbom .outputs.no_changes == 'false'
96111 uses : GuillaumeFalourd/git-commit-push@v1.3
97112 with :
98113 email : devops@owncloud.com
99114 name : ownClouders
100- commit_message : " docs: SBOM updated [skip ci] "
115+ commit_message : " docs: SBOM updated"
101116 files : sbom.json
0 commit comments