Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit d009a21

Browse files
Merged PR 21410: merge release/3.1.4xx into internal/release/3.1.4xx
merge release/3.1.4xx into internal/release/3.1.4xx
2 parents aba2d37 + fe7e5c7 commit d009a21

14 files changed

+565
-248
lines changed

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
</Dependency>
4343
</ProductDependencies>
4444
<ToolsetDependencies>
45-
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.21552.6">
45+
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.22077.9">
4646
<Uri>https://github.com/dotnet/arcade</Uri>
47-
<Sha>afb79612f8e0b62603d9c1a614d7e4cf3f54a1e7</Sha>
47+
<Sha>31e3d884010345c19f6335571e34b2b5c7ce13bc</Sha>
4848
</Dependency>
4949
</ToolsetDependencies>
5050
<ProductDependencies>

eng/common/pipeline-logging-functions.ps1

Lines changed: 88 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
1212
# TODO: BUG: Escape % ???
1313
# TODO: Add test to verify don't need to escape "=".
1414

15+
# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
1516
function Write-PipelineTelemetryError {
1617
[CmdletBinding()]
1718
param(
@@ -25,80 +26,101 @@ function Write-PipelineTelemetryError {
2526
[string]$SourcePath,
2627
[string]$LineNumber,
2728
[string]$ColumnNumber,
28-
[switch]$AsOutput)
29+
[switch]$AsOutput,
30+
[switch]$Force)
2931

30-
$PSBoundParameters.Remove("Category") | Out-Null
32+
$PSBoundParameters.Remove('Category') | Out-Null
3133

34+
if ($Force -Or ((Test-Path variable:ci) -And $ci)) {
3235
$Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message"
33-
$PSBoundParameters.Remove("Message") | Out-Null
34-
$PSBoundParameters.Add("Message", $Message)
35-
36-
Write-PipelineTaskError @PSBoundParameters
36+
}
37+
$PSBoundParameters.Remove('Message') | Out-Null
38+
$PSBoundParameters.Add('Message', $Message)
39+
Write-PipelineTaskError @PSBoundParameters
3740
}
3841

42+
# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
3943
function Write-PipelineTaskError {
4044
[CmdletBinding()]
4145
param(
42-
[Parameter(Mandatory = $true)]
43-
[string]$Message,
44-
[Parameter(Mandatory = $false)]
45-
[string]$Type = 'error',
46-
[string]$ErrCode,
47-
[string]$SourcePath,
48-
[string]$LineNumber,
49-
[string]$ColumnNumber,
50-
[switch]$AsOutput)
51-
52-
if(!$ci) {
53-
if($Type -eq 'error') {
54-
Write-Host $Message -ForegroundColor Red
55-
return
46+
[Parameter(Mandatory = $true)]
47+
[string]$Message,
48+
[Parameter(Mandatory = $false)]
49+
[string]$Type = 'error',
50+
[string]$ErrCode,
51+
[string]$SourcePath,
52+
[string]$LineNumber,
53+
[string]$ColumnNumber,
54+
[switch]$AsOutput,
55+
[switch]$Force
56+
)
57+
58+
if (!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) {
59+
if ($Type -eq 'error') {
60+
Write-Host $Message -ForegroundColor Red
61+
return
5662
}
5763
elseif ($Type -eq 'warning') {
58-
Write-Host $Message -ForegroundColor Yellow
59-
return
64+
Write-Host $Message -ForegroundColor Yellow
65+
return
6066
}
61-
}
62-
63-
if(($Type -ne 'error') -and ($Type -ne 'warning')) {
67+
}
68+
69+
if (($Type -ne 'error') -and ($Type -ne 'warning')) {
6470
Write-Host $Message
6571
return
66-
}
67-
if(-not $PSBoundParameters.ContainsKey('Type')) {
72+
}
73+
$PSBoundParameters.Remove('Force') | Out-Null
74+
if (-not $PSBoundParameters.ContainsKey('Type')) {
6875
$PSBoundParameters.Add('Type', 'error')
69-
}
70-
Write-LogIssue @PSBoundParameters
71-
}
76+
}
77+
Write-LogIssue @PSBoundParameters
78+
}
7279

