Skip to content

Commit 6c638bd

Browse files
🩹 [Refactor]: Simplify test configuration and improve workflow readability in Get-TestSuites and Test-ModuleLocal workflows
1 parent bc57e19 commit 6c638bd

File tree

3 files changed

+49
-63
lines changed

3 files changed

+49
-63
lines changed

‎.github/workflows/Get-TestSuites.yml

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,62 +53,41 @@ jobs:
5353
ShowOutput: true
5454
WorkingDirectory: ${{ inputs.Path }}
5555
Script: |
56-
# Define your test configurations
57-
$testConfigs = @(
58-
@{
59-
OS = 'ubuntu-latest'
60-
Shells = 'pwsh'
61-
Path = '' # to be filled later
62-
},
63-
@{
64-
OS = 'macos-latest'
65-
Shells = 'pwsh'
66-
Path = ''
67-
},
68-
@{
69-
OS = 'windows-latest'
70-
Shells = 'pwsh'
71-
Path = ''
72-
},
73-
@{
74-
OS = 'windows-latest'
75-
Shells = 'powershell'
76-
Path = ''
77-
}
56+
# Define test configurations as an array of hashtables.
57+
$osConfigs = @(
58+
@{ runson = 'ubuntu-latest'; name = 'Linux' }
59+
@{ runson = 'macos-latest'; name = 'macOS' }
60+
@{ runson = 'windows-latest'; name = 'Windows' }
7861
)
7962
80-
# Locate the tests directory
81-
$testsPath = Resolve-Path 'tests' | Select-Object -ExpandProperty Path
82-
if (-not (Test-Path -Path $testsPath)) {
63+
# Locate the tests directory.
64+
$testsPath = Resolve-Path 'tests' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path
65+
if (-not $testsPath -or -not (Test-Path -Path $testsPath)) {
8366
Write-Host 'No tests found'
8467
exit 0
8568
}
8669
Write-Host "Tests found at [$testsPath]"
8770
88-
# Get all directories inside the tests folder.
71+
# Get all subdirectories inside the tests folder; if none, use the tests folder itself.
8972
$testsPaths = Get-ChildItem -Path $testsPath -Directory | ForEach-Object { $_.FullName }
9073
if (-not $testsPaths) {
91-
# If no subdirectories, use the tests folder itself.
92-
$testsPaths = , $testsPath
74+
$testsPaths = @($testsPath)
9375
}
9476
95-
# Build the test suites matrix
96-
$testSuites = @()
97-
foreach ($folder in $testsPaths) {
98-
foreach ($config in $testConfigs) {
99-
# For each folder and config, produce a new object with the proper values.
100-
$testSuite = @{
101-
OS = $config.OS
102-
Shells = $config.Shells
103-
Path = $folder
77+
# Build the test suites matrix.
78+
$testSuites = foreach ($folder in $testsPaths) {
79+
foreach ($osConfig in $osConfigs) {
80+
[pscustomobject]@{
81+
RunsOn = $osConfig.runson
82+
OSName = $osConfig.name
83+
TestFolderPath = $folder
84+
TestName = Split-Path -Path $folder -Leaf
10485
}
105-
$testSuites += $testSuite
10686
}
10787
}
10888
10989
# (Optional) Display the generated matrix in a table for verification.
11090
$testSuites | Format-Table -AutoSize
11191
112-
# Pass the final object to GitHub Actions output
113-
Set-GitHubOutput -Name TestSuites -Value $testSuites -Verbose -Debug -Confirm:$false
114-
92+
# Pass the final object to GitHub Actions output.
93+
Set-GitHubOutput -Name TestSuites -Value $testSuites

‎.github/workflows/Test-ModuleLocal.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ on:
3737
type: string
3838
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
3939
required: false
40+
TestFolderPath:
41+
type: string
42+
description: The path to the tests folder.
43+
required: false
44+
default: tests
45+
TestName:
46+
type: string
47+
description: The path to the tests folder.
48+
required: false
49+
default: tests
4050
Path:
4151
type: string
4252
description: The path to the root of the repo.
@@ -103,8 +113,11 @@ jobs:
103113
Prerelease: ${{ inputs.Prerelease }}
104114
Verbose: ${{ inputs.Verbose }}
105115
Version: ${{ inputs.Version }}
106-
TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }}
107-
Path:
116+
TestResult_TestSuiteName: ${{ inputs.TestName }}-${{ runner.os }}
117+
TestResult_Enabled: true
118+
CodeCoverage_Enabled: true
119+
CodeCoverage_OutputFormat: JaCoCo
120+
Path: ${{ inputs.TestFolderPath }}
108121
Run_Path: ${{ inputs.Path }}/outputs/module
109122

110123
- name: Failed test

‎.github/workflows/workflow.yml

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,20 @@ jobs:
166166
fail-fast: false
167167
matrix:
168168
include: ${{ fromJson(needs.Get-TestSuites.outputs.TestSuites) }}
169-
runs-on: ${{ matrix.OS }}
170-
outputs:
171-
Passed: ${{ steps.action-test.outcome }}
172-
steps:
173-
- name: Test
174-
shell: pwsh
175-
id: action-test
176-
continue-on-error: true
177-
run: |
178-
$suite = '${{ matrix.Path }}'
179-
if ($IsLinux) {
180-
throw "Linux is not supported"
181-
}
182-
Write-Host "Running test suite: $suite"
183-
184-
- name: Status
185-
shell: pwsh
186-
run: |
187-
Write-Host 'outcome: ${{ steps.action-test.outcome }}'
188-
Write-Host 'conclusion: ${{ steps.action-test.conclusion }}'
169+
uses: ./.github/workflows/Test-ModuleLocal.yml
170+
secrets: inherit
171+
with:
172+
RunsOn: ${{ matrix.RunsOn }}
173+
OS: ${{ matrix.OSName }}
174+
Name: ${{ inputs.Name }}
175+
Path: ${{ inputs.Path }}
176+
SkipTests: ${{ inputs.SkipTests }}
177+
TestFolderPath: ${{ matrix.TestFolderPath }}
178+
TestName: ${{ matrix.TestName }}
179+
Debug: ${{ inputs.Debug }}
180+
Prerelease: ${{ inputs.Prerelease }}
181+
Verbose: ${{ inputs.Verbose }}
182+
Version: ${{ inputs.Version }}
189183

190184
Status:
191185
name: Status

0 commit comments

Comments
 (0)