2019-06-04 12:12:11 +00:00
|
|
|
Param(
|
|
|
|
[string] $GuardianCliLocation,
|
|
|
|
[string] $Repository,
|
2019-11-22 13:41:58 +00:00
|
|
|
[string] $BranchName='master',
|
2019-06-04 12:12:11 +00:00
|
|
|
[string] $WorkingDirectory,
|
2019-06-20 12:30:36 +00:00
|
|
|
[string] $AzureDevOpsAccessToken,
|
2019-11-22 13:41:58 +00:00
|
|
|
[string] $GuardianLoggerLevel='Standard'
|
2019-06-04 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2019-06-04 12:12:11 +00:00
|
|
|
Set-StrictMode -Version 2.0
|
2019-11-22 13:41:58 +00:00
|
|
|
$disableConfigureToolsetImport = $true
|
2021-06-12 12:58:31 +00:00
|
|
|
$global:LASTEXITCODE = 0
|
2019-06-04 12:12:11 +00:00
|
|
|
|
2020-03-31 13:04:58 +00:00
|
|
|
# `tools.ps1` checks $ci to perform some actions. Since the SDL
|
|
|
|
# scripts don't necessarily execute in the same agent that run the
|
|
|
|
# build.ps1/sh script this variable isn't automatically set.
|
|
|
|
$ci = $true
|
2019-11-22 13:41:58 +00:00
|
|
|
. $PSScriptRoot\..\tools.ps1
|
|
|
|
|
2019-08-28 12:37:30 +00:00
|
|
|
# Don't display the console progress UI - it's a huge perf hit
|
|
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
|
2019-06-04 12:12:11 +00:00
|
|
|
# Construct basic auth from AzDO access token; construct URI to the repository's gdn folder stored in that repository; construct location of zip file
|
2019-06-20 12:30:36 +00:00
|
|
|
$encodedPat = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$AzureDevOpsAccessToken"))
|
2019-06-04 12:12:11 +00:00
|
|
|
$escapedRepository = [Uri]::EscapeDataString("/$Repository/$BranchName/.gdn")
|
2020-04-28 13:18:29 +00:00
|
|
|
$uri = "https://dev.azure.com/dnceng/internal/_apis/git/repositories/sdl-tool-cfg/Items?path=$escapedRepository&versionDescriptor[versionOptions]=0&`$format=zip&api-version=5.0"
|
2019-06-04 12:12:11 +00:00
|
|
|
$zipFile = "$WorkingDirectory/gdn.zip"
|
|
|
|
|
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
2019-11-22 13:41:58 +00:00
|
|
|
$gdnFolder = (Join-Path $WorkingDirectory '.gdn')
|
2021-01-30 13:54:28 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
try {
|
2019-06-04 12:12:11 +00:00
|
|
|
# if the folder does not exist, we'll do a guardian init and push it to the remote repository
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Initializing Guardian...'
|
2019-06-04 12:12:11 +00:00
|
|
|
Write-Host "$GuardianCliLocation init --working-directory $WorkingDirectory --logger-level $GuardianLoggerLevel"
|
|
|
|
& $GuardianCliLocation init --working-directory $WorkingDirectory --logger-level $GuardianLoggerLevel
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Build' -Message "Guardian init failed with exit code $LASTEXITCODE."
|
|
|
|
ExitWithExitCode $LASTEXITCODE
|
2019-06-04 12:12:11 +00:00
|
|
|
}
|
|
|
|
# We create the mainbaseline so it can be edited later
|
|
|
|
Write-Host "$GuardianCliLocation baseline --working-directory $WorkingDirectory --name mainbaseline"
|
|
|
|
& $GuardianCliLocation baseline --working-directory $WorkingDirectory --name mainbaseline
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Build' -Message "Guardian baseline failed with exit code $LASTEXITCODE."
|
|
|
|
ExitWithExitCode $LASTEXITCODE
|
2019-06-04 12:12:11 +00:00
|
|
|
}
|
2019-11-22 13:41:58 +00:00
|
|
|
ExitWithExitCode 0
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-Host $_.ScriptStackTrace
|
2020-03-31 13:04:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
|
2019-11-22 13:41:58 +00:00
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|