Skip to content

Commit 2d1629b

Browse files
committed
Simplify build scripts even more and upgrade platyPS in Appveyor (PowerShell#1088)
* simplify build scripts even more and upgrade platyPS in Appveyor * add check for minimum version of platyps * fix ci and remove other leftovers * fix appveyor core build * fix wmf4 build by including the newtonsoft dll * fix syntax * trigger ci * trigger ci * address PR comments * build docs automatically the first time to simplify build process and save time on rebuild and get rid of unnecessary low level parameter sets * revert accidentally checked in file * fix merge/integration problem when merging from upstream * Fix another merge problem due to variable rename
1 parent deaf24b commit 2d1629b

File tree

6 files changed

+68
-95
lines changed

6 files changed

+68
-95
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,31 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
123123
* Building
124124
125125
You can either build using the `Visual Studio` solution `PSScriptAnalyzer.sln` or build using `PowerShell` specifically for your platform as follows:
126-
* The default build is for PowerShell Core
126+
* The default build is for the currently used version of PowerShell
127127
```powershell
128128
.\build.ps1
129129
```
130130
* Windows PowerShell version 5.0
131131
```powershell
132-
.\build.ps1 -Framework full -PSVersion 5 -Configuration Release
132+
.\build.ps1 -PSVersion 5
133133
```
134134
* Windows PowerShell version 4.0
135135
```powershell
136-
.\build.ps1 -Framework full -PSVersion 4 -Configuration Release
136+
.\build.ps1 -PSVersion 4
137137
```
138138
* Windows PowerShell version 3.0
139139
```powershell
140-
.\build.ps1 -Framework full -PSVersion 3 -Configuration Release
140+
.\build.ps1 -PSVersion 3
141141
```
142142
* PowerShell Core
143143
```powershell
144-
.\buildCoreClr.ps1 -Framework core -Configuration Release -Build
144+
.\build.ps1 -PSVersion 6
145145
```
146-
* Build documentation
146+
* Rebuild documentation since it gets built automatically only the first time
147147
```powershell
148148
.\build.ps1 -Documentation
149149
```
150-
* Build all versions (PowerShell v3, v4, v5, and Core) and documentation
150+
* Build all versions (PowerShell v3, v4, v5, and v6) and documentation
151151
```powershell
152152
.\build.ps1 -All
153153
```
@@ -166,7 +166,6 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to
166166
Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder.
167167

168168
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) or higher is installed
169-
* Ensure that the documentation has been built (`./build.ps1 -Documentation`)
170169
* In the root folder of your local repository, run:
171170
``` PowerShell
172171
./build -Test

Utils/ReleaseMaker.psm1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ function New-ReleaseBuild
9393
try
9494
{
9595
if ( test-path out ) { remove-item out/ -recurse -force }
96-
.\buildCoreClr.ps1 -Framework net452 -Configuration PSV3Release -Build
97-
.\buildCoreClr.ps1 -Framework net452 -Configuration PSV4Release -Build
98-
.\buildCoreClr.ps1 -Framework net452 -Configuration Release -Build
99-
.\buildCoreClr.ps1 -Framework netstandard2.0 -Configuration Release -Build
100-
.\build.ps1 -BuildDocs
96+
.\build.ps1 -All -Configuration Release
10197
}
10298
finally
10399
{

appveyor.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ build_script:
2424
- ps: |
2525
if ( $env:PowerShellEdition -eq 'WindowsPowerShell' ) {
2626
Set-Location $env:APPVEYOR_BUILD_FOLDER
27-
./build.ps1 -Documentation
2827
if ( $env:PSVersion -eq "4" ) { # On WMF4: Also build for v3 to check it builds at least since we do not have a WMF3 image
29-
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3 -Framework full
28+
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3
3029
}
31-
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion" -Framework full
30+
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion"
3231
}
3332
- pwsh: |
3433
if ($env:PowerShellEdition -eq 'PowerShellCore') {
3534
Set-Location $env:APPVEYOR_BUILD_FOLDER
36-
./build.ps1 -Documentation
37-
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 5 -Framework core
35+
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 6
3836
}
3937
4038
test_script:

build.ps1

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ param(
77
[switch]$All,
88

99
[Parameter(ParameterSetName="BuildOne")]
10-
[ValidateSet("full", "core")]
11-
[string]$Framework = "core",
12-
13-
[Parameter(ParameterSetName="BuildOne")]
14-
[ValidateSet("3","4","5")]
15-
[string]$PSVersion = "5",
10+
[ValidateRange(3, 6)]
11+
[int]$PSVersion = $PSVersionTable.PSVersion.Major,
1612

1713
[Parameter(ParameterSetName="BuildOne")]
1814
[Parameter(ParameterSetName="BuildAll")]
1915
[ValidateSet("Debug", "Release")]
2016
[string]$Configuration = "Debug",
2117

22-
[Parameter(ParameterSetName="BuildDoc")]
18+
# For building documentation only
19+
# or re-building it since docs gets built automatically only the first time
20+
[Parameter(ParameterSetName="BuildDocumentation")]
2321
[switch]$Documentation,
2422

2523
[Parameter(ParameterSetName='BuildAll')]
@@ -50,12 +48,11 @@ END {
5048
"BuildAll" {
5149
Start-ScriptAnalyzerBuild -All -Configuration $Configuration
5250
}
53-
"BuildDoc" {
51+
"BuildDocumentation" {
5452
Start-ScriptAnalyzerBuild -Documentation
5553
}
5654
"BuildOne" {
5755
$buildArgs = @{
58-
Framework = $Framework
5956
PSVersion = $PSVersion
6057
Configuration = $Configuration
6158
}

build.psm1

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,11 @@ function Start-DocumentationBuild
9393
$docsPath = Join-Path $projectRoot docs
9494
$markdownDocsPath = Join-Path $docsPath markdown
9595
$outputDocsPath = Join-Path $destinationDir en-US
96-
$requiredVersionOfplatyPS = 0.9
97-
#$modInfo = new-object Microsoft.PowerShell.Commands.ModuleSpecification -ArgumentList @{ ModuleName = "platyps"; ModuleVersion = $requiredVersionOfplatyPS}
98-
#if ( $null -eq (Get-Module -ListAvailable -FullyQualifiedName $modInfo))
99-
if ( $null -eq (Get-Module -ListAvailable platyPS))
96+
$platyPS = Get-Module -ListAvailable platyPS
97+
if ($null -eq $platyPS -or ($platyPS | Sort-Object Version -Descending | Select-Object -First 1).Version -lt [version]0.12)
10098
{
101-
Write-Verbose -verbose "platyPS not found, installing"
99+
Write-Verbose -verbose "platyPS module not found or below required version of 0.12, installing the latest version."
102100
Install-Module -Force -Name platyPS -Scope CurrentUser
103-
# throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
104101
}
105102
if (-not (Test-Path $markdownDocsPath))
106103
{
@@ -118,65 +115,42 @@ function Start-ScriptAnalyzerBuild
118115
{
119116
[CmdletBinding(DefaultParameterSetName="BuildOne")]
120117
param (
121-
[Parameter(ParameterSetName="BuildAll")]
122118
[switch]$All,
123119

124-
[Parameter(ParameterSetName="BuildOne")]
125-
[ValidateSet("full", "core")]
126-
[string]$Framework = "core",
120+
[ValidateRange(3, 6)]
121+
[int]$PSVersion = $PSVersionTable.PSVersion.Major,
127122

128-
[Parameter(ParameterSetName="BuildOne")]
129-
[ValidateSet("3","4","5")]
130-
[string]$PSVersion = "5",
131-
132-
[Parameter(ParameterSetName="BuildOne")]
133-
[Parameter(ParameterSetName="BuildAll")]
134123
[ValidateSet("Debug", "Release")]
135124
[string]$Configuration = "Debug",
136125

137-
[Parameter(ParameterSetName="BuildDoc")]
138126
[switch]$Documentation
139127
)
140128

141-
BEGIN {
142-
if ( $PSVersion -match "[34]" -and $Framework -eq "core" ) {
143-
throw "Script Analyzer for PowerShell 3/4 cannot be built for framework 'core'"
144-
}
145-
}
146129
END {
147130
if ( $All )
148131
{
149132
# Build all the versions of the analyzer
150-
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "3"
151-
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "4"
152-
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "5"
153-
Start-ScriptAnalyzerBuild -Framework core -Configuration $Configuration -PSVersion "5"
154-
Start-ScriptAnalyzerBuild -Documentation
133+
foreach($psVersion in 3..6) {
134+
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion
135+
}
155136
return
156137
}
157138

158-
if ( $Documentation )
139+
$documentationFileExists = Test-Path (Join-Path $PSScriptRoot 'out\PSScriptAnalyzer\en-us\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml')
140+
# Build docs either when -Documentation switch is being specified or the first time in a clean repo
141+
if ( $Documentation -or -not $documentationFileExists )
159142
{
160143
Start-DocumentationBuild
161-
return
162144
}
163145

164-
Push-Location -Path $projectRoot
165-
166-
if ( $framework -eq "core" ) {
167-
$frameworkName = "netstandard2.0"
146+
if ($PSVersion -ge 6) {
147+
$framework = 'netstandard2.0'
168148
}
169149
else {
170-
$frameworkName = "net452"
171-
}
172-
173-
# build the appropriate assembly
174-
if ($PSVersion -match "[34]" -and $Framework -eq "core")
175-
{
176-
throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework)
150+
$framework = "net452"
177151
}
178152

179-
#Write-Progress "Building ScriptAnalyzer"
153+
Push-Location -Path $projectRoot
180154
if (-not (Test-Path "$projectRoot/global.json"))
181155
{
182156
throw "Not in solution root"
@@ -188,53 +162,61 @@ function Start-ScriptAnalyzerBuild
188162
)
189163

190164
$destinationDir = "$projectRoot\out\PSScriptAnalyzer"
191-
# this is normalizing case as well as selecting the proper location
192-
if ( $Framework -eq "core" ) {
193-
$destinationDirBinaries = "$destinationDir\coreclr"
194-
}
195-
elseif ($PSVersion -eq '3') {
196-
$destinationDirBinaries = "$destinationDir\PSv3"
197-
}
198-
elseif ($PSVersion -eq '4') {
199-
$destinationDirBinaries = "$destinationDir\PSv4"
200-
}
201-
else {
202-
$destinationDirBinaries = $destinationDir
165+
switch ($PSVersion)
166+
{
167+
3
168+
{
169+
$destinationDirBinaries = "$destinationDir\PSv3"
170+
}
171+
4
172+
{
173+
$destinationDirBinaries = "$destinationDir\PSv4"
174+
}
175+
5
176+
{
177+
$destinationDirBinaries = "$destinationDir"
178+
}
179+
6
180+
{
181+
$destinationDirBinaries = "$destinationDir\coreclr"
182+
}
183+
default
184+
{
185+
throw "Unsupported PSVersion: '$PSVersion'"
186+
}
203187
}
204188

205-
# build the analyzer
206-
#Write-Progress "Building for framework $Framework, configuration $Configuration"
207-
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
208189
$config = "PSV${PSVersion}${Configuration}"
190+
191+
# Build ScriptAnalyzer
192+
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
209193
try {
210194
Push-Location $projectRoot/Rules
211-
Write-Progress "Building ScriptAnalyzer '$framework' version '${PSVersion}' configuration '${Configuration}'"
212-
$buildOutput = dotnet build Rules.csproj --framework $frameworkName --configuration "${config}"
195+
Write-Progress "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
196+
$buildOutput = dotnet build --framework $framework --configuration "$config"
213197
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
214198
}
215199
catch {
216-
Write-Error "Failure to build $framework ${config}"
200+
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$config'"
217201
return
218202
}
219203
finally {
220204
Pop-Location
221205
}
222206

223-
#Write-Progress "Copying files to $destinationDir"
224207
Publish-File $itemsToCopyCommon $destinationDir
225208

226209
$itemsToCopyBinaries = @(
227-
"$projectRoot\Engine\bin\${config}\${frameworkName}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
228-
"$projectRoot\Rules\bin\${config}\${frameworkName}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
210+
"$projectRoot\Engine\bin\${config}\${framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
211+
"$projectRoot\Rules\bin\${config}\${framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
229212
)
230213
Publish-File $itemsToCopyBinaries $destinationDirBinaries
231214

232215
$settingsFiles = Get-Childitem "$projectRoot\Engine\Settings" | ForEach-Object -MemberName FullName
233216
Publish-File $settingsFiles (Join-Path -Path $destinationDir -ChildPath Settings)
234217

235-
# copy newtonsoft dll if net452 framework
236-
if ($Framework -eq "full") {
237-
Copy-Item -path "$projectRoot\Rules\bin\${config}\${frameworkName}\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
218+
if ($framework -eq 'net452') {
219+
Copy-Item -path "$projectRoot\Rules\bin\${config}\${framework}\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
238220
}
239221

240222
Pop-Location
@@ -255,7 +237,7 @@ function Test-ScriptAnalyzer
255237
try {
256238
$savedModulePath = $env:PSModulePath
257239
$env:PSModulePath = "${testModulePath}{0}${env:PSModulePath}" -f [System.IO.Path]::PathSeparator
258-
$scriptBlock = [scriptblock]::Create("Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe")
240+
$scriptBlock = [scriptblock]::Create("Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe,Summary")
259241
if ( $InProcess ) {
260242
& $scriptBlock
261243
}

tools/appveyor.psm1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ function Invoke-AppVeyorInstall {
2020
}
2121
}
2222

23+
$platyPSVersion = '0.12.0'
2324
if ($null -eq (Get-Module -ListAvailable PowershellGet)) {
2425
# WMF 4 image build
2526
Write-Verbose -Verbose "Installing platyPS via nuget"
26-
nuget install platyPS -Version 0.9.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
27+
nuget install platyPS -Version $platyPSVersion -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion
2728
}
2829
else {
2930
Write-Verbose -Verbose "Installing platyPS via Install-Module"
30-
Install-Module -Name platyPS -Force -Scope CurrentUser -RequiredVersion '0.9.0'
31+
Install-Module -Name platyPS -Force -Scope CurrentUser -RequiredVersion $platyPSVersion
3132
}
3233

3334
# the legacy WMF4 image only has the old preview SDKs of dotnet

0 commit comments

Comments
 (0)