-
Notifications
You must be signed in to change notification settings - Fork 4
Add SBOM manifest generation #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2bcf451
faa2059
18cacf6
e8fe839
04d7138
aeac99a
1a76b35
7ea6706
a709130
bb25ffa
64939b7
b563d4e
b5abd7f
cb595eb
21ee9fd
d565bef
7edc03e
7cc4519
ceee24d
432eb0b
e4ded3c
240d280
924ac3a
9708851
a26d4cb
c9fefab
11a16ac
d4fe3c8
22ce34f
dbc033d
03dc78a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,78 @@ pool: | |
demands: | ||
- ImageOverride -equals $(imageName) | ||
|
||
variables: | ||
artifactName: 'azure-functions-durable-powershell-$(Build.SourceVersion)' | ||
# Every build will increment | ||
buildNumber: $[counter('build', 001) ] | ||
modulePath: './test/E2E/durableApp/Modules/AzureFunctions.PowerShell.Durable.SDK' | ||
|
||
steps: | ||
- pwsh: ./test/E2E/Start-E2ETest.ps1 -UseCoreToolsBuildFromIntegrationTests | ||
- pwsh: | | ||
$simulateReleaseBuild = $null | ||
Write-Host "SimulateReleaseBuild set to $env:SimulateReleaseBuild" | ||
if (-not([bool]::TryParse($env:SimulateReleaseBuild, [ref] $simulateReleaseBuild))) | ||
{ | ||
throw "SimulateReleaseBuild can only be set to true or false." | ||
} | ||
|
||
$isReleaseBuild = $false | ||
if ($env:BuildSourceBranchName -like "release_*" -or $simulateReleaseBuild) | ||
{ | ||
$isReleaseBuild = $true | ||
} | ||
Write-Host "Setting IsReleaseBuild to $isReleaseBuild because SimulateReleaseBuild is $env:SimulateReleaseBuild" | ||
Write-Host "##vso[task.setvariable variable=IsReleaseBuild]$isReleaseBuild" | ||
Write-Host "IsReleaseBuild: $isReleaseBuild" | ||
displayName: Set IsReleaseBuild pipeline variable | ||
env: | ||
SimulateReleaseBuild: $(SimulateReleaseBuild) | ||
|
||
- pwsh: | | ||
Import-Module ".\pipelineUtilities.psm1" -Force | ||
Install-Dotnet | ||
displayName: 'Install .NET 3.1' | ||
|
||
- pwsh: | | ||
Write-Host "IsReleaseBuild set to $env:IsReleaseBuild" | ||
$isReleaseBuild = $false | ||
if (-not([bool]::TryParse($env:IsReleaseBuild, [ref] $isReleaseBuild))) | ||
{ | ||
throw "SimulateReleaseBuild can only be set to true or false." | ||
} | ||
michaelpeng36 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# We only generate an SBOM for release or simulated release builds | ||
Write-Host "Running ./build.ps1 -Configuration Release -AddSBOM:$isReleaseBuild..." | ||
./build.ps1 -Configuration Release -AddSBOM:$isReleaseBuild | ||
displayName: 'Build Durable SDK' | ||
env: | ||
# We include IsReleaseBuild as an environment variable since Linux agents don't seem to support including | ||
# pipeline variables in scripts with the $(variable) syntax | ||
IsReleaseBuild: $(IsReleaseBuild) | ||
SBOMUtilSASUrl: $(SBOMUtilSASUrl) | ||
|
||
- pwsh: | | ||
./test/E2E/Start-E2ETest.ps1 -NoBuild -UseCoreToolsBuildFromIntegrationTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we ever call this without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, so the |
||
env: | ||
AzureWebJobsStorage: $(AzureWebJobsStorage) | ||
displayName: 'Run E2E tests' | ||
|
||
- task: ArchiveFiles@2 | ||
inputs: | ||
rootFolderOrFile: '$(Build.SourcesDirectory)/test/E2E/durableApp/Modules/AzureFunctions.PowerShell.Durable.SDK' | ||
includeRootFolder: false | ||
archiveType: 'tar' | ||
archiveFile: '$(Build.ArtifactStagingDirectory)/$(artifactName).tar.gz' | ||
replaceExistingArchive: true | ||
displayName: 'Tar build tartifacts' | ||
|
||
- task: PublishBuildArtifacts@1 | ||
inputs: | ||
PathtoPublish: $(Build.ArtifactStagingDirectory) | ||
ArtifactName: $(artifactName).tar.gz | ||
condition: and(succeeded(), eq(variables['IsReleaseBuild'], 'true')) | ||
displayName: 'Publish build artifacts' | ||
|
||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFormat: 'VSTest' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# | ||
# Copyright (c) Microsoft. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
# | ||
|
||
using namespace System.Runtime.InteropServices | ||
|
||
$DotnetSDKVersionRequirements = @{ | ||
|
||
# .NET SDK 3.1 is required by the Microsoft.ManifestTool.dll tool | ||
'3.1' = @{ | ||
MinimalPatch = '415' | ||
DefaultPatch = '415' | ||
} | ||
} | ||
|
||
function Write-Log | ||
{ | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Message, | ||
|
||
[Switch] | ||
$Warning, | ||
|
||
[Switch] | ||
$Throw, | ||
|
||
[System.String] | ||
$Color | ||
) | ||
|
||
$Message = (Get-Date -Format G) + " -- $Message" | ||
|
||
if ($Throw) | ||
{ | ||
throw $Message | ||
} | ||
|
||
$foregroundColor = if ($Warning.IsPresent) { 'Yellow' } elseif ($Color) { $Color } else { 'Green' } | ||
Write-Host -ForegroundColor $foregroundColor $Message | ||
} | ||
|
||
function Install-SBOMUtil | ||
{ | ||
if ([string]::IsNullOrEmpty($env:SBOMUtilSASUrl)) | ||
{ | ||
throw "The `$SBOMUtilSASUrl environment variable cannot be null or empty when specifying the `$AddSBOM switch" | ||
} | ||
|
||
$MANIFESTOOLNAME = "ManifestTool" | ||
Write-Log "Installing $MANIFESTOOLNAME..." | ||
|
||
$MANIFESTOOL_DIRECTORY = Join-Path $PSScriptRoot $MANIFESTOOLNAME | ||
Remove-Item -Recurse -Force $MANIFESTOOL_DIRECTORY -ErrorAction Ignore | ||
|
||
Invoke-RestMethod -Uri $env:SBOMUtilSASUrl -OutFile "$MANIFESTOOL_DIRECTORY.zip" | ||
Expand-Archive "$MANIFESTOOL_DIRECTORY.zip" -DestinationPath $MANIFESTOOL_DIRECTORY | ||
|
||
$dllName = "Microsoft.ManifestTool.dll" | ||
$manifestToolPath = Join-Path "$MANIFESTOOL_DIRECTORY" "$dllName" | ||
|
||
if (-not (Test-Path $manifestToolPath)) | ||
{ | ||
throw "$MANIFESTOOL_DIRECTORY does not contain '$dllName'" | ||
} | ||
|
||
Write-Log 'Done.' | ||
|
||
return $manifestToolPath | ||
} | ||
|
||
|
||
function AddLocalDotnetDirPath { | ||
$LocalDotnetDirPath = if ($IsWindows) { "$env:ProgramFiles/dotnet" } else { "/usr/share/dotnet" } | ||
if (($env:PATH -split [IO.Path]::PathSeparator) -notcontains $LocalDotnetDirPath) { | ||
$env:PATH = $LocalDotnetDirPath + [IO.Path]::PathSeparator + $env:PATH | ||
} | ||
} | ||
|
||
function Find-Dotnet | ||
{ | ||
AddLocalDotnetDirPath | ||
$listSdksOutput = dotnet --list-sdks | ||
$installedDotnetSdks = $listSdksOutput | ForEach-Object { $_.Split(" ")[0] } | ||
Write-Host "Detected dotnet SDKs: $($installedDotnetSdks -join ', ')" | ||
foreach ($majorMinorVersion in $DotnetSDKVersionRequirements.Keys) { | ||
$minimalVersion = "$majorMinorVersion.$($DotnetSDKVersionRequirements[$majorMinorVersion].MinimalPatch)" | ||
$firstAcceptable = $installedDotnetSdks | | ||
Where-Object { $_.StartsWith("$majorMinorVersion.") } | | ||
Where-Object { [System.Management.Automation.SemanticVersion]::new($_) -ge [System.Management.Automation.SemanticVersion]::new($minimalVersion) } | | ||
Select-Object -First 1 | ||
if (-not $firstAcceptable) { | ||
throw "Cannot find the dotnet SDK for .NET Core $majorMinorVersion. Version $minimalVersion or higher is required. Please specify '-Bootstrap' to install build dependencies." | ||
} | ||
} | ||
} | ||
|
||
function Install-Dotnet { | ||
[CmdletBinding()] | ||
param( | ||
[string]$Channel = 'release' | ||
) | ||
try { | ||
Find-Dotnet | ||
return # Simply return if we find dotnet SDk with the correct version | ||
} catch { } | ||
$obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain" | ||
try { | ||
$installScript = if ($IsWindows) { "dotnet-install.ps1" } else { "dotnet-install.sh" } | ||
Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript | ||
foreach ($majorMinorVersion in $DotnetSDKVersionRequirements.Keys) { | ||
$version = "$majorMinorVersion.$($DotnetSDKVersionRequirements[$majorMinorVersion].DefaultPatch)" | ||
Write-Host "Installing dotnet SDK version $version" | ||
if ($IsWindows) { | ||
& .\$installScript -InstallDir "$env:ProgramFiles/dotnet" -Channel $Channel -Version $Version | ||
} else { | ||
bash ./$installScript --install-dir "/usr/share/dotnet" -c $Channel -v $Version | ||
} | ||
} | ||
AddLocalDotnetDirPath | ||
} | ||
finally { | ||
Remove-Item $installScript -Force -ErrorAction SilentlyContinue | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we're assigning
isReleaseBuild
twice? In the firstpwsh
block, we do it based on the branch name and thesimulateReleaseBuild
variable. On the lastpwsh
block, we do it based onenv:IsReleaseBuild
.What would happen is
SimulateReleaseBuild
istrue
butenv:IsReleaseBuild
werefalse
? Wouldn't forceIsReleaseBuild
tofalse
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite. The intention of
SimulateReleaseBuild
is precisely to force the pipeline to emulate behavior as ifIsReleaseBuild
were set totrue
. There should never be a case following the firstpwsh
block where theSimulateReleaseBuild
istrue
butIsReleaseBuild
isfalse
.For the second
pwsh
block, the reasonIsReleaseBuild
pipeline variable is propagated to this step as an environment variable is because Linux agents don't always respect using the$(variableName)
notation directly in thepwsh
script, and variable values are not carried over between steps in ADO by default. Instead, we set the pipeline variable in the firstpwsh
block with theWrite-Host "##vso[task.setvariable variable=IsReleaseBuild]$isReleaseBuild"
statement, and set an environment variable equal to the pipeline variable in theenv
block of the secondpwsh
block.