Skip to content

Commit a5f6597

Browse files
Refactor Action-Test workflow: enhance version matrix to include 'null' and 'latest'; improve version verification logic for better clarity and error handling.
1 parent eea5f4d commit a5f6597

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

.github/workflows/Action-Test.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,42 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, windows-latest, macOS-latest]
25-
version: ['', '7.4.7', '7.5.0']
25+
version: ['', null, 'latest', '7.4.7', '7.5.0'] # '' → should resolve to latest
2626
runs-on: ${{ matrix.os }}
27-
name: ${{ matrix.os }} - ${{ matrix.version }}
27+
name: ${{ matrix.os }} - ${{ matrix.version == '' && 'latest' || matrix.version }}
2828
steps:
29-
# Need to check out as part of the test, as its a local action
29+
# 1. Checkout the repo so the local action is available
3030
- name: Checkout repo
3131
uses: actions/checkout@v4
3232

33+
# 2. Run the action under test
3334
- name: Action-Test
3435
uses: ./
3536
with:
3637
Version: ${{ matrix.version }}
3738

38-
- name: Test version
39+
# 3. Verify the installed PowerShell version
40+
- name: Verify installed version
3941
shell: pwsh
4042
run: |
41-
$PSVersionTable | Format-Table -AutoSize
42-
if ($PSVersionTable.PSVersion -ne '${{ matrix.version }}') {
43-
throw "Failed to install the expected version"
43+
# Requested version that came from the matrix
44+
$requested = '${{ matrix.version }}'
45+
46+
# When empty / 'null' / 'latest' → resolve to latest stable release
47+
if ([string]::IsNullOrWhiteSpace($requested) -or
48+
$requested.Trim().ToLower() -in @('latest','null')) {
49+
50+
$requested = (Invoke-RestMethod `
51+
-Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'
52+
).tag_name.TrimStart('v')
53+
Write-Host "Resolved 'latest' → $requested"
54+
}
55+
56+
# Actual version installed by the action
57+
$installed = ($PSVersionTable.PSVersion).ToString()
58+
Write-Host "Installed PowerShell version: $installed"
59+
Write-Host "Expected PowerShell version: $requested"
60+
61+
if ($installed -ne $requested) {
62+
throw "Failed: expected $requested but got $installed"
4463
}

0 commit comments

Comments
 (0)