Skip to content

Commit c24dfbe

Browse files
authored
Create Generate-Sbom.yml
1 parent 54864ba commit c24dfbe

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Generates and uploads SBOMs for a specific EPPlus version without running the full build pipeline.
2+
# Useful for backfilling SBOMs for older releases.
3+
# Triggered manually via workflow_dispatch with a version input.
4+
5+
name: Generate SBOM
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'EPPlus version to generate SBOMs for (e.g. 8.4.1)'
12+
required: true
13+
type: string
14+
15+
jobs:
16+
sbom:
17+
runs-on: windows-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
# Check out the release branch so that the csproj reflects the correct
22+
# version and dependencies for the requested version
23+
ref: release/epplus${{ github.event.inputs.version }}
24+
25+
- name: Fetch sbom-metadata-template.xml from develop8
26+
run: |
27+
git fetch origin develop8
28+
git checkout origin/develop8 -- src/EPPlus/sbom-metadata-template.xml
29+
shell: pwsh
30+
31+
- name: Setup .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: |
35+
9.0.x
36+
10.0.x
37+
38+
- name: Read target frameworks from csproj
39+
run: |
40+
$xml = [xml](Get-Content ./src/EPPlus/EPPlus.csproj)
41+
$tfms = $xml.Project.PropertyGroup.TargetFrameworks | Where-Object { $_ } | Select-Object -First 1
42+
echo "VERSION=${{ github.event.inputs.version }}" >> $env:GITHUB_ENV
43+
echo "TFMS=$tfms" >> $env:GITHUB_ENV
44+
shell: pwsh
45+
46+
- name: Restore dependencies
47+
run: dotnet restore ./src/EPPlus.sln
48+
49+
- name: Install CycloneDX
50+
run: dotnet tool install --global CycloneDX
51+
52+
- name: Generate combined SBOM
53+
run: dotnet CycloneDX ./src/EPPlus/EPPlus.csproj -o ./sbom -F Json -st Library -sv ${{ env.VERSION }} -fn epplus-${{ env.VERSION }}.sbom.json -imp ./src/EPPlus/sbom-metadata-template.xml
54+
55+
- name: Generate per-TFM SBOMs
56+
run: |
57+
$tfms = "${{ env.TFMS }}" -split ";"
58+
foreach ($tfm in $tfms) {
59+
$tfm = $tfm.Trim()
60+
if ([string]::IsNullOrEmpty($tfm)) { continue }
61+
Write-Host "Generating SBOM for $tfm"
62+
dotnet CycloneDX ./src/EPPlus/EPPlus.csproj -o ./sbom -F Json -st Library -sv ${{ env.VERSION }} -fn "epplus-${{ env.VERSION }}.$tfm.sbom.json" -imp ./src/EPPlus/sbom-metadata-template.xml --framework $tfm
63+
}
64+
shell: pwsh
65+
66+
- name: Generate SHA-256 checksums for all SBOMs
67+
run: |
68+
Get-ChildItem -Path "./sbom" -Filter "*.sbom.json" | ForEach-Object {
69+
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower()
70+
"$hash $($_.Name)" | Out-File -FilePath "$($_.FullName).sha256" -Encoding utf8NoBOM
71+
Write-Host "Checksum generated for $($_.Name): $hash"
72+
}
73+
shell: pwsh
74+
75+
- name: Authenticate to Azure
76+
uses: Azure/login@v2
77+
with:
78+
creds: '{"clientId":"${{ secrets.EPPLUS_CODE_SIGNING_APPLICATION_ID }}","clientSecret":"${{ secrets.EPPLUS_CODE_SIGNING_SECRET }}","subscriptionId":"${{ secrets.EPPLUS_CODE_SIGNING_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.EPPLUS_CODE_SIGNING_TENENT_ID }}"}'
79+
80+
- name: Upload all SBOMs to Azure Blob Storage
81+
run: |
82+
Get-ChildItem -Path "./sbom" | ForEach-Object {
83+
Write-Host "Uploading $($_.Name)"
84+
az storage blob upload `
85+
--account-name eppluswebprod `
86+
--container-name sbom `
87+
--name $_.Name `
88+
--file $_.FullName `
89+
--auth-mode login `
90+
--overwrite
91+
}
92+
shell: pwsh
93+
94+
- name: Upload all SBOMs as artifact
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: sbom-${{ github.event.inputs.version }}
98+
path: ./sbom/

0 commit comments

Comments
 (0)