@@ -2,39 +2,33 @@ name: SBOM
22
33on :
44 workflow_dispatch :
5+ inputs :
6+ target_branch :
7+ type : string
8+ required : false
9+ default : master
510 push :
611 branches :
7- - feature/*
8- - fix/*
9- - improvement/*
10- - release/*
11- - technical/*
12- - ' dependabot/**'
13-
14- # Cancels other executions in the same branch
15- concurrency :
16- group : ${{ github.workflow }}-${{ github.ref }}
17- cancel-in-progress : true
12+ - master
1813
1914permissions :
2015 contents : write
2116
2217jobs :
2318 sbom :
24- # Skip if the job was triggered by the SBOM commit or a merge commit in the latest push.
25- if : " !contains(github.event.head_commit.message, 'Merge pull request') && !contains(github.event.head_commit.message, 'SBOM updated')"
2619 runs-on : ubuntu-latest
20+ env :
21+ SOURCE_BRANCH : chore/sbom-update
22+ TARGET_BRANCH : ${{ github.event.inputs.target_branch || 'master' }}
2723
2824 steps :
2925 # Checkout the repository
3026 - name : Checkout repository
3127 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3228 with :
33- # Parent commit to compare
3429 fetch-depth : 2
3530 persist-credentials : false
3631
37-
3832 # Cache Gradle dependencies to speed up future builds
3933 - name : Cache Gradle dependencies
4034 uses : actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
@@ -79,40 +73,61 @@ jobs:
7973 EOF
8074 chmod +x normalize-sbom.sh
8175
82- # Compares with the HEAD to check if there are changes
83- - name : Compare with previous SBOM
76+ # Compare with the SBOM update branch, or master as fallback
77+ - name : Compare with previous SBOM in branch or master as fallback
8478 id : compare
8579 run : |
86- # Try HEAD first to compare with previous commit's sbom (HEAD~1)
87- git show HEAD~1:sbom.json > sbom_prev.json 2>/dev/null || echo '{}' > sbom_prev.json
80+ FALLBACK_BRANCH="master"
81+
82+ echo "Checking whether branch $SOURCE_BRANCH exists in origin..."
83+
84+ # If source branch exists, fetch it and set as previous sbom
85+ if git ls-remote --exit-code --heads origin "$SOURCE_BRANCH"; then
86+ echo "Remote branch found: $SOURCE_BRANCH"
87+ git fetch origin "refs/heads/$SOURCE_BRANCH:refs/remotes/origin/$SOURCE_BRANCH" --depth=1
88+ PREVIOUS_SBOM_REF="origin/$SOURCE_BRANCH"
89+ echo "Using sbom.json from $PREVIOUS_SBOM_REF"
90+ # Use the fallback branch
91+ else
92+ echo "Remote branch not found: $SOURCE_BRANCH"
93+ PREVIOUS_SBOM_REF="origin/$FALLBACK_BRANCH"
94+ echo "Using sbom.json from fallback branch: $PREVIOUS_SBOM_REF"
95+ fi
96+
97+ git show "$PREVIOUS_SBOM_REF:sbom.json" > sbom_prev.json
8898
8999 ./normalize-sbom.sh sbom_prev.json sbom_prev_normalized.json
90100 ./normalize-sbom.sh sbom.json sbom_current_normalized.json
91101
92102 if diff -q sbom_prev_normalized.json sbom_current_normalized.json; then
93- echo "no_changes=true " >> $GITHUB_OUTPUT
103+ echo "changes=false " >> $GITHUB_OUTPUT
94104 echo "No changes in SBOM"
95105 else
96- echo "no_changes=false " >> $GITHUB_OUTPUT
106+ echo "changes=true " >> $GITHUB_OUTPUT
97107 echo "Differences in SBOM"
98108 diff sbom_prev_normalized.json sbom_current_normalized.json || true
99109 fi
100110
101111 # Generate a token to perform the commit in the next step
102112 - name : Generate GitHub App token
113+ if : steps.compare.outputs.changes == 'true'
103114 id : app-token
104115 uses : actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
105116 with :
106117 app-id : ${{ secrets.SBOM_APP_ID }}
107118 private-key : ${{ secrets.SBOM_APP_PRIVATE_KEY }}
108119
109- # Commit the SBOM file only if it differs from master to avoid unnecessary commits
110- - name : Commit and push updated SBOM
111- if : steps.compare.outputs.no_changes == 'false '
112- uses : GuillaumeFalourd/git-commit-push@205c043bca2f932f7a48a28a8d619ba30eb84baf # v1.3
120+ # Create a branch with latest SBOM changes only if there are changes
121+ - name : Create or update SBOM PR
122+ if : steps.compare.outputs.changes == 'true '
123+ uses : peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
113124 with :
114- commit_message : " docs: SBOM updated"
115- files : sbom.json
116- email : devops@owncloud.com
117- name : ownClouders
118- access_token : ${{ steps.app-token.outputs.token }}
125+ add-paths : sbom.json
126+ token : ${{ steps.app-token.outputs.token }}
127+ branch : ${{ env.SOURCE_BRANCH }}
128+ base : ${{ env.TARGET_BRANCH }}
129+ commit-message : " chore: update SBOM"
130+ title : " chore: update sbom.json"
131+ body : " Automated SBOM update. This pull request is updated on each push to `master` or manual dispatch — merging it will close it and a fresh one will be opened on the next change."
132+ delete-branch : true
133+ sign-commits : true
0 commit comments