Skip to content

Commit c89eeb0

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 def9765 commit c89eeb0

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

azure-pipelines.yml

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

2828
- pwsh: |
2929
$ErrorActionPreference = "Stop"
30-
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
30+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM -SBOMUtilSASUrl $env:SBOMUtilSASUrl
3131
displayName: 'Build worker code'
32+
env:
33+
SBOMUtilSASUrl: $(SBOMUtilSASUrl)
3234

3335
- pwsh: ./build.ps1 -NoBuild -Test
3436
displayName: 'Running UnitTest'

build.ps1

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ param(
2828
$Configuration = "Debug",
2929

3030
[string]
31-
$BuildNumber = '0'
31+
$BuildNumber = '0',
32+
33+
[switch]
34+
$AddSBOM,
35+
36+
[string]
37+
$SBOMUtilSASUrl
3238
)
3339

3440
#Requires -Version 6.0
@@ -62,6 +68,35 @@ function Get-FunctionsCoreToolsDir {
6268
}
6369
}
6470

71+
function Install-SBOMUtil
72+
{
73+
if ([string]::IsNullOrEmpty($SBOMUtilSASUrl))
74+
{
75+
throw "The `$SBOMUtilSASUrl parameter cannot be null or empty when specifying the `$AddSBOM switch"
76+
}
77+
78+
$MANIFESTOOLNAME = "ManifestTool"
79+
Write-Host "Installing $MANIFESTOOLNAME..."
80+
81+
$MANIFESTOOL_DIRECTORY = Join-Path $PSScriptRoot $MANIFESTOOLNAME
82+
Remove-Item -Recurse -Force $MANIFESTOOL_DIRECTORY -ErrorAction Ignore
83+
84+
Invoke-RestMethod -Uri $SBOMUtilSASUrl -OutFile "$MANIFESTOOL_DIRECTORY.zip"
85+
Expand-Archive "$MANIFESTOOL_DIRECTORY.zip" -DestinationPath $MANIFESTOOL_DIRECTORY
86+
87+
$dllName = "Microsoft.ManifestTool.dll"
88+
$manifestToolPath = "$MANIFESTOOL_DIRECTORY/$dllName"
89+
90+
if (-not (Test-Path $manifestToolPath))
91+
{
92+
throw "$MANIFESTOOL_DIRECTORY does not contain '$dllName'"
93+
}
94+
95+
Write-Host 'Done.'
96+
97+
return $manifestToolPath
98+
}
99+
65100
function Deploy-PowerShellWorker {
66101
$ErrorActionPreference = 'Stop'
67102

@@ -140,6 +175,29 @@ if (!$NoBuild.IsPresent) {
140175
-OutFile "$PSScriptRoot/src/Modules/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1"
141176

142177
dotnet publish -c $Configuration "/p:BuildNumber=$BuildNumber" $PSScriptRoot
178+
179+
if ($AddSBOM)
180+
{
181+
# Install manifest tool
182+
$manifestTool = Install-SBOMUtil
183+
Write-Log "manifestTool: $manifestTool "
184+
185+
# Generate manifest
186+
$buildPath = "$PSScriptRoot/src/bin/$Configuration/$TargetFramework/publish"
187+
$telemetryFilePath = Join-Path $PSScriptRoot ((New-Guid).Guid + ".json")
188+
$packageName = "Microsoft.Azure.Functions.PowerShellWorker.nuspec"
189+
190+
# Delete the manifest folder if it exists
191+
$manifestFolderPath = Join-Path $buildPath "_manifest"
192+
if (Test-Path $manifestFolderPath)
193+
{
194+
Remove-Item $manifestFolderPath -Recurse -Force -ErrorAction Ignore
195+
}
196+
197+
Write-Log "Running: dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath"
198+
& { dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName }
199+
}
200+
143201
dotnet pack -c $Configuration "/p:BuildNumber=$BuildNumber" "$PSScriptRoot/package"
144202
}
145203

tools/helper.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ $RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
1111
$DotnetSDKVersionRequirements = @{
1212
# We need .NET SDK 3.1 for running the tests, as we still build against the 3.1 framework
1313
'3.1' = @{
14-
MinimalPatch = '412'
15-
DefaultPatch = '412'
14+
MinimalPatch = '415'
15+
DefaultPatch = '415'
1616
}
1717
# We need .NET SDK 5.0 for the updated C# compiler
1818
'5.0' = @{

0 commit comments

Comments
 (0)