Skip to content

Commit c1d5483

Browse files
authored
Merge pull request #4621 from owncloud/fix/sbom_into_repository
[FEATURE REQUEST] Modify sbom workflow to push to the repo
2 parents 2bdef05 + 428be66 commit c1d5483

File tree

3 files changed

+52
-39
lines changed

3 files changed

+52
-39
lines changed

.github/workflows/sbom.yml

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
name: SBOM
2-
3-
permissions:
4-
contents: read
1+
name: SBOM
52

63
on:
74
workflow_dispatch:
8-
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
permissions:
10+
contents: write
911

1012
jobs:
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 }}

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ ownCloud admins and users.
208208
* Enhancement - SBOM (Software Bill of Materials): [#4598](https://github.com/owncloud/android/issues/4598)
209209

210210
SBOM to be generated in every PR via GitHub Actions with the list of all
211-
dependencies used in the code. Tool cyclonedx builds it, artifact is exported to
212-
xml and finally converted to html with a xlst template.
211+
dependencies used in the code, powered by cyclonedx. Finally, it is pushed to
212+
the repo's root folder .
213213

214214
https://github.com/owncloud/android/issues/4598
215215
https://github.com/owncloud/android/pull/4599
216+
https://github.com/owncloud/android/pull/4621
216217

217218
# Changelog for ownCloud Android Client [4.5.1] (2025-04-03)
218219

changelog/unreleased/4599

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Enhancement: SBOM (Software Bill of Materials)
22

3-
SBOM to be generated in every PR via GitHub Actions with the list of all dependencies used in the code. Tool cyclonedx builds it, artifact is exported to xml and finally converted to html with a xlst template.
3+
SBOM to be generated in every PR via GitHub Actions with the list of all dependencies used in the code, powered by cyclonedx. Finally, it is pushed to the repo's root folder .
44

55
https://github.com/owncloud/android/issues/4598
66
https://github.com/owncloud/android/pull/4599
7-
7+
https://github.com/owncloud/android/pull/4621

0 commit comments

Comments
 (0)