Skip to content

Commit 7bb24d2

Browse files
authored
new build scripts for release pipeline (#1442)
* change build location when in VSTS * copy newtonsoft assembly from proper location * Add support for verbose output during build * update verbose behavior incorporate catalog building into module * better code to handle verbose * file for signing analyzer files * tweaks to catalog creation * Add suppression of UseCompatibleCommands rule for function that builds file catalog * Improve message when there are failures in use compatible commands * change logic for whether catalog can be created based on whether new-filecatalog exists rather than IsWindows variable which doesn't exist on PS5 * Add catalog signing configuration * fix typo in catalog name * use 400 for signing * Address PR feedback Remove comment code change logic to use existing environment variable when building in VSTS Remove extraneous suppression of New-FileCatalog * add the suppression back to the function which creates the filecatalog * Create suppression file for CredScan so it does not get triggered.
1 parent 6fa29cb commit 7bb24d2

File tree

6 files changed

+158
-18
lines changed

6 files changed

+158
-18
lines changed

Tests/Rules/UseCompatibleCommands.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Describe 'UseCompatibleCommands' {
400400
}
401401

402402
$diagnostics = Invoke-ScriptAnalyzer -Path "$PSScriptRoot/../../" -IncludeRule $script:RuleName -Settings $settings
403-
$diagnostics.Count | Should -Be 0 -Because ($diagnostics.RuleName -join ', ')
403+
$diagnostics.Count | Should -Be 0 -Because ($diagnostics.Message -join ', ')
404404
}
405405
}
406406

build.ps1

+25-5
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,24 @@ param(
3434
[switch] $InProcess,
3535

3636
[Parameter(ParameterSetName='Bootstrap')]
37-
[switch] $Bootstrap
37+
[switch] $Bootstrap,
38+
39+
[Parameter(ParameterSetName='BuildAll')]
40+
[switch] $Catalog
41+
3842
)
3943

