Skip to content

Commit 57e66c7

Browse files
authored
Merge pull request #4837 from owncloud/technical/adapt_sbom_workflow_signed_commits
[TECHNICAL] SBOM changes to be pushed in an specific branch with signed commits
2 parents b7b661c + 4e63507 commit 57e66c7

3 files changed

Lines changed: 55 additions & 30 deletions

File tree

.github/ISSUE_TEMPLATE/release_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you don't need some of the steps, cross them by removing the "[ ]" and surrou
2020
- [ ] [COM] Ping @mmattel about the new release
2121
- [ ] [GIT] Merge translations branch `chore/translations-update` into `master`
2222
- [ ] [GIT] Merge calens branch `chore/changelog-update` into `master`
23+
- [ ] [GIT] Merge sbom branch `chore/sbom-update` into `master`
2324
- [ ] [GIT] Create branch `release/M.m.p` in owncloud/android from `master`
2425
- [ ] [DEV] Update version number and name in build.gradle in owncloudApp module
2526
- [ ] [DIS] Move Calens files from `unreleased` to a new folder like `M.m.p_YYYY-MM-DD` inside the `changelog` folder

.github/workflows/sbom.yml

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,36 @@ name: SBOM
22

33
on:
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
12+
- master
13+
1514
concurrency:
16-
group: ${{ github.workflow }}-${{ github.ref }}
17-
cancel-in-progress: true
15+
group: sbom-update
16+
cancel-in-progress: false
1817

1918
permissions:
2019
contents: write
2120

2221
jobs:
2322
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')"
2623
runs-on: ubuntu-latest
24+
env:
25+
SOURCE_BRANCH: chore/sbom-update
26+
TARGET_BRANCH: ${{ github.event.inputs.target_branch || 'master' }}
2727

2828
steps:
2929
# Checkout the repository
3030
- name: Checkout repository
3131
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
3232
with:
33-
# Parent commit to compare
34-
fetch-depth: 2
3533
persist-credentials: false
3634

37-
3835
# Cache Gradle dependencies to speed up future builds
3936
- name: Cache Gradle dependencies
4037
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
@@ -79,40 +76,62 @@ jobs:
7976
EOF
8077
chmod +x normalize-sbom.sh
8178
82-
# Compares with the HEAD to check if there are changes
83-
- name: Compare with previous SBOM
79+
# Compare with the SBOM update branch, or master as fallback
80+
- name: Compare with previous SBOM in branch or master as fallback
8481
id: compare
8582
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
83+
# Branch to compare with in case the source branch does not exist
84+
FALLBACK_BRANCH="master"
85+
86+
echo "Checking whether branch $SOURCE_BRANCH exists in origin..."
87+
88+
# If source branch exists, fetch it and set as previous sbom
89+
if git ls-remote --exit-code --heads origin "$SOURCE_BRANCH"; then
90+
echo "Remote branch found: $SOURCE_BRANCH"
91+
git fetch origin "refs/heads/$SOURCE_BRANCH:refs/remotes/origin/$SOURCE_BRANCH" --depth=1
92+
PREVIOUS_SBOM_REF="origin/$SOURCE_BRANCH"
93+
echo "Using sbom.json from $PREVIOUS_SBOM_REF"
94+
# Use the fallback branch
95+
else
96+
echo "Remote branch not found: $SOURCE_BRANCH"
97+
PREVIOUS_SBOM_REF="origin/$FALLBACK_BRANCH"
98+
echo "Using sbom.json from fallback branch: $PREVIOUS_SBOM_REF"
99+
fi
100+
101+
git show "$PREVIOUS_SBOM_REF:sbom.json" > sbom_prev.json
88102
89103
./normalize-sbom.sh sbom_prev.json sbom_prev_normalized.json
90104
./normalize-sbom.sh sbom.json sbom_current_normalized.json
91105
92106
if diff -q sbom_prev_normalized.json sbom_current_normalized.json; then
93-
echo "no_changes=true" >> $GITHUB_OUTPUT
107+
echo "changes=false" >> $GITHUB_OUTPUT
94108
echo "No changes in SBOM"
95109
else
96-
echo "no_changes=false" >> $GITHUB_OUTPUT
110+
echo "changes=true" >> $GITHUB_OUTPUT
97111
echo "Differences in SBOM"
98112
diff sbom_prev_normalized.json sbom_current_normalized.json || true
99113
fi
100114
101115
# Generate a token to perform the commit in the next step
102116
- name: Generate GitHub App token
117+
if: steps.compare.outputs.changes == 'true'
103118
id: app-token
104119
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
105120
with:
106121
app-id: ${{ secrets.SBOM_APP_ID }}
107122
private-key: ${{ secrets.SBOM_APP_PRIVATE_KEY }}
108123

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
124+
# Create a branch with latest SBOM changes only if there are changes
125+
- name: Create or update SBOM PR
126+
if: steps.compare.outputs.changes == 'true'
127+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
113128
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 }}
129+
add-paths: sbom.json
130+
token: ${{ steps.app-token.outputs.token }}
131+
branch: ${{ env.SOURCE_BRANCH }}
132+
base: ${{ env.TARGET_BRANCH }}
133+
commit-message: "chore: update SBOM"
134+
title: "chore: update sbom.json"
135+
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."
136+
delete-branch: true
137+
sign-commits: true

changelog/unreleased/4837

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Change: SBOM to be updated in a separate branch with signed commits
2+
3+
SBOM workflow in GitHub Actions has been modified to accomplish security policies, assuring that commits are verified and pushing them to a specific branch
4+
5+
https://github.com/owncloud/android/pull/4837

0 commit comments

Comments
 (0)