Skip to content

Commit 3583e87

Browse files
committed
feat: make yaml file more consistent, including cache and setting an unique artifact name
1 parent fff8b08 commit 3583e87

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

.github/workflows/sbom.yml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: SBOM
22

3-
on:
3+
permissions:
4+
contents: read
45

6+
on:
57
workflow_dispatch:
68
pull_request:
7-
branches:
8-
- "*"
99

1010
jobs:
1111
sbom:
@@ -15,24 +15,50 @@ jobs:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
1717

18+
# Caches Gradle dependencies to avoid downloading them on every run
19+
- name: Cache Gradle dependencies
20+
uses: actions/cache@v3
21+
with:
22+
path: |
23+
~/.gradle/caches
24+
~/.gradle/wrapper
25+
~/.gradle/wrapper/dists/
26+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
27+
restore-keys: |
28+
${{ runner.os }}-gradle-
29+
1830
- name: Set up JDK 17
1931
uses: actions/setup-java@v4
2032
with:
2133
java-version: '17'
2234
distribution: 'temurin'
2335

2436
- name: Install xsltproc
25-
run: sudo apt-get update && sudo apt-get install -y xsltproc
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y xsltproc
2640
41+
# Use --no-daemon to prevent Gradle from running in the background
2742
- name: Generate SBOM (CycloneDX)
28-
run: ./gradlew cyclonedxBom
43+
run: ./gradlew --no-daemon cyclonedxBom
2944

3045
- name: Convert SBOM to HTML
3146
run: xsltproc sbom/cyclonedx-xml-to-html.xslt build/reports/bom.xml > sbom.html
3247

33-
- name: Upload SBOM as artifact
34-
if: success()
48+
# Create a specific artifact name using the branch name and timestamp
49+
- name: Set artifact name
50+
id: vars
51+
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
56+
57+
- name: Rename SBOM HTML file to match artifact name
58+
run: mv sbom.html "${{ steps.vars.outputs.artifact_name }}.html"
59+
60+
- name: Upload SBOM artifact
3561
uses: actions/upload-artifact@v4
3662
with:
37-
name: sbom
38-
path: sbom.html
63+
name: ${{ steps.vars.outputs.artifact_name }}
64+
path: ${{ steps.vars.outputs.artifact_name }}.html

0 commit comments

Comments
 (0)