Skip to content

Commit 7302039

Browse files
Port SBOM generation to v3.x/ps6 (#726)
* 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 image name (#718) * Generate SBOM only for release builds * Publish the test results * Copy package to ArtifactStagingDirectory * Simplify logic to upload the nuget package for integration testing * Install .Net 3.1 which is required by the Microsoft.ManifestTool.dll tool for release builds * Update AspNetVNext value from https://dotnet.myget.org/ to https://www.myget.org/ * Fix CosmosDB E2E test * Obtain the branch name from BuildSourceBranch (#728) * Update task condition boolean values to include single quotes (#731) * Update task condition boolean value to include single quotes
1 parent f24b5f2 commit 7302039

File tree

4 files changed

+106
-36
lines changed

4 files changed

+106
-36
lines changed

NuGet.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<add key="azure_app_service" value="https://www.myget.org/F/azure-appservice/api/v2" />
66
<add key="azure_app_service_staging" value="https://www.myget.org/F/azure-appservice-staging/api/v2" />
77
<add key="buildTools" value="https://www.myget.org/F/30de4ee06dd54956a82013fa17a3accb/" />
8-
<add key="AspNetVNext" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
8+
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcore-dev/api/v3/index.json" />
99
</packageSources>
1010
</configuration>

azure-pipelines.yml

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,50 @@
88
#- dev
99

1010
pool:
11-
vmImage: 'vs2017-win2016'
11+
name: '1ES-Hosted-AzFunc'
12+
vmImage: 'MMS2019TLS'
1213

1314
variables:
1415
Configuration: Release
1516
buildNumber: $[ counter('build', 400) ] # Start higher than our AppVeyor versions. Every build (pr or branch) will increment.
1617

1718
steps:
19+
- pwsh: |
20+
$releaseBranches = @('v4.x/ps7.2', 'v4.x/ps7.0', 'v3.x/ps7', 'v3.x/ps6', 'v2.x')
21+
22+
Write-Host "BuildSourceBranch: $($env:BuildSourceBranch)"
23+
$branchName = $env:BuildSourceBranch.Replace("refs/heads/", "")
24+
Write-Host "BranchName: $branchName"
25+
26+
$isReleaseBuild = ($releaseBranches -contains $branchName)
27+
Write-Host "##vso[task.setvariable variable=IsReleaseBuild]$isReleaseBuild"
28+
Write-Host "IsReleaseBuild: $isReleaseBuild"
29+
displayName: 'Set IsReleaseBuild variable'
30+
env:
31+
BuildSourceBranch: $(Build.SourceBranch)
32+
33+
- pwsh: |
34+
Invoke-WebRequest 'https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1' -OutFile 'dotnet-install.ps1'
35+
./dotnet-install.ps1 -InstallDir "$env:ProgramFiles/dotnet" -Version "3.1.415" -Channel 'release'
36+
displayName: 'Install .Net 3.1 which is required by the Microsoft.ManifestTool.dll tool'
37+
condition: eq(variables['IsReleaseBuild'], 'true')
38+
1839
- pwsh: ./build.ps1 -NoBuild -Bootstrap
1940
displayName: 'Running ./build.ps1 -NoBuild -Bootstrap'
2041

2142
- pwsh: |
2243
$ErrorActionPreference = "Stop"
23-
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
44+
if ($isReleaseBuild)
45+
{
46+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)" -AddSBOM -SBOMUtilSASUrl $env:SBOMUtilSASUrl
47+
}
48+
else
49+
{
50+
./build.ps1 -Clean -Configuration Release -BuildNumber "$(buildNumber)"
51+
}
2452
displayName: 'Build worker code'
53+
env:
54+
SBOMUtilSASUrl: $(SBOMUtilSASUrl)
2555

2656
- pwsh: ./build.ps1 -NoBuild -Test
2757
displayName: 'Running UnitTest'
@@ -36,41 +66,23 @@ steps:
3666
PSWorkerEnableExperimentalDurableFunctions: "true"
3767
displayName: 'Running E2ETest'
3868

39-
- task: CopyFiles@2
69+
- task: PublishTestResults@2
4070
inputs:
41-
SourceFolder: '$(System.DefaultWorkingDirectory)/testResults'
42-
Contents: '*.trx'
43-
TargetFolder: '$(Build.ArtifactStagingDirectory)'
44-
displayName: 'Copying test result file for artifacts'
71+
testResultsFormat: 'VSTest'
72+
testResultsFiles: '**/*.trx'
73+
failTaskOnFailedTests: true
74+
condition: succeededOrFailed()
75+
displayName: 'Publish tests results'
4576

46-
- task: PublishBuildArtifacts@1
77+
- task: CopyFiles@2
4778
inputs:
48-
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
49-
ArtifactName: 'drop'
50-
publishLocation: 'Container'
51-
displayName: 'Publishing build and test result artifacts'
79+
SourceFolder: '$(System.DefaultWorkingDirectory)/package'
80+
Contents: '**/*.nupkg'
81+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
82+
displayName: 'Copy package to artifacts directory'
5283

53-
- pwsh: |
54-
$sourcePath = (ls package/**/*/Microsoft.Azure.Functions.PowerShellWorker*.nupkg).FullName
55-
if (-not (test-path $sourcePath))
56-
{
57-
throw 'Unable to find Microsoft.Azure.Functions.PowerShellWorker*.nupkg at ./package'
58-
}
59-
Copy-Item -Path $sourcePath -Destination $(Build.ArtifactStagingDirectory) -ErrorAction Stop -Verbose -Force
60-
displayName: 'Copy package to ArtifactStagingDirectory'
61-
62-
- pwsh: |
63-
$uploadPackage = $null
64-
if (-not ([bool]::TryParse($env:UPLOADPACKAGETOPRERELEASEFEED, [ref] $uploadPackage)))
65-
{
66-
throw "UploadPackageToPreReleaseFeed can only be set to True or False. Current value is set to $env:UPLOADPACKAGETOPRERELEASEFEED"
67-
}
68-
Write-Host "##vso[task.setvariable variable=UploadPackage]$uploadPackage"
69-
Write-Host "UploadPackage: $uploadPackage"
70-
displayName: 'Set UploadPackage variable'
71-
7284
- task: NuGetCommand@2
73-
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'))
7486
inputs:
7587
command: 'push'
7688
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
@@ -80,7 +92,7 @@ steps:
8092
displayName: 'Push NuGet package'
8193

8294
- task: NuGetCommand@2
83-
condition: eq(variables.UploadPackage, true)
95+
condition: eq(variables['UPLOADPACKAGETOPRERELEASEFEED'], 'true')
8496
inputs:
8597
command: 'push'
8698
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'

build.ps1

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
3065
Import-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

test/E2E/Azure.Functions.PowerShellWorker.E2E/Azure.Functions.PowerShellWorker.E2E/Helpers/CosmosDBHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ await Utilities.RetryAsync(async () =>
5757
retrievedDocument = await _docDbClient.ReadDocumentAsync(docUri);
5858
return true;
5959
}
60-
catch (DocumentClientException ex) when (ex.Error.Code == "NotFound")
60+
catch (DocumentClientException ex) when (ex.Error.Code == "NotFound" || ex.Error.Code == "Not Found")
6161
{
6262
return false;
6363
}

0 commit comments

Comments
 (0)