Skip to content

Commit

Permalink
Fix dotnet 9 potential issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nightroman committed Nov 20, 2024
1 parent 861a8c5 commit fc3c7e0
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down Expand Up @@ -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.
'@

Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/test2.yml

This file was deleted.

7 changes: 5 additions & 2 deletions Invoke-Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,20 @@ 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 {
& ${*s}
}
finally {
foreach($_ in ${*e}.GetEnumerator()) {
[Environment]::SetEnvironmentVariable($_.Key, $_.Value)
*set $_.Key $_.Value
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion Release-Notes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions Show-BuildGraph.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#PSScriptInfo
.VERSION 1.0.8
.VERSION 1.0.9
.AUTHOR Roman Kuzmin
.COPYRIGHT (c) Roman Kuzmin
.TAGS Invoke-Build, Graphviz
Expand Down Expand Up @@ -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'
}
}

Expand Down
4 changes: 1 addition & 3 deletions Tests/.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/Build-Parallel/Parallel.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Convert-psake/Convert-psake.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions Tests/CountKeysValues/.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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|'))
Expand Down Expand Up @@ -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"'))
Expand Down
8 changes: 3 additions & 5 deletions Tests/Exec.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

Import-Module .\Tools

$PSv3 = $PSVersionTable.PSVersion.Major -ge 3

task ExecWorksCode0 {
$r = exec {
if (Test-Unix) {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
16 changes: 5 additions & 11 deletions Tests/Issues/217-bad-error-on-unknown-parameter/217.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions Tests/New-VSCodeTask/.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Tests New-VSCodeTask.ps1
#>

if ($PSVersionTable.PSVersion.Major -eq 2) {return task skipV2}

Import-Module ..\Tools
Set-StrictMode -Off

Expand Down
12 changes: 5 additions & 7 deletions Tests/TaskHelp.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions ib/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit fc3c7e0

Please sign in to comment.