diff --git a/README.md b/README.md index 4a8ec531b..1d8d4677a 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 diff --git a/Utils/ReleaseMaker.psm1 b/Utils/ReleaseMaker.psm1 index c6be2ef2e..8f2553839 100644 --- a/Utils/ReleaseMaker.psm1 +++ b/Utils/ReleaseMaker.psm1 @@ -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 { diff --git a/appveyor.yml b/appveyor.yml index 07c891a40..0e3ec08d6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: diff --git a/build.ps1 b/build.ps1 index e0e0712cd..2473146e2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -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')] @@ -50,12 +48,11 @@ END { "BuildAll" { Start-ScriptAnalyzerBuild -All -Configuration $Configuration } - "BuildDoc" { + "BuildDocumentation" { Start-ScriptAnalyzerBuild -Documentation } "BuildOne" { $buildArgs = @{ - Framework = $Framework PSVersion = $PSVersion Configuration = $Configuration } diff --git a/build.psm1 b/build.psm1 index 889a855ab..f9f216554 100644 --- a/build.psm1 +++ b/build.psm1 @@ -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)) { @@ -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" @@ -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 @@ -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 } diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index 46fc0736a..d9cbf3663 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -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