From a874e1385e37fac8a3675833689f2853c1b28d02 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 4 May 2020 09:43:19 -0400 Subject: [PATCH] Prevent install of Pester v5 --- CI/PS-CI.ps1 | 110 ++++++++++++++++++++++---------------------- appveyor.yml | 12 ++--- azure-pipelines.yml | 8 ++-- 3 files changed, 66 insertions(+), 64 deletions(-) diff --git a/CI/PS-CI.ps1 b/CI/PS-CI.ps1 index b37a8a4..5d6e0c9 100644 --- a/CI/PS-CI.ps1 +++ b/CI/PS-CI.ps1 @@ -1,4 +1,4 @@ -[cmdletbinding(DefaultParameterSetName='Scope')] +[cmdletbinding(DefaultParameterSetName = 'Scope')] Param( [Parameter(Mandatory = $true, ParameterSetName = 'ModulePath')] [ValidateNotNullOrEmpty()] @@ -10,7 +10,7 @@ Param( [string] $Scope = 'CurrentUser', - [Parameter(Mandatory=$true, ParameterSetName = 'PreCheckOnly')] + [Parameter(Mandatory = $true, ParameterSetName = 'PreCheckOnly')] [switch]$PreCheckOnly, [Parameter(ParameterSetName = 'ModulePath')] [Parameter(ParameterSetName = 'Scope')] @@ -30,7 +30,7 @@ Param( ) Function Show-Warning { param( - [Parameter(Position=0,ValueFromPipeline=$true)] + [Parameter(Position = 0, ValueFromPipeline = $true)] $message ) process { @@ -49,11 +49,11 @@ if (-not $psdpath -or $psdpath.count -gt 1) { throw "Did not find a unique PSD file " } else { - try {$null = Test-ModuleManifest -Path $psdpath -ErrorAction stop} - catch {throw $_ ; return} - $ModuleName = $psdpath.Name -replace '\.psd1$' , '' - $Settings = $(& ([scriptblock]::Create(($psdpath | Get-Content -Raw)))) - $approvedVerbs = Get-Verb | Select-Object -ExpandProperty verb + try { $null = Test-ModuleManifest -Path $psdpath -ErrorAction stop } + catch { throw $_ ; return } + $ModuleName = $psdpath.Name -replace '\.psd1$' , '' + $Settings = $(& ([scriptblock]::Create(($psdpath | Get-Content -Raw)))) + $approvedVerbs = Get-Verb | Select-Object -ExpandProperty verb $script:warningfile = Join-Path -Path $pwd -ChildPath "warnings.txt" } @@ -63,7 +63,7 @@ if (-not $SkipPreChecks) { #Check files in the manifest are present foreach ($file in $Settings.FileList) { if (-not (Test-Path $file)) { - Show-Warning "File $file in the manifest file list is not present" + Show-Warning "File $file in the manifest file list is not present" } } @@ -71,7 +71,7 @@ if (-not $SkipPreChecks) { # its name and any alias names in the manifest; function should have a param block and help should be in an MD file # We will want a regex which captures from "function verb-noun {" to its closing "}" # need to match each { to a } - $reg is based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis - $reg = [Regex]::new(@" + $reg = [Regex]::new(@" function\s*[-\w]+\s*{ # The function name and opening '{' (?: [^{}]+ # Match all non-braces @@ -84,56 +84,56 @@ if (-not $SkipPreChecks) { } # Functions closing '}' "@, 57) # 57 = compile,multi-line ignore case and white space. foreach ($file in (Get-Item .\Public\*.ps1)) { - $name = $file.name -replace(".ps1","") - if ($name -notmatch ("(\w+)-\w+")) {Show-Warning "$name in the public folder is not a verb-noun name"} - elseif ($Matches[1] -notin $approvedVerbs) {Show-Warning "$name in the public folder does not start with an approved verb"} - if(-not ($Settings.FunctionsToExport -ceq $name)) { + $name = $file.name -replace (".ps1", "") + if ($name -notmatch ("(\w+)-\w+")) { Show-Warning "$name in the public folder is not a verb-noun name" } + elseif ($Matches[1] -notin $approvedVerbs) { Show-Warning "$name in the public folder does not start with an approved verb" } + if (-not ($Settings.FunctionsToExport -ceq $name)) { Show-Warning ('File {0} in the public folder does not match an exported function in the manifest' -f $file.name) } else { $fileContent = Get-Content $file -Raw - $m = $reg.Matches($fileContent) - if ($m.Count -eq 0) {Show-Warning ('Could not find {0} function in {1}' -f $name, $file.name); continue} - elseif ($m.Count -ge 2) {Show-Warning ('Multiple functions in {0}' -f $item.name) ; Continue} + $m = $reg.Matches($fileContent) + if ($m.Count -eq 0) { Show-Warning ('Could not find {0} function in {1}' -f $name, $file.name); continue } + elseif ($m.Count -ge 2) { Show-Warning ('Multiple functions in {0}' -f $item.name) ; Continue } elseif ($m[0] -imatch "^\function\s" -and - $m[0] -cnotmatch "^\w+\s+$name") {Show-Warning ('function name does not match file name for {0}' -f $file.name)} + $m[0] -cnotmatch "^\w+\s+$name") { Show-Warning ('function name does not match file name for {0}' -f $file.name) } #$m[0] runs form the f of function to its final } -find the section up to param, check for aliases & comment-based help - $m2 = [regex]::Match($m[0],"^.*?param",17) # 17 = multi-line, ignnore case - if (-not $m2.Success) {Show-Warning "function $name has no param() block"} + $m2 = [regex]::Match($m[0], "^.*?param", 17) # 17 = multi-line, ignnore case + if (-not $m2.Success) { Show-Warning "function $name has no param() block" } else { if ($m2.value -match "(?