Skip to content

Commit 6bdc6f4

Browse files
authored
move to new signing process for release build and prep for 1.20.0 (#1625)
* Move to new compliance and signing infrastructure * bump version to 1.20.0 * change to use allowlist in documentation and tests
1 parent 3b0a16f commit 6bdc6f4

File tree

14 files changed

+264
-24
lines changed

14 files changed

+264
-24
lines changed

.ci/releaseBuild.yml

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# The name of the build that will be seen in mscodehub
2+
name: PSSA-Release-$(Build.BuildId)
3+
# how is the build triggered
4+
# since this is a release build, no trigger as it's a manual release
5+
trigger: none
6+
7+
pr:
8+
branches:
9+
include:
10+
- master
11+
- release*
12+
13+
# variables to set in the build environment
14+
variables:
15+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
16+
POWERSHELL_TELEMETRY_OPTOUT: 1
17+
18+
# since this build relies on templates, we need access to those
19+
# This needs a service connection in the build to work
20+
# the *name* of the service connection must be the same as the endpoint
21+
resources:
22+
repositories:
23+
- repository: ComplianceRepo
24+
type: github
25+
endpoint: ComplianceGHRepo
26+
name: PowerShell/compliance
27+
# this can be any branch of your choosing
28+
ref: master
29+
30+
# the stages in this build. There are 2
31+
# the assumption for script analyzer is that test is done as part of
32+
# CI so we needn't do it here
33+
stages:
34+
- stage: Build
35+
displayName: Build
36+
pool:
37+
name: Package ES CodeHub Lab E
38+
jobs:
39+
- job: Build_Job
40+
displayName: Build Microsoft.PowerShell.ScriptAnalyzer
41+
# note the variable reference to ESRP.
42+
# this must be created in Project -> Pipelines -> Library -> VariableGroups
43+
# where it describes the link to the SigningServer
44+
variables:
45+
- group: ESRP
46+
steps:
47+
- checkout: self
48+
49+
# the steps for building the module go here
50+
- pwsh: |
51+
Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA"
52+
try { ./build.ps1 -Configuration Release -All } catch { throw $_ }
53+
displayName: Execute build
54+
55+
# these are setting vso variables which will be persisted between stages
56+
- pwsh: |
57+
$signSrcPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/out"
58+
# Set signing src path variable
59+
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
60+
Write-Host "sending $vstsCommandString"
61+
Write-Host "##$vstsCommandString"
62+
63+
$signOutStep1 = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/Step1"
64+
$null = New-Item -ItemType Directory -Path $signOutStep1
65+
# Set signing out path variable
66+
$vstsCommandString = "vso[task.setvariable variable=signOutStep1]${signOutStep1}"
67+
Write-Host "sending $vstsCommandString"
68+
Write-Host "##$vstsCommandString"
69+
70+
$signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/signed"
71+
$null = New-Item -ItemType Directory -Path $signOutPath
72+
# Set signing out path variable
73+
$vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}"
74+
Write-Host "sending $vstsCommandString"
75+
Write-Host "##$vstsCommandString"
76+
77+
# Set path variable for guardian codesign validation
78+
$vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}"
79+
Write-Host "sending $vstsCommandString"
80+
Write-Host "##$vstsCommandString"
81+
82+
# Get version and create a variable
83+
$moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/Engine/PSScriptAnalyzer.psd1"
84+
$moduleVersion = $moduleData.ModuleVersion
85+
$vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}"
86+
Write-Host "sending $vstsCommandString"
87+
Write-Host "##$vstsCommandString"
88+
89+
90+
displayName: Setup variables for signing
91+
92+
# checkout the Compliance repository so it can be used to do the actual signing
93+
- checkout: ComplianceRepo
94+
95+
# in script analyzer, we must sign with 2 different certs
96+
# the normal cert for MS created items and the 3rd party cert
97+
# this the MS authored step
98+
# Because this needs 2 certs, we do it in 2 steps.
99+
# the first step signs the binaries and puts them in a staging directory which
100+
# will then be used for the second step.
101+
- template: EsrpSign.yml@ComplianceRepo
102+
parameters:
103+
# the folder which contains the binaries to sign
104+
buildOutputPath: $(signSrcPath)
105+
# the location to put the signed output
106+
signOutputPath: $(signOutStep1)
107+
# the certificate ID to use
108+
certificateId: "CP-230012"
109+
# use minimatch because we need to exclude the NewtonSoft assembly
110+
useMinimatch: true
111+
# the file pattern to use - newtonSoft is excluded
112+
pattern: |
113+
**\*.psd1
114+
**\*.psm1
115+
**\*.ps1xml
116+
**\Microsoft*.dll
117+
118+
# this is the second step of the signing.
119+
# note that the buildOutputPath (where we get the files to sign)
120+
# is the same as the signOutputPath in the previous step
121+
# at the end of this step we will have all the files signed that should be
122+
# signOutPath is the location which contains the files we will use to make the module
123+
- template: EsrpSign.yml@ComplianceRepo
124+
parameters:
125+
# the folder which contains the binaries to sign
126+
buildOutputPath: $(signOutStep1)
127+
# the location to put the signed output
128+
signOutputPath: $(signOutPath)
129+
# the certificate ID to use
130+
# we'll need to change this to the 3rd party cert id
131+
certificateId: "CP-231522"
132+
# the file pattern to use - only sign newtonsoft
133+
pattern: 'Newtonsoft*.dll'
134+
135+
# now create the nupkg which we will use to publish the module
136+
# to the powershell gallery (not part of this yaml)
137+
- pwsh: |
138+
Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA"
139+
./build -BuildNupkg -signed
140+
displayName: Create nupkg for publishing
141+
142+
# finally publish the parts of the build which will be used in the next stages
143+
# if it's not published, the subsequent stages will not be able to access it.
144+
# This is the build directory (it contains all of the dll/pdb files)
145+
- publish: "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA"
146+
artifact: build
147+
displayName: publish build directory
148+
149+
# export the nupkg only which will be used in the release pipeline
150+
- publish: "$(signOutPath)/PSScriptAnalyzer.$(moduleVersion).nupkg"
151+
artifact: nupkg
152+
displayName: Publish module nupkg
153+
154+
# Now on to the compliance stage
155+
- stage: compliance
156+
displayName: Compliance
157+
dependsOn: Build
158+
jobs:
159+
- job: Compliance_Job
160+
pool:
161+
name: Package ES CodeHub Lab E
162+
steps:
163+
- checkout: self
164+
- checkout: ComplianceRepo
165+
- download: current
166+
artifact: build
167+
168+
# use the templates in the compliance repo
169+
# since script analyzer has modules, we're using the assembly-module-compliance template
170+
# if you don't have assemblies, you should use script-module-compliance template
171+
- template: assembly-module-compliance.yml@ComplianceRepo
172+
parameters:
173+
# component-governance - the path to sources
174+
sourceScanPath: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA'
175+
# binskim - this isn't recursive, so you need the path to the assemblies
176+
AnalyzeTarget: '$(Pipeline.Workspace)\build\bin\PSV7Release\netcoreapp3.1\*.dll'
177+
# credscan - scan the repo for credentials
178+
# you can suppress some files with this.
179+
suppressionsFile: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/tools/ReleaseBuild/CredScan.Suppressions.json'
180+
# TermCheck
181+
optionsRulesDBPath: ''
182+
optionsFTPath: ''
183+
# tsa-upload
184+
# the compliance scanning must be uploaded, which you need to request
185+
codeBaseName: 'PSSA_202004'
186+
# selections
187+
APIScan: false # set to false when not using Windows APIs.
188+
189+
#- template: template/publish.yml
190+
# parameters:
191+
# stageName: AzArtifactsFeed
192+
# environmentName:
193+
# feedCredential:
194+
195+
#- template: template/publish.yml
196+
# parameters:
197+
# stageName: NuGet
198+
# environmentName: PSMarkdownRenderNuGetApproval
199+
# feedCredential: NugetOrgPush

Engine/Engine.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.19.1</VersionPrefix>
4+
<VersionPrefix>1.20.0</VersionPrefix>
55
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
7-
<AssemblyVersion>1.19.1</AssemblyVersion>
7+
<AssemblyVersion>1.20.0</AssemblyVersion>
88
<PackageId>Engine</PackageId>
99
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
1010
</PropertyGroup>

Engine/PSScriptAnalyzer.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
1111
RootModule = 'PSScriptAnalyzer.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.19.1'
14+
ModuleVersion = '1.20.0'
1515

1616
# ID used to uniquely identify this module
1717
GUID = 'd6245802-193d-4068-a631-8863a4342a18'

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.19.1</VersionPrefix>
4+
<VersionPrefix>1.20.0</VersionPrefix>
55
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
6-
<AssemblyVersion>1.19.1</AssemblyVersion>
6+
<AssemblyVersion>1.20.0</AssemblyVersion>
77
</PropertyGroup>
88

99
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

RuleDocumentation/AvoidUsingCmdletAliases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To prevent `PSScriptAnalyzer` from flagging your preferred aliases, create an al
2828
@{
2929
'Rules' = @{
3030
'PSAvoidUsingCmdletAliases' = @{
31-
'Whitelist' = @('cd')
31+
'allowlist' = @('cd')
3232
}
3333
}
3434
}

