diff --git a/.build.ps1 b/.build.ps1 index 607e467..bb53777 100644 --- a/.build.ps1 +++ b/.build.ps1 @@ -86,7 +86,7 @@ task module version, markdown, help, { CompanyName = 'Roman Kuzmin' Copyright = '(c) Roman Kuzmin' Description = 'Build and test automation in PowerShell' - PowerShellVersion = '2.0' + PowerShellVersion = '3.0' AliasesToExport = 'Invoke-Build', 'Build-Checkpoint', 'Build-Parallel' PrivateData = @{ PSData = @{ @@ -114,7 +114,7 @@ task nuget module, { # summary and description $text = @' Invoke-Build is a build and test automation tool which invokes tasks defined in -PowerShell v2.0+ scripts. It is similar to psake but arguably easier to use and +PowerShell v3.0+ scripts. It is similar to psake but arguably easier to use and more powerful. It is complete, bug free, well covered by tests. '@ diff --git a/.github/workflows/test2.yml b/.github/workflows/test2.yml deleted file mode 100644 index 68706aa..0000000 --- a/.github/workflows/test2.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: test2 - -on: - workflow_dispatch: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test2: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - name: boot - shell: powershell - run: ./Invoke-Build.ps1 boot - - name: test - shell: cmd - run: powershell -Version 2 ./Invoke-Build.ps1 . Tests/.build.ps1 diff --git a/Invoke-Build.ps1 b/Invoke-Build.ps1 index d06b377..684c7a8 100644 --- a/Invoke-Build.ps1 +++ b/Invoke-Build.ps1 @@ -235,9 +235,12 @@ function Get-BuildSynopsis([Parameter(Mandatory=1)]$Task, $Hash=${*}.H) { function Use-BuildEnv([Parameter(Mandatory=1)][hashtable]$Env, [Parameter(Mandatory=1)][scriptblock]$Script) { ${private:*e} = @{} ${private:*s} = $Script + function *set($n, $v) { + [Environment]::SetEnvironmentVariable($n, $(if ($null -eq $v) {[System.Management.Automation.Language.NullString]::Value} else {$v})) + } foreach($_ in $Env.GetEnumerator()) { ${*e}[$_.Key] = [Environment]::GetEnvironmentVariable($_.Key) - [Environment]::SetEnvironmentVariable($_.Key, $_.Value) + *set $_.Key $_.Value } Remove-Variable Env, Script try { @@ -245,7 +248,7 @@ function Use-BuildEnv([Parameter(Mandatory=1)][hashtable]$Env, [Parameter(Mandat } finally { foreach($_ in ${*e}.GetEnumerator()) { - [Environment]::SetEnvironmentVariable($_.Key, $_.Value) + *set $_.Key $_.Value } } } diff --git a/README.md b/README.md index 49ac3b4..35b5570 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Build Automation in PowerShell Invoke-Build is a build and test automation tool which invokes tasks defined in -PowerShell v2.0+ scripts. It is similar to psake but arguably easier to use and +PowerShell v3.0+ scripts. It is similar to psake but arguably easier to use and more powerful. It is complete, bug free, well covered by tests. In addition to basic task processing the engine supports diff --git a/Release-Notes.md b/Release-Notes.md index c9df451..7d22dd1 100644 --- a/Release-Notes.md +++ b/Release-Notes.md @@ -1,6 +1,14 @@ # Invoke-Build Release Notes -`Show-BuildGraph.ps1` - use viz-3.9.0 +## v5.12.0 + +Stop supporting and testing PowerShell v2.0 (unlikely practical). + +Fix `Use-BuildEnv` potential issues in PowerShell 7.5. + +Fix `ib` dotnet tool similar potential issues. + +`Show-BuildGraph.ps1` - use viz-3.11.0 ## v5.11.3 diff --git a/Show-BuildGraph.ps1 b/Show-BuildGraph.ps1 index e9b04f8..d9439ea 100644 --- a/Show-BuildGraph.ps1 +++ b/Show-BuildGraph.ps1 @@ -1,5 +1,5 @@ <#PSScriptInfo -.VERSION 1.0.8 +.VERSION 1.0.9 .AUTHOR Roman Kuzmin .COPYRIGHT (c) Roman Kuzmin .TAGS Invoke-Build, Graphviz @@ -102,7 +102,7 @@ else { $jsUrl = 'file:///' + $app.Source.Replace('\', '/') } else { - $jsUrl = 'https://github.com/mdaines/viz-js/releases/download/release-viz-3.9.0/viz-standalone.js' + $jsUrl = 'https://github.com/mdaines/viz-js/releases/download/release-viz-3.11.0/viz-standalone.js' } } diff --git a/Tests/.build.ps1 b/Tests/.build.ps1 index fed3096..cf6c443 100644 --- a/Tests/.build.ps1 +++ b/Tests/.build.ps1 @@ -196,9 +196,7 @@ task TestSelfAlias { } # Synopsis: Test a build invoked from a background job just to be sure it works. -task TestStartJob -If { - !($PSVersionTable.PSVersion.Major -eq 2 -and $env:GITHUB_ACTION) -and !($Host.Name -eq 'FarHost') -} { +task TestStartJob -If {$Host.Name -ne 'FarHost'} { $job = Start-Job { Invoke-Build . $args[0] } -ArgumentList "$BuildRoot\Dynamic.build.ps1" $log = Wait-Job $job | Receive-Job Remove-Job $job diff --git a/Tests/Build-Parallel/Parallel.test.ps1 b/Tests/Build-Parallel/Parallel.test.ps1 index 8b1dca3..9566b49 100644 --- a/Tests/Build-Parallel/Parallel.test.ps1 +++ b/Tests/Build-Parallel/Parallel.test.ps1 @@ -209,7 +209,7 @@ task OmittedBuildParameterFile { # Covers #27, [IB] was not found before loading IB. task ParallelEmptyRun { ($r = Invoke-PowerShell -NoProfile -Command 'Build-Parallel.ps1 -Result r; $r.GetType().Name') - equals $r $(if ($PSVersionTable.PSVersion.Major -eq 2) {'Hashtable'} else {'PSCustomObject'}) + equals $r PSCustomObject } # Covers #93 with the new switch FailHard. diff --git a/Tests/Convert-psake/Convert-psake.test.ps1 b/Tests/Convert-psake/Convert-psake.test.ps1 index f8db808..34dec21 100644 --- a/Tests/Convert-psake/Convert-psake.test.ps1 +++ b/Tests/Convert-psake/Convert-psake.test.ps1 @@ -4,6 +4,6 @@ #> # Synopsis: Invoke Convert-psake.ps1. Output is to be compared. -task Convert-psake -If ($PSVersionTable.PSVersion.Major -ge 3) { +task Convert-psake { Convert-psake default.ps1 -Invoke -Synopsis } diff --git a/Tests/CountKeysValues/.test.ps1 b/Tests/CountKeysValues/.test.ps1 index 3bb16b3..218505c 100644 --- a/Tests/CountKeysValues/.test.ps1 +++ b/Tests/CountKeysValues/.test.ps1 @@ -30,7 +30,7 @@ task Show-BuildTree { } # used to out funny parameters and environment -task WhatIf -If ($PSVersionTable.PSVersion.Major -ne 2) { +task WhatIf { ($r = Invoke-Build -WhatIf | Out-String) $r = Remove-Ansi ($r -replace ' ' -replace '\r?\n', '|') assert ($r.Contains('|Parameters:|[Object]Count|[Object]Keys|[Object]Values|Environment:|Count,Keys,Values|')) @@ -78,7 +78,7 @@ task Show-BuildGraph -If (!(Test-Unix) -and !$env:GITHUB_ACTION) { } # used to generate just `values` -task New-VSCodeTask -If ($PSVersionTable.PSVersion.Major -ne 2) { +task New-VSCodeTask { New-VSCodeTask.ps1 $r = (Get-Content .vscode/tasks.json | Out-String) -replace '\s+', ' ' assert ($r.Contains('"label": "count"')) diff --git a/Tests/Exec.test.ps1 b/Tests/Exec.test.ps1 index 3f3523b..ab6bd35 100644 --- a/Tests/Exec.test.ps1 +++ b/Tests/Exec.test.ps1 @@ -5,8 +5,6 @@ Import-Module .\Tools -$PSv3 = $PSVersionTable.PSVersion.Major -ge 3 - task ExecWorksCode0 { $r = exec { if (Test-Unix) { @@ -83,7 +81,7 @@ task ExecShouldUseGlobalLastExitCode { } # New switch Echo, #176 #179 -task Echo1 -If $PSv3 { +task Echo1 { # different kind variables $env:SOME_VAR = 'SOME_VAR' $script:foo = 'foo' @@ -142,7 +140,7 @@ task ErrorMessage { } # #192 -task Echo2 -If $PSv3 { +task Echo2 { function *Write { $args[1] } #! 1 line, make 1 leading and trailing space @@ -215,7 +213,7 @@ task StdErrBadCommand { } # Echo properties, #221 -task EchoProperties -If $PSv3 { +task EchoProperties { Set-Alias Write-Build Write-Build-Fake function Write-Build-Fake($Color, $Text) {$Text} diff --git a/Tests/Issues/217-bad-error-on-unknown-parameter/217.test.ps1 b/Tests/Issues/217-bad-error-on-unknown-parameter/217.test.ps1 index d6ea9b3..9e886c8 100644 --- a/Tests/Issues/217-bad-error-on-unknown-parameter/217.test.ps1 +++ b/Tests/Issues/217-bad-error-on-unknown-parameter/217.test.ps1 @@ -16,17 +16,11 @@ task UnknownParameter { # parameter positions after IB $b1, $b2, $b3 = Get-ParameterPosition - if ($PSVersionTable.PSVersion.Major -eq 2) { - equals $b1 $a1 - equals $b2 $a2 - equals $b3 $a3 - } - else { - # shifted +2 on every call - equals $b1 ($a1 + 2) - equals $b2 ($a2 + 2) - equals $b3 ($a3 + 2) - } + + # shifted +2 on every call + equals $b1 ($a1 + 2) + equals $b2 ($a2 + 2) + equals $b3 ($a3 + 2) } function Get-ParameterPosition { diff --git a/Tests/New-VSCodeTask/.test.ps1 b/Tests/New-VSCodeTask/.test.ps1 index 3d40ef8..dd6dd2a 100644 --- a/Tests/New-VSCodeTask/.test.ps1 +++ b/Tests/New-VSCodeTask/.test.ps1 @@ -3,8 +3,6 @@ Tests New-VSCodeTask.ps1 #> -if ($PSVersionTable.PSVersion.Major -eq 2) {return task skipV2} - Import-Module ..\Tools Set-StrictMode -Off diff --git a/Tests/TaskHelp.test.ps1 b/Tests/TaskHelp.test.ps1 index 37ccb7d..2b4bcf9 100644 --- a/Tests/TaskHelp.test.ps1 +++ b/Tests/TaskHelp.test.ps1 @@ -66,7 +66,7 @@ task Test { # Use this repo build script, test code and tree processing. # 2024-02-29 v2 started to fail, skip. -task UndocumentedStuff -If ($PSVersionTable.PSVersion.Major -ge 3) { +task UndocumentedStuff { # call by WhatIf Invoke-Build -File ../.build.ps1 -WhatIf @@ -190,12 +190,10 @@ task IfInputsOutputs { # call and test $r = Show-TaskHelp t1 z.ps1 -Format {$args[0]} - if ($PSVersionTable.PSVersion.Major -ge 3) { - equals $r.Parameters.Count 3 - equals $r.Parameters[0].Name If - equals $r.Parameters[1].Name Inputs - equals $r.Parameters[2].Name Outputs - } + equals $r.Parameters.Count 3 + equals $r.Parameters[0].Name If + equals $r.Parameters[1].Name Inputs + equals $r.Parameters[2].Name Outputs Remove-Item z.ps1 } diff --git a/ib/Program.cs b/ib/Program.cs index 80e8e63..a45176e 100644 --- a/ib/Program.cs +++ b/ib/Program.cs @@ -75,8 +75,9 @@ If the environment variable `pwsh` is defined it is used as pwsh. return 0; } - var app = Environment.GetEnvironmentVariable("pwsh") - ?? (options.UsePwsh || Environment.OSVersion.Platform != PlatformID.Win32NT ? "pwsh" : "powershell"); + var app = Environment.GetEnvironmentVariable("pwsh"); + if (string.IsNullOrEmpty(app)) + app = options.UsePwsh || Environment.OSVersion.Platform != PlatformID.Win32NT ? "pwsh" : "powershell"; var root = Path.GetDirectoryName(typeof(Program).Assembly.Location); var ib = Path.Combine(root, "../../../InvokeBuild/Invoke-Build.ps1");