73-
function Write-PipelineSetVariable {
80+
function Write-PipelineSetVariable {
7481
[CmdletBinding()]
7582
param(
76-
[Parameter(Mandatory = $true)]
77-
[string]$Name,
78-
[string]$Value,
79-
[switch]$Secret,
80-
[switch]$AsOutput,
81-
[bool]$IsMultiJobVariable=$true)
82-
83-
if($ci) {
83+
[Parameter(Mandatory = $true)]
84+
[string]$Name,
85+
[string]$Value,
86+
[switch]$Secret,
87+
[switch]$AsOutput,
88+
[bool]$IsMultiJobVariable = $true)
89+
90+
if ((Test-Path variable:ci) -And $ci) {
8491
Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $Value -Properties @{
85-
'variable' = $Name
86-
'isSecret' = $Secret
87-
'isOutput' = $IsMultiJobVariable
92+
'variable' = $Name
93+
'isSecret' = $Secret
94+
'isOutput' = $IsMultiJobVariable
8895
} -AsOutput:$AsOutput
89-
}
90-
}
96+
}
97+
}
9198

92-
function Write-PipelinePrependPath {
99+
function Write-PipelinePrependPath {
93100
[CmdletBinding()]
94101
param(
95-
[Parameter(Mandatory=$true)]
96-
[string]$Path,
97-
[switch]$AsOutput)
98-
if($ci) {
102+
[Parameter(Mandatory = $true)]
103+
[string]$Path,
104+
[switch]$AsOutput)
105+
106+
if ((Test-Path variable:ci) -And $ci) {
99107
Write-LoggingCommand -Area 'task' -Event 'prependpath' -Data $Path -AsOutput:$AsOutput
100-
}
101-
}
108+
}
109+
}
110+
111+
function Write-PipelineSetResult {
112+
[CmdletBinding()]
113+
param(
114+
[ValidateSet("Succeeded", "SucceededWithIssues", "Failed", "Cancelled", "Skipped")]
115+
[Parameter(Mandatory = $true)]
116+
[string]$Result,
117+
[string]$Message)
118+
if ((Test-Path variable:ci) -And $ci) {
119+
Write-LoggingCommand -Area 'task' -Event 'complete' -Data $Message -Properties @{
120+
'result' = $Result
121+
}
122+
}
123+
}
102124

103125
<########################################
104126
# Private functions.
@@ -115,7 +137,8 @@ function Format-LoggingCommandData {
115137
foreach ($mapping in $script:loggingCommandEscapeMappings) {
116138
$Value = $Value.Replace($mapping.Token, $mapping.Replacement)
117139
}
118-
} else {
140+
}
141+
else {
119142
for ($i = $script:loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i--) {
120143
$mapping = $script:loggingCommandEscapeMappings[$i]
121144
$Value = $Value.Replace($mapping.Replacement, $mapping.Token)
@@ -148,7 +171,8 @@ function Format-LoggingCommand {
148171
if ($first) {
149172
$null = $sb.Append(' ')
150173
$first = $false
151-
} else {
174+
}
175+
else {
152176
$null = $sb.Append(';')
153177
}
154178

@@ -185,7 +209,8 @@ function Write-LoggingCommand {
185209
$command = Format-LoggingCommand -Area $Area -Event $Event -Data $Data -Properties $Properties
186210
if ($AsOutput) {
187211
$command
188-
} else {
212+
}
213+
else {
189214
Write-Host $command
190215
}
191216
}
@@ -204,12 +229,12 @@ function Write-LogIssue {
204229
[switch]$AsOutput)
205230

206231
$command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{
207-
'type' = $Type
208-
'code' = $ErrCode
209-
'sourcepath' = $SourcePath
210-
'linenumber' = $LineNumber
211-
'columnnumber' = $ColumnNumber
212-
}
232+
'type' = $Type
233+
'code' = $ErrCode
234+
'sourcepath' = $SourcePath
235+
'linenumber' = $LineNumber
236+
'columnnumber' = $ColumnNumber
237+
}
213238
if ($AsOutput) {
214239
return $command
215240
}
@@ -221,7 +246,8 @@ function Write-LogIssue {
221246
$foregroundColor = [System.ConsoleColor]::Red
222247
$backgroundColor = [System.ConsoleColor]::Black
223248
}
224-
} else {
249+
}
250+
else {
225251
$foregroundColor = $host.PrivateData.WarningForegroundColor
226252
$backgroundColor = $host.PrivateData.WarningBackgroundColor
227253
if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) {
@@ -231,4 +257,4 @@ function Write-LogIssue {
231257
}
232258

233259
Write-Host $command -ForegroundColor $foregroundColor -BackgroundColor $backgroundColor
234-
}
260+
}

