@@ -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 :
2728 mkdir -p ~/.ssh
2829 echo "${{ secrets.DEPLOYMENT_SSH_KEY_TEST }}" > ~/.ssh/id_rsa
2930 chmod 600 ~/.ssh/id_rsa
30- # Start the SSH agent in the background
3131 eval "$(ssh-agent -s)"
32- # Add the private key to the SSH agent
3332 ssh-add ~/.ssh/id_rsa
34- # Add GitHub's public SSH keys to known_hosts to prevent host verification prompts
3533 ssh-keyscan github.com >> ~/.ssh/known_hosts
36- # Test the SSH connection to GitHub (this will fail gracefully if not successful)
3734 ssh -o StrictHostKeyChecking=no -T git@github.com || true
3835
3936 # Dry-run push to confirm SSH authentication is working
@@ -69,38 +66,51 @@ jobs:
6966 - name : Move and rename SBOM to root
7067 run : mv build/reports/bom.json ./sbom.json
7168
72- # Clean dynamic fields (serialNumber and timestamp) for meaningful diffs
73- - name : Clean serialNumber and timestamp in SBOM
74- run : |
75- sudo apt-get update && sudo apt-get install -y jq
76- jq 'del(.serialNumber, .timestamp)' sbom.json > sbom_clean.json && mv sbom_clean.json sbom.json
69+ # Install jq (JSON processor) for JSON manipulations
70+ - name : Install jq
71+ run : sudo apt-get update && sudo apt-get install -y jq
7772
7873 # Fetch the master branch to compare with current SBOM
7974 - name : Fetch origin/master
8075 run : git fetch origin master_fake
8176
82- # Extract and clean the SBOM file from origin/master
83- - name : Extract clean 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
8491 run : |
8592 git show origin/master_fake:sbom.json > sbom_master.json || echo '{}' > sbom_master.json
86- jq 'del(.serialNumber, .timestamp)' sbom_master.json > sbom_master_clean.json
93+ ./normalize-sbom.sh sbom_master.json sbom_master_normalized.json
94+ ./normalize-sbom.sh sbom.json sbom_normalized.json
8795
88- # Compare current SBOM with cleaned master version and set output
89- - name : Compare current SBOM with master
90- id : diff
96+ # Compare normalized SBOMs
97+ - name : Compare SBOMs and show diff
98+ id : diff_sbom
9199 run : |
92- if diff -q sbom .json sbom_master_clean .json; then
100+ if diff -u sbom_master_normalized .json sbom_normalized .json > sbom_diff.txt ; then
93101 echo "no_changes=true" >> $GITHUB_OUTPUT
94102 else
95103 echo "no_changes=false" >> $GITHUB_OUTPUT
104+ echo "Differences found in SBOM:"
105+ cat sbom_diff.txt
96106 fi
97107
98- # Commit the file, only if it is different than the existing one
108+ # Commit the SBOM file only if it differs from master to avoid unnecessary commits
99109 - name : Commit files
100110 if : steps.diff.outputs.no_changes == 'false'
101111 uses : GuillaumeFalourd/git-commit-push@v1.3
102112 with :
103113 email : devops@owncloud.com
104114 name : ownClouders
105- commit_message : " docs: SBOM updated [skip ci] "
115+ commit_message : " docs: SBOM updated"
106116 files : sbom.json
0 commit comments