Skip to content

Commit 33d2224

Browse files
Add SBOM generation as part of the build process (#716)
* Add SBOM task to generate manifest * Update pipeline to generate manifest
1 parent f24b5f2 commit 33d2224

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ steps:
2020

2121
- pwsh: |
2222
$ErrorActionPreference = "Stop"
23-
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
23+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM -SBOMUtilSASUrl $env:SBOMUtilSASUrl
2424
displayName: 'Build worker code'
25+
env:
26+
SBOMUtilSASUrl: $(SBOMUtilSASUrl)
2527

2628
- pwsh: ./build.ps1 -NoBuild -Test
2729
displayName: 'Running UnitTest'

build.ps1

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,46 @@ param(
2222
$Configuration = "Debug",
2323

2424
[string]
25-
$BuildNumber = '0'
25+
$BuildNumber = '0',
26+
27+
[switch]
28+
$AddSBOM,
29+
30+
[string]
31+
$SBOMUtilSASUrl
2632
)
2733

2834
#Requires -Version 6.0
2935

36+
function Install-SBOMUtil
37+
{
38+
if ([string]::IsNullOrEmpty($SBOMUtilSASUrl))
39+
{
40+
throw "The `$SBOMUtilSASUrl parameter cannot be null or empty when specifying the `$AddSBOM switch"
41+
}
42+
43+
$MANIFESTOOLNAME = "ManifestTool"
44+
Write-Host "Installing $MANIFESTOOLNAME..."
45+
46+
$MANIFESTOOL_DIRECTORY = Join-Path $PSScriptRoot $MANIFESTOOLNAME
47+
Remove-Item -Recurse -Force $MANIFESTOOL_DIRECTORY -ErrorAction Ignore
48+
49+
Invoke-RestMethod -Uri $SBOMUtilSASUrl -OutFile "$MANIFESTOOL_DIRECTORY.zip"
50+
Expand-Archive "$MANIFESTOOL_DIRECTORY.zip" -DestinationPath $MANIFESTOOL_DIRECTORY
51+
52+
$dllName = "Microsoft.ManifestTool.dll"
53+
$manifestToolPath = "$MANIFESTOOL_DIRECTORY/$dllName"
54+
55+
if (-not (Test-Path $manifestToolPath))
56+
{
57+
throw "$MANIFESTOOL_DIRECTORY does not contain '$dllName'"
58+
}
59+
60+
Write-Host 'Done.'
61+
62+
return $manifestToolPath
63+
}
64+
3065
Import-Module "$PSScriptRoot/tools/helper.psm1" -Force
3166

3267
# Bootstrap step
@@ -87,6 +122,29 @@ if(!$NoBuild.IsPresent) {
87122
-OutFile "$PSScriptRoot/src/Modules/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1"
88123

89124
dotnet publish -c $Configuration "/p:BuildNumber=$BuildNumber" $PSScriptRoot
125+
126+
if ($AddSBOM)
127+
{
128+
# Install manifest tool
129+
$manifestTool = Install-SBOMUtil
130+
Write-Log "manifestTool: $manifestTool "
131+
132+
# Generate manifest
133+
$buildPath = "$PSScriptRoot/src/bin/$Configuration/$TargetFramework/publish"
134+
$telemetryFilePath = Join-Path $PSScriptRoot ((New-Guid).Guid + ".json")
135+
$packageName = "Microsoft.Azure.Functions.PowerShellWorker.nuspec"
136+
137+
# Delete the manifest folder if it exists
138+
$manifestFolderPath = Join-Path $buildPath "_manifest"
139+
if (Test-Path $manifestFolderPath)
140+
{
141+
Remove-Item $manifestFolderPath -Recurse -Force -ErrorAction Ignore
142+
}
143+
144+
Write-Log "Running: dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath"
145+
& { dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName }
146+
}
147+
90148
dotnet pack -c $Configuration "/p:BuildNumber=$BuildNumber" "$PSScriptRoot/package"
91149
}
92150

0 commit comments

Comments
 (0)