Skip to content

Simplify build scripts even more and upgrade platyPS in Appveyor #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,31 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
* Building

You can either build using the `Visual Studio` solution `PSScriptAnalyzer.sln` or build using `PowerShell` specifically for your platform as follows:
* The default build is for PowerShell Core
* The default build is for the currently used version of PowerShell
```powershell
.\build.ps1
```
* Windows PowerShell version 5.0
```powershell
.\build.ps1 -Framework full -PSVersion 5 -Configuration Release
.\build.ps1 -PSVersion 5
```
* Windows PowerShell version 4.0
```powershell
.\build.ps1 -Framework full -PSVersion 4 -Configuration Release
.\build.ps1 -PSVersion 4
```
* Windows PowerShell version 3.0
```powershell
.\build.ps1 -Framework full -PSVersion 3 -Configuration Release
.\build.ps1 -PSVersion 3
```
* PowerShell Core
```powershell
.\buildCoreClr.ps1 -Framework core -Configuration Release -Build
.\build.ps1 -PSVersion 6
```
* Build documentation
* Rebuild documentation since it gets built automatically only the first time
```powershell
.\build.ps1 -Documentation
```
* Build all versions (PowerShell v3, v4, v5, and Core) and documentation
* Build all versions (PowerShell v3, v4, v5, and v6) and documentation
```powershell
.\build.ps1 -All
```
Expand All @@ -166,7 +166,6 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to
Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder.

* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) or higher is installed
* Ensure that the documentation has been built (`./build.ps1 -Documentation`)
* In the root folder of your local repository, run:
``` PowerShell
./build -Test
Expand Down
6 changes: 1 addition & 5 deletions Utils/ReleaseMaker.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ function New-ReleaseBuild
try
{
if ( test-path out ) { remove-item out/ -recurse -force }
.\buildCoreClr.ps1 -Framework net452 -Configuration PSV3Release -Build
.\buildCoreClr.ps1 -Framework net452 -Configuration PSV4Release -Build
.\buildCoreClr.ps1 -Framework net452 -Configuration Release -Build
.\buildCoreClr.ps1 -Framework netstandard2.0 -Configuration Release -Build
.\build.ps1 -BuildDocs
.\build.ps1 -All -Configuration Release
}
finally
{
Expand Down
8 changes: 3 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ build_script:
- ps: |
if ( $env:PowerShellEdition -eq 'WindowsPowerShell' ) {
Set-Location $env:APPVEYOR_BUILD_FOLDER
./build.ps1 -Documentation
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
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3 -Framework full
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3
}
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion" -Framework full
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion"
}
- pwsh: |
if ($env:PowerShellEdition -eq 'PowerShellCore') {
Set-Location $env:APPVEYOR_BUILD_FOLDER
./build.ps1 -Documentation
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 5 -Framework core
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 6
}

test_script:
Expand Down
15 changes: 6 additions & 9 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ param(
[switch]$All,

[Parameter(ParameterSetName="BuildOne")]
[ValidateSet("full", "core")]
[string]$Framework = "core",

[Parameter(ParameterSetName="BuildOne")]
[ValidateSet("3","4","5")]
[string]$PSVersion = "5",
[ValidateRange(3, 6)]
[int]$PSVersion = $PSVersionTable.PSVersion.Major,

[Parameter(ParameterSetName="BuildOne")]
[Parameter(ParameterSetName="BuildAll")]
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",

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

[Parameter(ParameterSetName='BuildAll')]
Expand Down Expand Up @@ -50,12 +48,11 @@ END {
"BuildAll" {
Start-ScriptAnalyzerBuild -All -Configuration $Configuration
}
"BuildDoc" {
"BuildDocumentation" {
Start-ScriptAnalyzerBuild -Documentation
}
"BuildOne" {
$buildArgs = @{
Framework = $Framework
PSVersion = $PSVersion
Configuration = $Configuration
}
Expand Down
114 changes: 48 additions & 66 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ function Start-DocumentationBuild
$docsPath = Join-Path $projectRoot docs
$markdownDocsPath = Join-Path $docsPath markdown
$outputDocsPath = Join-Path $destinationDir en-US
$requiredVersionOfplatyPS = 0.9
#$modInfo = new-object Microsoft.PowerShell.Commands.ModuleSpecification -ArgumentList @{ ModuleName = "platyps"; ModuleVersion = $requiredVersionOfplatyPS}
#if ( $null -eq (Get-Module -ListAvailable -FullyQualifiedName $modInfo))
if ( $null -eq (Get-Module -ListAvailable platyPS))
$platyPS = Get-Module -ListAvailable platyPS
if ($null -eq $platyPS -or ($platyPS | Sort-Object Version -Descending | Select-Object -First 1).Version -lt [version]0.12)
{
Write-Verbose -verbose "platyPS not found, installing"
Write-Verbose -verbose "platyPS module not found or below required version of 0.12, installing the latest version."
Install-Module -Force -Name platyPS -Scope CurrentUser
# throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
}
if (-not (Test-Path $markdownDocsPath))
{
Expand All @@ -118,65 +115,42 @@ function Start-ScriptAnalyzerBuild
{
[CmdletBinding(DefaultParameterSetName="BuildOne")]
param (
[Parameter(ParameterSetName="BuildAll")]
[switch]$All,

[Parameter(ParameterSetName="BuildOne")]
[ValidateSet("full", "core")]
[string]$Framework = "core",
[ValidateRange(3, 6)]
[int]$PSVersion = $PSVersionTable.PSVersion.Major,

[Parameter(ParameterSetName="BuildOne")]
[ValidateSet("3","4","5")]
[string]$PSVersion = "5",

[Parameter(ParameterSetName="BuildOne")]
[Parameter(ParameterSetName="BuildAll")]
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",

[Parameter(ParameterSetName="BuildDoc")]
[switch]$Documentation
)

BEGIN {
if ( $PSVersion -match "[34]" -and $Framework -eq "core" ) {
throw "Script Analyzer for PowerShell 3/4 cannot be built for framework 'core'"
}
}
END {
if ( $All )
{
# Build all the versions of the analyzer
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "3"
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "4"
Start-ScriptAnalyzerBuild -Framework full -Configuration $Configuration -PSVersion "5"
Start-ScriptAnalyzerBuild -Framework core -Configuration $Configuration -PSVersion "5"
Start-ScriptAnalyzerBuild -Documentation
foreach($psVersion in 3..6) {
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion
}
return
}

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

Push-Location -Path $projectRoot

if ( $framework -eq "core" ) {
$frameworkName = "netstandard2.0"
if ($PSVersion -ge 6) {
$framework = 'netstandard2.0'
}
else {
$frameworkName = "net452"
}

# build the appropriate assembly
if ($PSVersion -match "[34]" -and $Framework -eq "core")
{
throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework)
$framework = "net452"
}

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

$destinationDir = "$projectRoot\out\PSScriptAnalyzer"
# this is normalizing case as well as selecting the proper location
if ( $Framework -eq "core" ) {
$destinationDirBinaries = "$destinationDir\coreclr"
}
elseif ($PSVersion -eq '3') {
$destinationDirBinaries = "$destinationDir\PSv3"
}
elseif ($PSVersion -eq '4') {
$destinationDirBinaries = "$destinationDir\PSv4"
}
else {
$destinationDirBinaries = $destinationDir
switch ($PSVersion)
{
3
{
$destinationDirBinaries = "$destinationDir\PSv3"
}
4
{
$destinationDirBinaries = "$destinationDir\PSv4"
}
5
{
$destinationDirBinaries = "$destinationDir"
}
6
{
$destinationDirBinaries = "$destinationDir\coreclr"
}
default
{
throw "Unsupported PSVersion: '$PSVersion'"
}
}

# build the analyzer
#Write-Progress "Building for framework $Framework, configuration $Configuration"
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
$config = "PSV${PSVersion}${Configuration}"

# Build ScriptAnalyzer
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
try {
Push-Location $projectRoot/Rules
Write-Progress "Building ScriptAnalyzer '$framework' version '${PSVersion}' configuration '${Configuration}'"
$buildOutput = dotnet build Rules.csproj --framework $frameworkName --configuration "${config}"
Write-Progress "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
$buildOutput = dotnet build --framework $framework --configuration "$config"
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
}
catch {
Write-Error "Failure to build $framework ${config}"
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$config'"
return
}
finally {
Pop-Location
}

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

$itemsToCopyBinaries = @(
"$projectRoot\Engine\bin\${config}\${frameworkName}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
"$projectRoot\Rules\bin\${config}\${frameworkName}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
"$projectRoot\Engine\bin\${config}\${framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
"$projectRoot\Rules\bin\${config}\${framework}\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
)
Publish-File $itemsToCopyBinaries $destinationDirBinaries

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

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

Pop-Location
Expand All @@ -255,7 +237,7 @@ function Test-ScriptAnalyzer
try {
$savedModulePath = $env:PSModulePath
$env:PSModulePath = "${testModulePath}{0}${env:PSModulePath}" -f [System.IO.Path]::PathSeparator
$scriptBlock = [scriptblock]::Create("Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe")
$scriptBlock = [scriptblock]::Create("Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe,Summary")
if ( $InProcess ) {
& $scriptBlock
}
Expand Down
5 changes: 3 additions & 2 deletions tools/appveyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ function Invoke-AppVeyorInstall {
}
}

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

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