Skip to content

Commit 55e2496

Browse files
Add SBOM task to generate manifest
1 parent 9e59d63 commit 55e2496

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

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 = (Get-item "$MANIFESTOOL_DIRECTORY/$dllName").FullName
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
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

0 commit comments

Comments
 (0)