Skip to content
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

Update, simplify, and consolidate build scripts #1082

Merged
merged 17 commits into from
Oct 23, 2018

Conversation

JamesWTruher
Copy link
Contributor

@JamesWTruher JamesWTruher commented Oct 17, 2018

PR Summary

In order to actually build script analyzer, you have to run a couple of different scripts if you're going to also build documentation. This PR consolidates everything into a single script build.ps1 and a module build.psm1 which implements the actions. This is targeting the developer scenario rather than CI usage.

The documentation is updated to provide examples of how to use the script.
Additionally, I'm updating the sdk version to 2.1.400 to match PowerShell Core, so you can build both PowerShell Core and Script Analyzer with the same SDK.

PR Checklist

Require any 2.1 sdk for building, this way we can build with the same sdk as PowerShell core
To build for core, simply type ./build,
to build all flavors and documentation type ./build -all.
You can now run tests as well via ./build -Test.
because it's really about the version of PS, not the analyzer
Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at the code it looks good overall, with one small mistake. Some odd (non-standard and inconsistent) whitespace at the beginning and/or end of a parenthesis.
I will try running and using this locally the next days and then approve.


RUN apt update -qq && \
cd / && \
git clone https://github.com/JamesWTruher/PSScriptAnalyzer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be?

Suggested change
git clone https://github.com/JamesWTruher/PSScriptAnalyzer
git clone https://github.com/PowerShell/PSScriptAnalyzer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it should :/

Copy link
Contributor

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -123,25 +123,33 @@ 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:
* Windows PowerShell version 5.0 and greater
* The default build is for PowerShell Core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the sake of argument, should the default build be for the current platform the script is being run on? That's possibly an order of magnitude harder to accomplish, but thought I would bring it up.

Copy link
Collaborator

@bergmeister bergmeister Oct 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for that but I see it as an optional nice to have that could come after this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) why would anyone be using anything other than core? :)

$testScriptFilePath = CreateTestRunnerScript $testPath
Start-Process powershell -ArgumentList "-NoExit","-File $testScriptFilePath" -Verb runas
# clean up the test file
$setName = $PSCmdlet.ParameterSetName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is used above, maybe it's worth assigning above, below the Import-Module line?

Build-ScriptAnalyzer -Documentation
}
"BuildOne" {
$buildArgs = @{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I find I do this a lot in PowerShell as well (pass arguments down through commands). Perhaps it's an antipattern (Law of Demeter violation type of thing), but it would be nice to introduce a simpler way for commands to "inherit" all the common parameters between it and its caller (which haven't been overridden).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i often create a hash earlier in the script and then modify it based on conditions.

[string]$Framework = "core",

[Parameter(ParameterSetName="BuildOne")]
[ValidateSet("3","4","5")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "6" be an option here? I feel like equating 5 with Core might prove confusing. We should probably have a comment to document it at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and we should then remove the $Framework parameter and handle that internally since we know which ps version is core and which is full

@JamesWTruher JamesWTruher changed the title update, simplify, and consolidate build scripts WIP: update, simplify, and consolidate build scripts Oct 17, 2018
Copy link
Contributor Author

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like i've broken the CI - I'm working on a fix, but it's not ready yet


RUN apt update -qq && \
cd / && \
git clone https://github.com/JamesWTruher/PSScriptAnalyzer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it should :/

@JamesWTruher JamesWTruher force-pushed the buildscripts branch 3 times, most recently from 75891d8 to 67ceb40 Compare October 18, 2018 19:58
@JamesWTruher JamesWTruher force-pushed the buildscripts branch 2 times, most recently from fcd5f2d to 14e0fdc Compare October 18, 2018 23:42
Add additional verbose statements for debugging
@JamesWTruher
Copy link
Contributor Author

there's a couple of good suggestions here which I would like to put in a follow-on PR

@JamesWTruher JamesWTruher changed the title WIP: update, simplify, and consolidate build scripts Update, simplify, and consolidate build scripts Oct 19, 2018
@JamesWTruher
Copy link
Contributor Author

@bergmeister - CI problems addressed

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some minor comments to be addressed please. What would be good to know is why the pragmas (psv4) needed to be adapted (why was it working before?)
Otherwise it looks good, let;s get it merged after that :-)

$docsPath = Join-Path $projectRoot docs
$markdownDocsPath = Join-Path $docsPath markdown
$outputDocsPath = Join-Path $destinationDir en-US
$requiredVersionOfplatyPS = 0.9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update platyPs to 0.12.0 but this can be another PR after that
https://twitter.com/xvorsx/status/1053495983588265991?s=19

$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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out code

{
Write-Verbose -verbose "platyPS not found, installing"
Install-Module -Force -Name platyPS -Scope CurrentUser
# throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out code.

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be OK with showing only the Describe output but then Pester does not show the summary any more, which we definitely need if we want to avoid scrolling through all test results when running locally. Can we therefore use the Describe,Summary option please

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments to be address please but looks good overall. Can you please comment on why the conditional compilation had to change for WMF4 (why was it working before but not now any more?)?

$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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out line

$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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out line

{
Write-Verbose -verbose "platyPS not found, installing"
Install-Module -Force -Name platyPS -Scope CurrentUser
# throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented out line

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the Summary option to -Show would be useful

Suggested change
$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")

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the Describe,Summary option to -Show would be useful

Suggested change
$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")

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the Describe,Summary option to -Show would be useful

Suggested change
$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")

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments to be addressed please but looks good overall, GitHub had a glitch, therefore some comments are duplicated. Can you please comment on why the conditional compilation had to change for WMF4 (why was it working before but not now any more?)? After this PR we also need to update ReleaseMaker.psm1

…nalyzer into buildscripts

use HEAD due to newer sdk version
# Conflicts:
#	global.json
@bergmeister
Copy link
Collaborator

This is good enough to merge, we plan to have follow up PRs that tweak this and also adapt ReleaseMaker.psm1 for that. It's better to merge early to avoid conflicts

@bergmeister bergmeister merged commit 1eb9a01 into PowerShell:development Oct 23, 2018
bergmeister pushed a commit to bergmeister/PSScriptAnalyzer that referenced this pull request Mar 22, 2019
* consolidate build of script analyzer into module

Require any 2.1 sdk for building, this way we can build with the same sdk as PowerShell core

* Have git ignore vim swap files and the test results file

* Only special case linux for the customized rule tests

* Update to build scripts.

To build for core, simply type ./build,
to build all flavors and documentation type ./build -all.
You can now run tests as well via ./build -Test.

* Modify readme to match new build instructions

* Add ubuntu16 docker file to build scripts

* change to use psversion rather than analyzerversion

because it's really about the version of PS, not the analyzer

* Add copyright banners to script and module

* Fix repo to point to the official repo

* Update appveyor scripts to use new build script

* Forcing installation of platyPS if not found when building documentation

* Be sure to skip uses of TypeDefinitionAst on both PSV3 and PSV4

* Modified logic to not build full on non-Windows

Add additional verbose statements for debugging

* fix issue with incorrect build configuration

When simplifying to use only psversion, add back the 'PSV' prolog to configuration

* reduce build matrix to accellerate CI testing

* Revert "reduce build matrix to accellerate CI testing"

This reverts commit b3018ea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants