Skip to content

Commit d5e8d41

Browse files
🩹 [CI]: Refactor test suite retrieval logic and standardize test path parameter naming
1 parent 0ef0ef2 commit d5e8d41

File tree

3 files changed

+50
-70
lines changed

3 files changed

+50
-70
lines changed

‎.github/workflows/Get-TestSuites.yml

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -73,71 +73,51 @@ jobs:
7373
}
7474
Write-Host "Tests found at [$testsPath]"
7575
76-
# First, check if the root tests folder contains configuration.ps1, .container.ps1 or .tests.ps1 files
77-
$hasTestFiles = Get-ChildItem -Path $testsPath -File -Recurse:$false | Where-Object {
78-
$_.Name -like '*.Configuration.ps1' -or
79-
$_.Name -like '*.Container.ps1' -or
80-
$_.Name -like '*.Tests.ps1'
81-
}
76+
function Get-TestItemsFromFolder {
77+
param ([string]$FolderPath)
78+
79+
$configFiles = Get-ChildItem -Path $FolderPath -File -Filter '*.Configuration.ps1'
80+
if ($configFiles.Count -eq 1) {
81+
return @($configFiles)
82+
} elseif ($configFiles.Count -gt 1) {
83+
throw "Multiple configuration files found in [$FolderPath]. Please separate configurations into different folders."
84+
}
8285
83-
# Define the test paths based on our findings
84-
$testsPaths = @()
85-
if ($hasTestFiles) {
86-
# If the tests folder directly contains test files, only use the root folder
87-
Write-Host "Test files found directly in tests folder. Using only the root tests folder."
88-
$testsPaths = @($testsPath)
89-
} else {
90-
# Otherwise, recursively search for subdirectories that might contain tests
91-
Write-Host "No test files found in root tests folder. Searching subdirectories..."
92-
93-
# Helper function to find test directories recursively
94-
function Find-TestDirectories {
95-
param (
96-
[string]$Path
97-
)
98-
99-
$directories = @()
100-
$childDirs = Get-ChildItem -Path $Path -Directory
101-
102-
foreach ($dir in $childDirs) {
103-
# Check if this directory contains test files
104-
$hasTests = Get-ChildItem -Path $dir.FullName -File -Recurse:$false | Where-Object {
105-
$_.Name -like '*.Configuration.ps1' -or
106-
$_.Name -like '*.Container.ps1' -or
107-
$_.Name -like '*.Tests.ps1'
108-
}
86+
$containerFiles = Get-ChildItem -Path $FolderPath -File -Filter '*.Container.ps1'
87+
if ($containerFiles.Count -ge 1) {
88+
return $containerFiles
89+
}
10990
110-
if ($hasTests) {
111-
$directories += $dir.FullName
112-
} else {
113-
# Recursively check subdirectories
114-
$directories += Find-TestDirectories -Path $dir.FullName
115-
}
116-
}
91+
$testFiles = Get-ChildItem -Path $FolderPath -File -Filter '*.Tests.ps1'
92+
return $testFiles
93+
}
11794
118-
return $directories
119-
}
95+
function Find-TestDirectories {
96+
param ([string]$Path)
12097
121-
$testsPaths = Find-TestDirectories -Path $testsPath
98+
$directories = @()
99+
$childDirs = Get-ChildItem -Path $Path -Directory
122100
123-
# If no test directories were found, default to the root tests folder
124-
if (-not $testsPaths) {
125-
Write-Host "No specific test directories found. Using the root tests folder."
126-
$testsPaths = @($testsPath)
127-
} else {
128-
Write-Host "Found test directories:"
129-
$testsPaths | ForEach-Object { Write-Host " - $_" }
101+
foreach ($dir in $childDirs) {
102+
$directories += $dir.FullName
103+
$directories += Find-TestDirectories -Path $dir.FullName
130104
}
105+
106+
return $directories
131107
}
132108
133-
# Build the test suites matrix.
134-
$testSuites = foreach ($folder in $testsPaths) {
135-
foreach ($osConfig in $osConfigs) {
136-
[pscustomobject]@{
137-
RunsOn = $osConfig.runson
138-
OSName = $osConfig.name
139-
TestFolderPath = Resolve-Path -Path $folder -Relative
140-
TestName = Split-Path -Path $folder -Leaf
109+
$allTestFolders = @($testsPath) + (Find-TestDirectories -Path $testsPath)
110+
111+
$testSuites = foreach ($folder in $allTestFolders) {
112+
$testItems = Get-TestItemsFromFolder -FolderPath $folder
113+
foreach ($item in $testItems) {
114+
foreach ($osConfig in $osConfigs) {
115+
[pscustomobject]@{
116+
RunsOn = $osConfig.runson
117+
OSName = $osConfig.name
118+
TestPath = Resolve-Path -Path $item.FullName -Relative
119+
TestName = $item.BaseName
120+
}
141121
}
142122
}
143123
}

‎.github/workflows/Test-ModuleLocal.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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:
40+
TestPath:
4141
type: string
4242
description: The path to the tests folder.
4343
required: false
@@ -132,6 +132,6 @@ jobs:
132132
Output_Verbosity: Detailed
133133
CodeCoverage_OutputFormat: JaCoCo
134134
CodeCoverage_CoveragePercentTarget: 0
135-
Path: ${{ inputs.TestFolderPath }}
135+
Path: ${{ inputs.TestPath }}
136136
Run_Path: ${{ steps.import-module.outputs.path }}
137137
WorkingDirectory: ${{ inputs.WorkingDirectory }}

‎.github/workflows/workflow.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ jobs:
120120
Version: ${{ inputs.Version }}
121121
WorkingDirectory: ${{ inputs.WorkingDirectory }}
122122

123+
Get-TestSuites:
124+
name: Get-TestSuites
125+
uses: ./.github/workflows/Get-TestSuites.yml
126+
with:
127+
Debug: ${{ inputs.Debug }}
128+
Prerelease: ${{ inputs.Prerelease }}
129+
Verbose: ${{ inputs.Verbose }}
130+
Version: ${{ inputs.Version }}
131+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
132+
123133
Test-Module:
124134
if: ${{ needs.Build-Module.result == 'success' && !cancelled() }}
125135
name: Test-Module
@@ -148,16 +158,6 @@ jobs:
148158
Version: ${{ inputs.Version }}
149159
WorkingDirectory: ${{ inputs.WorkingDirectory }}
150160

151-
Get-TestSuites:
152-
name: Get-TestSuites
153-
uses: ./.github/workflows/Get-TestSuites.yml
154-
with:
155-
Debug: ${{ inputs.Debug }}
156-
Prerelease: ${{ inputs.Prerelease }}
157-
Verbose: ${{ inputs.Verbose }}
158-
Version: ${{ inputs.Version }}
159-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
160-
161161
Test-ModuleLocal:
162162
name: ${{ matrix.TestName }}
163163
if: ${{ needs.Build-Module.result == 'success' && !cancelled() }}
@@ -175,7 +175,7 @@ jobs:
175175
OS: ${{ matrix.OSName }}
176176
Name: ${{ inputs.Name }}
177177
SkipTests: ${{ inputs.SkipTests }}
178-
TestFolderPath: ${{ matrix.TestFolderPath }}
178+
TestPath: ${{ matrix.TestPath }}
179179
TestName: ${{ matrix.TestName }}
180180
Debug: ${{ inputs.Debug }}
181181
Prerelease: ${{ inputs.Prerelease }}

0 commit comments

Comments
 (0)