Skip to content

Test PowerShell Preview in CI #2070

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

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ param(

[Parameter(ParameterSetName='Test')]
[switch] $InProcess,
[string] $WithPowerShell,

[Parameter(ParameterSetName='BuildAll')]
[switch] $Catalog,
Expand Down Expand Up @@ -85,7 +86,12 @@ END {
Start-CreatePackage
}
"Test" {
Test-ScriptAnalyzer -InProcess:$InProcess
$testArgs = @{
InProcess = $InProcess
WithPowerShell = $WithPowerShell
Verbose = $verboseWanted
}
Test-ScriptAnalyzer @testArgs
return
}
default {
Expand Down
22 changes: 20 additions & 2 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down