Skip to content

Commit 2919222

Browse files
🩹 [CI]: Refactor Get-TestSuites workflow to include SkipTests input and separate outputs for SourceCode and Module test suites
1 parent 38fd0d5 commit 2919222

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

‎.github/workflows/CI.yml‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,25 @@ permissions:
6969
statuses: write # to update the status of the workflow from linter
7070

7171
jobs:
72+
Get-TestSuites:
73+
name: Get-TestSuites
74+
uses: ./.github/workflows/Get-TestSuites.yml
75+
with:
76+
SkipTests: ${{ inputs.SkipTests }}
77+
Debug: ${{ inputs.Debug }}
78+
Prerelease: ${{ inputs.Prerelease }}
79+
Verbose: ${{ inputs.Verbose }}
80+
Version: ${{ inputs.Version }}
81+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
82+
7283
Test-SourceCode:
7384
name: Test-SourceCode
85+
needs:
86+
- Get-TestSuites
7487
strategy:
7588
fail-fast: false
7689
matrix:
77-
include:
78-
- OSName: Linux
79-
RunsOn: ubuntu-latest
80-
- OSName: macOS
81-
RunsOn: macos-latest
82-
- OSName: Windows
83-
RunsOn: windows-latest
90+
include: ${{ fromJson(needs.Get-TestSuites.outputs.SourceCodeTestSuites) }}
8491
uses: ./.github/workflows/Test-SourceCode.yml
8592
with:
8693
RunsOn: ${{ matrix.RunsOn }}
@@ -143,16 +150,6 @@ jobs:
143150
Version: ${{ inputs.Version }}
144151
WorkingDirectory: ${{ inputs.WorkingDirectory }}
145152

146-
Get-TestSuites:
147-
name: Get-TestSuites
148-
uses: ./.github/workflows/Get-TestSuites.yml
149-
with:
150-
Debug: ${{ inputs.Debug }}
151-
Prerelease: ${{ inputs.Prerelease }}
152-
Verbose: ${{ inputs.Verbose }}
153-
Version: ${{ inputs.Version }}
154-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
155-
156153
Test-ModuleLocal:
157154
name: ${{ matrix.TestName }}
158155
if: ${{ needs.Build-Module.result == 'success' && !cancelled() }}
@@ -162,7 +159,7 @@ jobs:
162159
strategy:
163160
fail-fast: false
164161
matrix:
165-
include: ${{ fromJson(needs.Get-TestSuites.outputs.TestSuites) }}
162+
include: ${{ fromJson(needs.Get-TestSuites.outputs.ModuleTestSuites) }}
166163
uses: ./.github/workflows/Test-ModuleLocal.yml
167164
secrets: inherit
168165
with:

‎.github/workflows/Get-TestSuites.yml‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Get-TestSuites
33
on:
44
workflow_call:
55
inputs:
6+
SkipTests:
7+
type: string
8+
description: Defines what types of tests to skip. Allowed values are 'All', 'SourceCode', 'Module', 'None', 'macOS', 'Windows', 'Linux'.
9+
required: false
10+
default: None
611
Debug:
712
type: boolean
813
description: Enable debug output.
@@ -30,9 +35,12 @@ on:
3035
default: '.'
3136

3237
outputs:
33-
TestSuites:
34-
description: The test suites to run.
35-
value: ${{ jobs.Get-TestSuites.outputs.TestSuites }}
38+
SourceCodeTestSuites:
39+
description: Source Code test suites to run.
40+
value: ${{ jobs.Get-TestSuites.outputs.SourceCodeTestSuites }}
41+
ModuleTestSuites:
42+
description: Module test suites to run.
43+
value: ${{ jobs.Get-TestSuites.outputs.ModuleTestSuites }}
3644

3745
permissions:
3846
contents: read # to checkout the repo
@@ -42,14 +50,17 @@ jobs:
4250
name: Get-TestSuites
4351
runs-on: ubuntu-latest
4452
outputs:
45-
TestSuites: ${{ fromJson(steps.Get-TestSuites.outputs.result).TestSuites }}
53+
SourceCodeTestSuites: ${{ fromJson(steps.Get-TestSuites.outputs.result).SourceCodeTestSuites }}
54+
ModuleTestSuites: ${{ fromJson(steps.Get-TestSuites.outputs.result).ModuleTestSuites }}
4655
steps:
4756
- name: Checkout Code
4857
uses: actions/checkout@v4
4958

5059
- name: Get-TestSuites
5160
uses: PSModule/GitHub-Script@v1
5261
id: Get-TestSuites
62+
env:
63+
PSMODULE_GET_TESTSUITES_INPUT_SkipTests: ${{ inputs.SkipTests }}
5364
with:
5465
ShowOutput: true
5566
Debug: ${{ inputs.Debug }}
@@ -60,9 +71,9 @@ jobs:
6071
Script: |
6172
# Define test configurations as an array of hashtables.
6273
$osConfigs = @(
63-
@{ runson = 'ubuntu-latest'; name = 'Linux' }
64-
@{ runson = 'macos-latest'; name = 'macOS' }
65-
@{ runson = 'windows-latest'; name = 'Windows' }
74+
@{ RunsOn = 'ubuntu-latest'; OSName = 'Linux' }
75+
@{ RunsOn = 'macos-latest'; OSName = 'macOS' }
76+
@{ RunsOn = 'windows-latest'; OSName = 'Windows' }
6677
)
6778
6879
# Locate the tests directory.
@@ -113,17 +124,24 @@ jobs:
113124
foreach ($item in $testItems) {
114125
foreach ($osConfig in $osConfigs) {
115126
[pscustomobject]@{
116-
RunsOn = $osConfig.runson
117-
OSName = $osConfig.name
127+
RunsOn = $osConfig.RunsOn
128+
OSName = $osConfig.OSName
118129
TestPath = Resolve-Path -Path $item.FullName -Relative
119130
TestName = $item.BaseName
120131
}
121132
}
122133
}
123134
}
124135
125-
# (Optional) Display the generated matrix in a table for verification.
126-
$testSuites | Format-Table -AutoSize
136+
# Create separate outputs for source code tests (OS only) and module tests (existing detailed output)
137+
$sourceCodeTestSuites = $osConfigs | Select-Object -Property RunsOn, OSName -Unique
138+
139+
# Display the generated matrices for verification.
140+
Write-Host "Source Code Test Suites:"
141+
$sourceCodeTestSuites | Format-Table -AutoSize | Out-String
142+
Write-Host "Module Test Suites:"
143+
$testSuites | Format-Table -AutoSize | Out-String
127144
128-
# Pass the final object to GitHub Actions output.
129-
Set-GitHubOutput -Name TestSuites -Value $testSuites
145+
# Pass the final objects to GitHub Actions output.
146+
Set-GitHubOutput -Name SourceCodeTestSuites -Value $sourceCodeTestSuites
147+
Set-GitHubOutput -Name ModuleTestSuites -Value $testSuites

0 commit comments

Comments
 (0)