diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index d681191c8..5469c54a5 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -31,24 +31,43 @@ jobs: shell: pwsh - name: Build - run: ./build.ps1 -Configuration Release -All + run: ./build.ps1 -Configuration Release -All -Verbose shell: pwsh - name: Package - run: ./build.ps1 -BuildNupkg + run: ./build.ps1 -BuildNupkg -Verbose shell: pwsh - name: Test - run: ./build.ps1 -Test + run: ./build.ps1 -Test -Verbose shell: pwsh - name: Test Windows PowerShell + if: matrix.os == 'windows-latest' run: | Install-Module Pester -Scope CurrentUser -Force -SkipPublisherCheck - ./build.ps1 -Test - if: matrix.os == 'windows-latest' + ./build.ps1 -Test -Verbose shell: powershell + - name: Download PowerShell install script + uses: actions/checkout@v4 + with: + repository: PowerShell/PowerShell + path: pwsh + sparse-checkout: tools/install-powershell.ps1 + sparse-checkout-cone-mode: false + + - name: Install preview + continue-on-error: true + run: ./pwsh/tools/install-powershell.ps1 -Preview -Destination ./preview + shell: pwsh + + - name: Test preview + run: | + $PwshPreview = if ($isWindows) { "./preview/pwsh.exe" } else { "./preview/pwsh" } + ./build.ps1 -Test -WithPowerShell:$PwshPreview -Verbose + shell: pwsh + - name: Upload build artifacts uses: actions/upload-artifact@v4 if: always() diff --git a/build.ps1 b/build.ps1 index bbc6c505a..d6d661bf6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -32,6 +32,7 @@ param( [Parameter(ParameterSetName='Test')] [switch] $InProcess, + [string] $WithPowerShell, [Parameter(ParameterSetName='BuildAll')] [switch] $Catalog, @@ -85,7 +86,12 @@ END { Start-CreatePackage } "Test" { - Test-ScriptAnalyzer -InProcess:$InProcess + $testArgs = @{ + InProcess = $InProcess + WithPowerShell = $WithPowerShell + Verbose = $verboseWanted + } + Test-ScriptAnalyzer @testArgs return } default { diff --git a/build.psm1 b/build.psm1 index ba839fab1..98a87af0d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -308,7 +308,10 @@ function New-Catalog function Test-ScriptAnalyzer { [CmdletBinding()] - param ( [switch] $InProcess ) + param ( + [switch] $InProcess, + [string] $WithPowerShell + ) END { # versions 3 and 4 don't understand versioned module paths, so we need to rename the directory of the version to @@ -347,11 +350,19 @@ function Test-ScriptAnalyzer $analyzerPsd1Path = Join-Path -Path $script:destinationDir -ChildPath "$analyzerName.psd1" $scriptBlock = [scriptblock]::Create("Import-Module '$analyzerPsd1Path'; Invoke-Pester -Path $testScripts -CI") if ( $InProcess ) { + Write-Verbose "Testing with PowerShell $($PSVersionTable.PSVersion)" & $scriptBlock } + elseif ( $WithPowerShell ) { + $pwshVersion = & $WithPowerShell --version + Write-Verbose "Testing with $pwshVersion" + & $WithPowerShell -Command $scriptBlock + } else { $powershell = (Get-Process -id $PID).MainModule.FileName - & ${powershell} -NoProfile -Command $scriptBlock + $pwshVersion = & $powershell --version + Write-Verbose "Testing with $pwshVersion" + & $powershell -NoProfile -Command $scriptBlock } } finally { @@ -555,6 +566,13 @@ function Get-DotnetExe $script:DotnetExe = $dotnetHuntPath return $dotnetHuntPath } + + $dotnetHuntPath = "C:\Program Files\dotnet\dotnet.exe" + Write-Verbose -Verbose "checking Windows $dotnetHuntPath" + if ( test-path $dotnetHuntPath ) { + $script:DotnetExe = $dotnetHuntPath + return $dotnetHuntPath + } } else { $dotnetHuntPath = "$HOME/.dotnet/dotnet"