eng/common/sdl/configure-sdl-tool.ps1

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Param(
2+
[string] $GuardianCliLocation,
3+
[string] $WorkingDirectory,
4+
[string] $TargetDirectory,
5+
[string] $GdnFolder,
6+
# The list of Guardian tools to configure. For each object in the array:
7+
# - If the item is a [hashtable], it must contain these entries:
8+
# - Name = The tool name as Guardian knows it.
9+
# - Scenario = (Optional) Scenario-specific name for this configuration entry. It must be unique
10+
# among all tool entries with the same Name.
11+
# - Args = (Optional) Array of Guardian tool configuration args, like '@("Target > C:\temp")'
12+
# - If the item is a [string] $v, it is treated as '@{ Name="$v" }'
13+
[object[]] $ToolsList,
14+
[string] $GuardianLoggerLevel='Standard',
15+
# Optional: Additional params to add to any tool using CredScan.
16+
[string[]] $CrScanAdditionalRunConfigParams,
17+
# Optional: Additional params to add to any tool using PoliCheck.
18+
[string[]] $PoliCheckAdditionalRunConfigParams
19+
)
20+
21+
$ErrorActionPreference = 'Stop'
22+
Set-StrictMode -Version 2.0
23+
$disableConfigureToolsetImport = $true
24+
$global:LASTEXITCODE = 0
25+
26+
try {
27+
# `tools.ps1` checks $ci to perform some actions. Since the SDL
28+
# scripts don't necessarily execute in the same agent that run the
29+
# build.ps1/sh script this variable isn't automatically set.
30+
$ci = $true
31+
. $PSScriptRoot\..\tools.ps1
32+
33+
# Normalize tools list: all in [hashtable] form with defined values for each key.
34+
$ToolsList = $ToolsList |
35+
ForEach-Object {
36+
if ($_ -is [string]) {
37+
$_ = @{ Name = $_ }
38+
}
39+
40+
if (-not ($_['Scenario'])) { $_.Scenario = "" }
41+
if (-not ($_['Args'])) { $_.Args = @() }
42+
$_
43+
}
44+
45+
Write-Host "List of tools to configure:"
46+
$ToolsList | ForEach-Object { $_ | Out-String | Write-Host }
47+
48+
# We store config files in the r directory of .gdn
49+
$gdnConfigPath = Join-Path $GdnFolder 'r'
50+
$ValidPath = Test-Path $GuardianCliLocation
51+
52+
if ($ValidPath -eq $False)
53+
{
54+
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Invalid Guardian CLI Location."
55+
ExitWithExitCode 1
56+
}
57+
58+
foreach ($tool in $ToolsList) {
59+
# Put together the name and scenario to make a unique key.
60+
$toolConfigName = $tool.Name
61+
if ($tool.Scenario) {
62+
$toolConfigName += "_" + $tool.Scenario
63+
}
64+
65+
Write-Host "=== Configuring $toolConfigName..."
66+
67+
$gdnConfigFile = Join-Path $gdnConfigPath "$toolConfigName-configure.gdnconfig"
68+
69+
# For some tools, add default and automatic args.
70+
if ($tool.Name -eq 'credscan') {
71+
if ($targetDirectory) {
72+
$tool.Args += "`"TargetDirectory < $TargetDirectory`""
73+
}
74+
$tool.Args += "`"OutputType < pre`""
75+
$tool.Args += $CrScanAdditionalRunConfigParams
76+
} elseif ($tool.Name -eq 'policheck') {
77+
if ($targetDirectory) {
78+
$tool.Args += "`"Target < $TargetDirectory`""
79+
}
80+
$tool.Args += $PoliCheckAdditionalRunConfigParams
81+
}
82+
83+
# Create variable pointing to the args array directly so we can use splat syntax later.
84+
$toolArgs = $tool.Args
85+
86+
# Configure the tool. If args array is provided or the current tool has some default arguments
87+
# defined, add "--args" and splat each element on the end. Arg format is "{Arg id} < {Value}",
88+
# one per parameter. Doc page for "guardian configure":
89+
# https://dev.azure.com/securitytools/SecurityIntegration/_wiki/wikis/Guardian/1395/configure
90+
Exec-BlockVerbosely {
91+
& $GuardianCliLocation configure `
92+
--working-directory $WorkingDirectory `
93+
--tool $tool.Name `
94+
--output-path $gdnConfigFile `
95+
--logger-level $GuardianLoggerLevel `
96+
--noninteractive `
97+
--force `
98+
$(if ($toolArgs) { "--args" }) @toolArgs
99+
Exit-IfNZEC "Sdl"
100+
}
101+
102+
Write-Host "Created '$toolConfigName' configuration file: $gdnConfigFile"
103+
}
104+
}
105+
catch {
106+
Write-Host $_.ScriptStackTrace
107+
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
108+
ExitWithExitCode 1
109+
}

0 commit comments

Comments
 (0)