Skip to content

Commit bce3a1b

Browse files
Port SBOM generation to v3.x/ps7 (#725)
* Add SBOM generation as part of the build process (#716) * Add SBOM task to generate manifest * Update pipeline to generate manifest * Update VM pool and images name (#718) * Generate SBOM only for release builds (#720) * Generate SBOM only for release builds * Simplify the logic to determine if this is a release build * Simplify logic to upload the nuget package for integration testing * Obtain the branch name from BuildSourceBranch (#728) * Update task condition boolean values to include single quotes (#731)
1 parent def9765 commit bce3a1b

File tree

3 files changed

+90
-18
lines changed

3 files changed

+90
-18
lines changed

azure-pipelines.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,49 @@
1010
strategy:
1111
matrix:
1212
linux:
13-
imageName: 'ubuntu-latest'
13+
imageName: 'MMSUbuntu20.04TLS'
1414
windows:
15-
imageName: 'vs2017-win2016'
15+
imageName: 'MMS2019TLS'
1616

1717
pool:
18+
name: '1ES-Hosted-AzFunc'
1819
vmImage: $(imageName)
1920

2021
variables:
2122
Configuration: Release
2223
buildNumber: $[ counter('build', 400) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment.
2324

2425
steps:
26+
- pwsh: |
27+
$releaseBranches = @('v4.x/ps7.2', 'v4.x/ps7.0', 'v3.x/ps7', 'v3.x/ps6', 'v2.x')
28+
29+
Write-Host "BuildSourceBranch: $($env:BuildSourceBranch)"
30+
$branchName = $env:BuildSourceBranch.Replace("refs/heads/", "")
31+
Write-Host "BranchName: $branchName"
32+
33+
$isReleaseBuild = ($releaseBranches -contains $branchName)
34+
Write-Host "##vso[task.setvariable variable=IsReleaseBuild]$isReleaseBuild"
35+
Write-Host "IsReleaseBuild: $isReleaseBuild"
36+
displayName: 'Set IsReleaseBuild variable'
37+
env:
38+
BuildSourceBranch: $(Build.SourceBranch)
39+
2540
- pwsh: ./build.ps1 -NoBuild -Bootstrap
2641
displayName: 'Running ./build.ps1 -NoBuild -Bootstrap'
2742

2843
- pwsh: |
2944
$ErrorActionPreference = "Stop"
30-
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
45+
if ($isReleaseBuild)
46+
{
47+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM -SBOMUtilSASUrl $env:SBOMUtilSASUrl
48+
}
49+
else
50+
{
51+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
52+
}
3153
displayName: 'Build worker code'
54+
env:
55+
SBOMUtilSASUrl: $(SBOMUtilSASUrl)
3256

3357
- pwsh: ./build.ps1 -NoBuild -Test
3458
displayName: 'Running UnitTest'
@@ -57,18 +81,8 @@ steps:
5781
TargetFolder: '$(Build.ArtifactStagingDirectory)'
5882
displayName: 'Copy package to artifacts directory'
5983

60-
- pwsh: |
61-
$uploadPackage = $null
62-
if (-not ([bool]::TryParse($env:UPLOADPACKAGETOPRERELEASEFEED, [ref] $uploadPackage)))
63-
{
64-
throw "UploadPackageToPreReleaseFeed can only be set to True or False. Current value is set to $env:UPLOADPACKAGETOPRERELEASEFEED"
65-
}
66-
Write-Host "##vso[task.setvariable variable=UploadPackage]$uploadPackage"
67-
Write-Host "UploadPackage: $uploadPackage"
68-
displayName: 'Set UploadPackage variable'
69-
7084
- task: NuGetCommand@2
71-
condition: and(ne(variables['Build.Reason'], 'PullRequest'), in(variables['Build.SourceBranch'], 'refs/heads/v3.x/ps7', 'refs/heads/v3.x/ps6', 'refs/heads/v2.x'), eq(variables.UploadPackage, false))
85+
condition: and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['IsReleaseBuild'], 'true'), eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'false'))
7286
inputs:
7387
command: 'push'
7488
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
@@ -78,7 +92,7 @@ steps:
7892
displayName: 'Push NuGet package'
7993

8094
- task: NuGetCommand@2
81-
condition: eq(variables.UploadPackage, true)
95+
condition: eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'true')
8296
inputs:
8397
command: 'push'
8498
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'

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)