@@ -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+
3065Import-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