44+
BEGIN {
45+
$verboseWanted = $false
46+
if ( $PSBoundParameters['Verbose'] ) {
47+
$verboseWanted = $PSBoundParameters['Verbose'].ToBool()
48+
}
49+
}
50+
4051
END {
41-
Import-Module -Force (Join-Path $PSScriptRoot build.psm1)
52+
Import-Module -Force (Join-Path $PSScriptRoot build.psm1) -verbose:$false
4253
if ( $Clean -or $Clobber ) {
43-
Remove-Build
54+
Remove-Build -verbose:$false
4455
if ( $PSCmdlet.ParameterSetName -eq "Clean" ) {
4556
return
4657
}
@@ -49,10 +60,19 @@ END {
4960
$setName = $PSCmdlet.ParameterSetName
5061
switch ( $setName ) {
5162
"BuildAll" {
52-
Start-ScriptAnalyzerBuild -All -Configuration $Configuration
63+
$buildArgs = @{
64+
All = $true
65+
Configuration = $Configuration
66+
Verbose = $verboseWanted
67+
Catalog = $false
68+
}
69+
if ( $Catalog ) {
70+
$buildArgs['Catalog'] = $true
71+
}
72+
Start-ScriptAnalyzerBuild @buildArgs
5373
}
5474
"BuildDocumentation" {
55-
Start-ScriptAnalyzerBuild -Documentation
75+
Start-ScriptAnalyzerBuild -Documentation -Verbose:$Verbose
5676
}
5777
"BuildOne" {
5878
$buildArgs = @{

build.psm1

+68-12
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function Start-DocumentationBuild
114114
{
115115
throw "Cannot find markdown documentation folder."
116116
}
117-
Import-Module platyPS
117+
Import-Module platyPS -Verbose:$false
118118
if ( -not (Test-Path $outputDocsPath)) {
119119
$null = New-Item -Type Directory -Path $outputDocsPath -Force
120120
}
@@ -150,7 +150,9 @@ function Start-ScriptAnalyzerBuild
150150
[ValidateSet("Debug", "Release")]
151151
[string]$Configuration = "Debug",
152152

153-
[switch]$Documentation
153+
[switch]$Documentation,
154+
155+
[switch]$Catalog
154156
)
155157

156158
BEGIN {
@@ -163,27 +165,36 @@ function Start-ScriptAnalyzerBuild
163165
$foundVersion = Get-InstalledCLIVersion
164166
Write-Warning "No suitable dotnet CLI found, requires version '$requiredVersion' found only '$foundVersion'"
165167
}
168+
$verboseWanted = $false
169+
if ( $PSBoundParameters['Verbose'] ) {
170+
$verboseWanted = $PSBoundParameters['Verbose'].ToBool()
171+
}
166172
}
167173
END {
168174

169175
# Build docs either when -Documentation switch is being specified or the first time in a clean repo
170176
$documentationFileExists = Test-Path (Join-Path $PSScriptRoot 'out\PSScriptAnalyzer\en-us\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml')
171177
if ( $Documentation -or -not $documentationFileExists )
172178
{
173-
Start-DocumentationBuild
179+
Write-Verbose -Verbose:$verboseWanted -Message "Start-DocumentationBuild"
180+
Start-DocumentationBuild -Verbose:$verboseWanted
174181
}
175182

176183
if ( $All )
177184
{
178185
# Build all the versions of the analyzer
179186
foreach($psVersion in 3..7) {
180-
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion
187+
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$verboseWanted
188+
}
189+
if ( $Catalog ) {
190+
New-Catalog -Location $script:destinationDir
181191
}
182192
return
183193
}
184194

185195
if (-not $profilesCopied)
186196
{
197+
Write-Verbose -Verbose:$verboseWanted -Message "Copy-CompatibilityProfiles"
187198
Copy-CompatibilityProfiles
188199
# Set the variable in the caller's scope, so this will only happen once
189200
Set-Variable -Name profilesCopied -Value $true -Scope 1
@@ -253,12 +264,24 @@ function Start-ScriptAnalyzerBuild
253264
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
254265
try {
255266
Push-Location $projectRoot/Rules
256-
Write-Progress "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
267+
$message = "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
268+
Write-Verbose -Verbose:$verboseWanted -Message "$message"
269+
Write-Progress "$message"
257270
if ( -not $script:DotnetExe ) {
258271
$script:DotnetExe = Get-DotnetExe
259272
}
260-
$buildOutput = & $script:DotnetExe build --framework $framework --configuration "$buildConfiguration" 2>&1
273+
$dotnetArgs = "build",
274+
"--framework",
275+
$framework,
276+
"--configuration",
277+
"$buildConfiguration"
278+
if ( $env:TF_BUILD ) {
279+
$dotnetArgs += "--output"
280+
$dotnetArgs += "${PSScriptRoot}\bin\${buildConfiguration}\${framework}"
281+
}
282+
$buildOutput = & $script:DotnetExe $dotnetArgs 2>&1
261283
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
284+
Write-Verbose -Verbose:$verboseWanted -message "$buildOutput"
262285
}
263286
catch {
264287
Write-Warning $_
@@ -271,24 +294,57 @@ function Start-ScriptAnalyzerBuild
271294

272295
Publish-File $itemsToCopyCommon $script:destinationDir
273296

274-
$itemsToCopyBinaries = @(
275-
"$projectRoot\Engine\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
276-
"$projectRoot\Rules\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
277-
"$projectRoot\Rules\bin\${buildConfiguration}\${framework}\Microsoft.PowerShell.CrossCompatibility.dll"
278-
)
297+
if ( $env:TF_BUILD ) {
298+
$itemsToCopyBinaries = @(
299+
"$projectRoot\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
300+
"$projectRoot\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
301+
"$projectRoot\bin\${buildConfiguration}\${framework}\Microsoft.PowerShell.CrossCompatibility.dll"
302+
)
303+
}
304+
else {
305+
$itemsToCopyBinaries = @(
306+
"$projectRoot\Engine\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
307+
"$projectRoot\Rules\bin\${buildConfiguration}\${Framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
308+
"$projectRoot\Rules\bin\${buildConfiguration}\${framework}\Microsoft.PowerShell.CrossCompatibility.dll"
309+
)
310+
}
279311
Publish-File $itemsToCopyBinaries $destinationDirBinaries
280312

281313
$settingsFiles = Get-Childitem "$projectRoot\Engine\Settings" | ForEach-Object -MemberName FullName
282314
Publish-File $settingsFiles (Join-Path -Path $script:destinationDir -ChildPath Settings)
283315

284316
if ($framework -eq 'net452') {
285-
Copy-Item -path "$projectRoot\Rules\bin\${buildConfiguration}\${framework}\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
317+
if ( $env:TF_BUILD ) {
318+
$nsoft = "$projectRoot\bin\${buildConfiguration}\${framework}\Newtonsoft.Json.dll"
319+
}
320+
else {
321+
$nsoft = "$projectRoot\Rules\bin\${buildConfiguration}\${framework}\Newtonsoft.Json.dll"
322+
}
323+
Copy-Item -path $nsoft -Destination $destinationDirBinaries
286324
}
287325

288326
Pop-Location
289327
}
290328
}
291329

330+
function New-Catalog
331+
{
332+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleCommands', '')]
333+
param ( [Parameter()]$Location )
334+
$newFileCatalog = Get-Command -ErrorAction SilentlyContinue New-FileCatalog
335+
if ($null -eq $newFileCatalog) {
336+
Write-Warning "New-FileCatalog not found, not creating catalog"
337+
return
338+
}
339+
try {
340+
Push-Location $Location
341+
New-FileCatalog -CatalogFilePath PSScriptAnalyzer.cat -Path .
342+
}
343+
finally {
344+
Pop-Location
345+
}
346+
}
347+
292348
# TEST HELPERS
293349
# Run our tests
294350
function Test-ScriptAnalyzer
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<SignConfigXML>
3+
<!-- ****Begin**** BothDual - Dual (Sha256 and Sha1) AuthicodeDual) and should be StrongName, but we will add this in 6.1.0 ******** -->
4+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer" approvers="vigarg;gstolt">
5+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
6+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
7+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Microsoft.PowerShell.CrossCompatibility.dll" />
8+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.psd1" />
9+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.psm1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.psm1" />
10+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\ScriptAnalyzer.format.ps1xml" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\ScriptAnalyzer.format.ps1xml" />
11+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\ScriptAnalyzer.types.ps1xml" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\ScriptAnalyzer.types.ps1xml" />
12+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\CmdletDesign.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\CmdletDesign.psd1" />
13+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\CodeFormatting.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\CodeFormatting.psd1" />
14+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingAllman.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingAllman.psd1" />
15+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingOTBS.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingOTBS.psd1" />
16+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingStroustrup.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\CodeFormattingStroustrup.psd1" />
17+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\DSC.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\DSC.psd1" />
18+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\PSGallery.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\PSGallery.psd1" />
19+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\ScriptFunctions.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\ScriptFunctions.psd1" />
20+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\ScriptingStyle.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\ScriptingStyle.psd1" />
21+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\Settings\ScriptSecurity.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\Settings\ScriptSecurity.psd1" />
22+
</job>
23+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv6" approvers="vigarg;gstolt">
24+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
25+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
26+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" />
27+
</job>
28+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv7" approvers="vigarg;gstolt">
29+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
30+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
31+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv7\Microsoft.PowerShell.CrossCompatibility.dll" />
32+
</job>
33+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv4" approvers="vigarg;gstolt">
34+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
35+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
36+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv4\Microsoft.PowerShell.CrossCompatibility.dll" />
37+
</job>
38+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv3" approvers="vigarg;gstolt">
39+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
40+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
41+
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSv3\Microsoft.PowerShell.CrossCompatibility.dll" />
42+
</job>
43+
</SignConfigXML>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<SignConfigXML>
3+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer File Catalog" approvers="vigarg;gstolt">
4+
<file src="__INPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" />
5+
</job>
6+
</SignConfigXML>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"tool": "Credential Scanner",
3+
"suppressions": [
4+
{ "file": "\\Engine\\Settings\\desktop-4.0-windows.json",
5+
"_justification": "The file contains the list of all parameters of a cmdlet but no passwords are actually present." },
6+
{ "file": "\\Engine\\Settings\\desktop-3.0-windows.json",
7+
"_justification": "The file contains the list of all parameters of a cmdlet but no passwords are actually present." },
8+
{ "file": "\\Engine\\Settings\\desktop-5.1.14393.206-windows.json",
9+
"_justification": "The file contains the list of all parameters of a cmdlet but no passwords are actually present." },
10+
{ "file": "\\Tests\\Engine\\RuleSuppression.tests.ps1",
11+
"_justification": "The parameter password is used in function declaration for test but is not called and no password is present." }
12+
]
13+
}
14+
15+

0 commit comments

Comments
 (0)