-
Notifications
You must be signed in to change notification settings - Fork 395
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
Changes from 8 commits
6f97d1a
749138b
863b48b
95b4042
2c0326b
7d78b1a
3be79c7
43113ac
2c93636
7517b5a
c595fcc
9de6986
0ef7eff
3e53231
8a44577
ac11bf5
fa1c18a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,14 +93,10 @@ 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)) | ||
if ( $null -eq (Get-Module -ListAvailable platyPS) -or ((Get-Module -ListAvailable platyPS | 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)) | ||
{ | ||
|
@@ -122,12 +118,8 @@ function Start-ScriptAnalyzerBuild | |
[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")] | ||
|
@@ -138,19 +130,13 @@ function Start-ScriptAnalyzerBuild | |
[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" | ||
foreach($psVersion in 3..6) { | ||
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion | ||
} | ||
Start-ScriptAnalyzerBuild -Documentation | ||
return | ||
} | ||
|
@@ -161,22 +147,12 @@ function Start-ScriptAnalyzerBuild | |
return | ||
} | ||
|
||
Push-Location -Path $projectRoot | ||
|
||
if ( $framework -eq "core" ) { | ||
$frameworkName = "netstandard2.0" | ||
} | ||
else { | ||
$frameworkName = "net451" | ||
$framework = 'net451' | ||
if ($PSVersion -ge 6) { | ||
$framework = 'netstandard2.0' | ||
} | ||
|
||
# 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) | ||
} | ||
|
||
#Write-Progress "Building ScriptAnalyzer" | ||
Push-Location -Path $projectRoot | ||
if (-not (Test-Path "$projectRoot/global.json")) | ||
{ | ||
throw "Not in solution root" | ||
|
@@ -191,51 +167,48 @@ 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') { | ||
if ($PSVersion -eq '3') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This switch ($PSVersion)
{
3
{
}
4
{
}
5
{
}
default
{
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, point taken. I'll change it to a switch for 3,4,5 and 6 and throw otherwise |
||
$destinationDirBinaries = "$destinationDir\PSv3" | ||
} | ||
elseif ($PSVersion -eq '4') { | ||
$destinationDirBinaries = "$destinationDir\PSv4" | ||
} | ||
else { | ||
elseif ($PSVersion -eq '5') { | ||
$destinationDirBinaries = $destinationDir | ||
} | ||
else { | ||
$destinationDirBinaries = "$destinationDir\coreclr" | ||
} | ||
|
||
# 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}" | ||
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 '$config'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a change in variables There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$buildOutput = dotnet build --framework $framework --configuration "${config}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth taking the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this was a James-ism ;-) |
||
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 | ||
|
||
Publish-File $settingsFiles (Join-Path -Path $destinationDir -ChildPath Settings) | ||
|
||
# copy newtonsoft dll if net451 framework | ||
if ($Framework -eq "full") { | ||
Copy-Item -path "$projectRoot\Rules\bin\${config}\${frameworkName}\Newtonsoft.Json.dll" -Destination $destinationDirBinaries | ||
if ($framework -eq 'net451') { | ||
Copy-Item -path "$projectRoot\Rules\bin\${config}\${framework}\Newtonsoft.Json.dll" -Destination $destinationDirBinaries | ||
} | ||
|
||
Pop-Location | ||
|
@@ -256,7 +229,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 | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Got a space on the left of the
$null
but no space on the right of the0.12
.gmo -List
is being called twice here and only looks at the first module (gmo -List
returns module in essentially random order, so that might not be the check we want).Maybe something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored that slightly to use a FullyQualifiedName
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but
Get-Module -ListAvailable @{ ModuleName = 'platyPS'; ModuleVersion = '0.12.0' }
does not work on my machine using either WPS or PSCore, I will refactor it to callgmo
only once though and sort by version. This shows thatgmo
could benefit from-MinimumVersion
parameter. P.S.Sort-Object Version
also needs theDescending
switch to get the latest version, otherwise it'd be the earliest.