Rules/Rules.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.19.1</VersionPrefix>
4+
<VersionPrefix>1.20.0</VersionPrefix>
55
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
7-
<AssemblyVersion>1.19.1</AssemblyVersion>
7+
<AssemblyVersion>1.20.0</AssemblyVersion>
88
<PackageId>Rules</PackageId>
99
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
1010
</PropertyGroup>

Tests/Engine/Settings.tests.ps1

+7-7
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,23 @@ Describe "Settings Class" {
109109
$settingsHashtable = @{
110110
Rules = @{
111111
PSAvoidUsingCmdletAliases = @{
112-
WhiteList = @("cd", "cp")
112+
allowlist = @("cd", "cp")
113113
}
114114
}
115115
}
116116
$settings = New-Object -TypeName $settingsTypeName -ArgumentList $settingsHashtable
117117
}
118118

119119
It "Should return the rule arguments" {
120-
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["WhiteList"].Count | Should -Be 2
121-
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["WhiteList"][0] | Should -Be "cd"
122-
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["WhiteList"][1] | Should -Be "cp"
120+
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["allowlist"].Count | Should -Be 2
121+
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["allowlist"][0] | Should -Be "cd"
122+
$settings.RuleArguments["PSAvoidUsingCmdletAliases"]["allowlist"][1] | Should -Be "cp"
123123
}
124124

125125
It "Should Be case insensitive" {
126-
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["whiteList"].Count | Should -Be 2
127-
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["whiteList"][0] | Should -Be "cd"
128-
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["whiteList"][1] | Should -Be "cp"
126+
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["allowlist"].Count | Should -Be 2
127+
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["allowlist"][0] | Should -Be "cd"
128+
$settings.RuleArguments["psAvoidUsingCmdletAliases"]["allowlist"][1] | Should -Be "cp"
129129
}
130130
}
131131

Tests/Engine/SettingsTest/Issue828/PSScriptAnalyzerSettings.psd1

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
PSAvoidUsingCmdletAliases = @{
1717
# only allowlist verbs from *-Object cmdlets
18-
Whitelist = @(
18+
allowlist = @(
1919
'%',
2020
'?',
2121
'compare',
@@ -60,4 +60,4 @@
6060
CheckSeparator = $true
6161
}
6262
}
63-
}
63+
}

Tests/Engine/SettingsTest/Project1/ExplicitSettings.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ExcludeRules" = @("PSShouldProcess", "PSAvoidUsingWMICmdlet", "PSUseCmdletCorrectly")
44
"rules" = @{
55
PSAvoidUsingCmdletAliases = @{
6-
WhiteList = @("cd", "cp")
6+
allowlist = @("cd", "cp")
77
}
88

99
PSUseConsistentIndentation = @{

Tests/Rules/AvoidUsingAlias.tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Configuration MyDscConfiguration {
7373
$settings = @{
7474
'Rules' = @{
7575
'PSAvoidUsingCmdletAliases' = @{
76-
'Whitelist' = @('cd')
76+
'allowlist' = @('cd')
7777
}
7878
}
7979
}
@@ -83,7 +83,7 @@ Configuration MyDscConfiguration {
8383
$settings = @{
8484
'Rules' = @{
8585
'PSAvoidUsingCmdletAliases' = @{
86-
'Whitelist' = @('cd')
86+
'allowlist' = @('cd')
8787
}
8888
}
8989
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@{
22
'Rules' = @{
33
'PSAvoidUsingCmdletAliases' = @{
4-
'Whitelist' = @('cd')
4+
'allowlist' = @('cd')
55
}
66
}
7-
}
7+
}

build.ps1

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ param(
3737
[switch] $Bootstrap,
3838

3939
[Parameter(ParameterSetName='BuildAll')]
40-
[switch] $Catalog
40+
[switch] $Catalog,
41+
42+
[Parameter(ParameterSetName='Package')]
43+
[switch] $BuildNupkg,
44+
45+
[Parameter(ParameterSetName='Package')]
46+
[switch] $Signed
4147

4248
)
4349

@@ -85,6 +91,9 @@ END {
8591
Install-DotNet
8692
return
8793
}
94+
"Package" {
95+
Start-CreatePackage -signed:$Signed
96+
}
8897
"Test" {
8998
Test-ScriptAnalyzer -InProcess:$InProcess
9099
return

0 commit comments

Comments
 (0)