diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 29f028ca..c0f1488d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,8 +27,10 @@ steps: - pwsh: | $ErrorActionPreference = "Stop" - ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" + ./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM -SBOMUtilSASUrl $env:SBOMUtilSASUrl displayName: 'Build worker code' + env: + SBOMUtilSASUrl: $(SBOMUtilSASUrl) - pwsh: ./build.ps1 -NoBuild -Test displayName: 'Running UnitTest' diff --git a/build.ps1 b/build.ps1 index dad2e5e4..3596634e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -28,7 +28,13 @@ param( $Configuration = "Debug", [string] - $BuildNumber = '0' + $BuildNumber = '0', + + [switch] + $AddSBOM, + + [string] + $SBOMUtilSASUrl ) #Requires -Version 6.0 @@ -62,6 +68,35 @@ function Get-FunctionsCoreToolsDir { } } +function Install-SBOMUtil +{ + if ([string]::IsNullOrEmpty($SBOMUtilSASUrl)) + { + throw "The `$SBOMUtilSASUrl parameter cannot be null or empty when specifying the `$AddSBOM switch" + } + + $MANIFESTOOLNAME = "ManifestTool" + Write-Host "Installing $MANIFESTOOLNAME..." + + $MANIFESTOOL_DIRECTORY = Join-Path $PSScriptRoot $MANIFESTOOLNAME + Remove-Item -Recurse -Force $MANIFESTOOL_DIRECTORY -ErrorAction Ignore + + Invoke-RestMethod -Uri $SBOMUtilSASUrl -OutFile "$MANIFESTOOL_DIRECTORY.zip" + Expand-Archive "$MANIFESTOOL_DIRECTORY.zip" -DestinationPath $MANIFESTOOL_DIRECTORY + + $dllName = "Microsoft.ManifestTool.dll" + $manifestToolPath = "$MANIFESTOOL_DIRECTORY/$dllName" + + if (-not (Test-Path $manifestToolPath)) + { + throw "$MANIFESTOOL_DIRECTORY does not contain '$dllName'" + } + + Write-Host 'Done.' + + return $manifestToolPath +} + function Deploy-PowerShellWorker { $ErrorActionPreference = 'Stop' @@ -140,6 +175,29 @@ if (!$NoBuild.IsPresent) { -OutFile "$PSScriptRoot/src/Modules/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1" dotnet publish -c $Configuration "/p:BuildNumber=$BuildNumber" $PSScriptRoot + + if ($AddSBOM) + { + # Install manifest tool + $manifestTool = Install-SBOMUtil + Write-Log "manifestTool: $manifestTool " + + # Generate manifest + $buildPath = "$PSScriptRoot/src/bin/$Configuration/$TargetFramework/publish" + $telemetryFilePath = Join-Path $PSScriptRoot ((New-Guid).Guid + ".json") + $packageName = "Microsoft.Azure.Functions.PowerShellWorker.nuspec" + + # Delete the manifest folder if it exists + $manifestFolderPath = Join-Path $buildPath "_manifest" + if (Test-Path $manifestFolderPath) + { + Remove-Item $manifestFolderPath -Recurse -Force -ErrorAction Ignore + } + + Write-Log "Running: dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath" + & { dotnet $manifestTool generate -BuildDropPath $buildPath -BuildComponentPath $buildPath -Verbosity Information -t $telemetryFilePath -PackageName $packageName } + } + dotnet pack -c $Configuration "/p:BuildNumber=$BuildNumber" "$PSScriptRoot/package" } diff --git a/tools/helper.psm1 b/tools/helper.psm1 index a5ee7161..8a402367 100644 --- a/tools/helper.psm1 +++ b/tools/helper.psm1 @@ -9,6 +9,13 @@ $IsWindowsEnv = [RuntimeInformation]::IsOSPlatform([OSPlatform]::Windows) $RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path $DotnetSDKVersionRequirements = @{ + + # .NET SDK 3.1 is required by the Microsoft.ManifestTool.dll tool + '3.1' = @{ + MinimalPatch = '415' + DefaultPatch = '415' + } + '6.0' = @{ MinimalPatch = '100' DefaultPatch = '100'