Skip to content

Commit 86d49bf

Browse files
🩹 [Refactor]: Modularize Get-TestResults workflow and enhance input handling in CI configuration
1 parent 1184ce0 commit 86d49bf

File tree

3 files changed

+164
-56
lines changed

3 files changed

+164
-56
lines changed

‎.github/workflows/CI.yml

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,113 @@ jobs:
178178
Version: ${{ inputs.Version }}
179179
WorkingDirectory: ${{ inputs.WorkingDirectory }}
180180

181-
Status:
182-
name: Status
183-
runs-on: ubuntu-latest
181+
Get-TestResults:
182+
name: Get-TestResults
184183
needs:
185184
- Test-SourceCode
186185
- Test-Module
187186
- Test-ModuleLocal
188-
steps:
189-
- name: Status
190-
shell: pwsh
191-
run: |
192-
[pscustomobject]@{
193-
TestModule = '${{ needs.Test-Module.result }}'
194-
TestModuleLocal = '${{ needs.Test-ModuleLocal.result }}'
195-
}
187+
uses: ./.github/workflows/Get-TestResults.yml
188+
secrets: inherit
189+
with:
190+
Debug: ${{ inputs.Debug }}
191+
Prerelease: ${{ inputs.Prerelease }}
192+
Verbose: ${{ inputs.Verbose }}
193+
Version: ${{ inputs.Version }}
194+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
195+
196+
# Get-CodeCoverage:
197+
# name: Get-CodeCoverage
198+
# runs-on: ubuntu-latest
199+
# needs:
200+
# - Test-SourceCode
201+
# - Test-Module
202+
# - Test-ModuleLocal
203+
# steps:
204+
# - name: Get-CodeCoverage
205+
# uses: PSModule/GitHub-Script@v1
206+
# with:
207+
# Debug: ${{ inputs.Debug }}
208+
# Prerelease: ${{ inputs.Prerelease }}
209+
# Verbose: ${{ inputs.Verbose }}
210+
# Version: ${{ inputs.Version }}
211+
# Script: |
212+
# $PSStyle.OutputRendering = 'Ansi'
213+
# $repo = $env:GITHUB_REPOSITORY
214+
# $runId = $env:GITHUB_RUN_ID
215+
# gh run download $runId --repo $repo --pattern *-CodeCoverage
216+
# $files = Get-ChildItem -Path . -Recurse -File | Select-Object -ExpandProperty FullName | Sort-Object
217+
# # Load the first XML as the base report
218+
# [xml]$mergedReport = Get-Content -Path $files[0]
219+
220+
# # Function to merge counters
221+
# function Merge-Counters($baseNode, $newNode) {
222+
# foreach ($newCounter in $newNode.counter) {
223+
# $baseCounter = $baseNode.counter | Where-Object { $_.type -eq $newCounter.type }
224+
# if ($baseCounter) {
225+
# $baseCounter.missed = [int]$baseCounter.missed + [int]$newCounter.missed
226+
# $baseCounter.covered = [int]$baseCounter.covered + [int]$newCounter.covered
227+
# } else {
228+
# # Import new counter if it doesn't exist
229+
# $importedCounter = $mergedReport.ImportNode($newCounter, $true)
230+
# $baseNode.AppendChild($importedCounter) | Out-Null
231+
# }
232+
# }
233+
# }
234+
235+
# # Loop through remaining reports to merge coverage data
236+
# foreach ($reportPath in $files[1..($files.Count - 1)]) {
237+
# [xml]$currentReport = Get-Content -Path $reportPath
238+
239+
# # Merge the top-level counters
240+
# Merge-Counters -baseNode $mergedReport.report -newNode $currentReport.report
241+
242+
# # Merge packages and classes
243+
# foreach ($package in $currentReport.report.package) {
244+
# $basePackage = $mergedReport.report.package | Where-Object { $_.name -eq $package.name }
245+
246+
# if ($basePackage) {
247+
# # Merge counters at package level
248+
# Merge-Counters -baseNode $basePackage -newNode $package
249+
250+
# foreach ($class in $package.class) {
251+
# $baseClass = $basePackage.class | Where-Object { $_.name -eq $class.name }
252+
# if ($baseClass) {
253+
# # Merge counters at class level
254+
# Merge-Counters -baseNode $baseClass -newNode $class
255+
# } else {
256+
# # Import new class
257+
# $importedClass = $mergedReport.ImportNode($class, $true)
258+
# $basePackage.AppendChild($importedClass) | Out-Null
259+
# }
260+
# }
261+
# } else {
262+
# # Import entire new package
263+
# $importedPackage = $mergedReport.ImportNode($package, $true)
264+
# $mergedReport.report.AppendChild($importedPackage) | Out-Null
265+
# }
266+
# }
267+
# }
268+
269+
# # Output the combined report
270+
# $mergedReport.Save("merged-jacoco-report.xml")
271+
272+
# # Assuming $mergedReport is your final [xml] object:
273+
# $xmlString = $mergedReport.OuterXml
274+
275+
# # To format (pretty-print) the XML nicely:
276+
# $stringWriter = New-Object System.IO.StringWriter
277+
# $xmlWriter = [System.Xml.XmlTextWriter]::new($stringWriter)
278+
# $xmlWriter.Formatting = "Indented"
279+
# $mergedReport.WriteTo($xmlWriter)
280+
# $xmlWriter.Flush()
281+
# $prettyXml = $stringWriter.ToString()
282+
283+
# $prettyXml | Out-String
284+
285+
# # Output or export the XML string
286+
# # $prettyXml | Out-File -FilePath "merged-jacoco-report.xml" -Encoding UTF8
287+
196288

197289
# TestModuleStatus:
198290
# name: Test module status
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Get-TestResults
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
Debug:
7+
type: boolean
8+
description: Enable debug output.
9+
required: false
10+
default: false
11+
Verbose:
12+
type: boolean
13+
description: Enable verbose output.
14+
required: false
15+
default: false
16+
Version:
17+
type: string
18+
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
19+
required: false
20+
default: ''
21+
Prerelease:
22+
type: boolean
23+
description: Whether to use a prerelease version of the 'GitHub' module.
24+
required: false
25+
default: false
26+
WorkingDirectory:
27+
type: string
28+
description: The working directory where the script will run from.
29+
required: false
30+
default: ${{ github.workspace }}
31+
32+
permissions:
33+
contents: read # to checkout the repo
34+
35+
jobs:
36+
Get-TestResults:
37+
name: Get-TestResults
38+
runs-on: ubuntu-latest
39+
outputs:
40+
TestResults: ${{ fromJson(steps.Get-TestResults.outputs.result).TestResults }}
41+
steps:
42+
- name: Checkout Code
43+
uses: actions/checkout@v4
44+
45+
- name: Get-TestResults
46+
uses: PSModule/Get-PesterTestResults@v1
47+
id: Get-TestResults
48+
with:
49+
Debug: ${{ inputs.Debug }}
50+
Prerelease: ${{ inputs.Prerelease }}
51+
Verbose: ${{ inputs.Verbose }}
52+
Version: ${{ inputs.Version }}
53+
WorkingDirectory: ${{ inputs.WorkingDirectory }}

‎.github/workflows/workflow.yml

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -187,55 +187,18 @@ jobs:
187187

188188
Get-TestResults:
189189
name: Get-TestResults
190-
runs-on: ubuntu-latest
191190
needs:
192191
- Test-SourceCode
193192
- Test-Module
194193
- Test-ModuleLocal
195-
steps:
196-
- name: Get-TestResults
197-
uses: PSModule/GitHub-Script@v1
198-
with:
199-
Debug: ${{ inputs.Debug }}
200-
Prerelease: ${{ inputs.Prerelease }}
201-
Verbose: ${{ inputs.Verbose }}
202-
Version: ${{ inputs.Version }}
203-
Script: |
204-
$PSStyle.OutputRendering = 'Ansi'
205-
$repo = $env:GITHUB_REPOSITORY
206-
$runId = $env:GITHUB_RUN_ID
207-
gh run download $runId --repo $repo --pattern *-TestResults
208-
$files = Get-ChildItem -Path . -Recurse -File
209-
210-
LogGroup "List TestResults files" {
211-
$files.Name | Out-String
212-
}
213-
$files | Format-Table -AutoSize | Out-String
214-
215-
$allCases = [System.Collections.Generic.List[psobject]]::new()
216-
foreach ($file in $files) {
217-
$fileName = $file.BaseName
218-
LogGroup $fileName {
219-
Get-Content -Path $file | Out-String
220-
}
221-
LogGroup "$fileName - Process" {
222-
$xmlDoc = [xml](Get-Content -Path $file.FullName)
223-
$cases = $xmlDoc.SelectNodes('//test-case') | ForEach-Object {
224-
[pscustomobject]@{
225-
Name = $_.name
226-
Description = $_.description
227-
Result = $_.result
228-
Success = [bool]($_.success -eq 'True')
229-
Time = [float]$_.time
230-
Executed = [bool]($_.executed -eq 'True')
231-
FailureMessage = $_.failure.message
232-
StackTrace = $_.failure.'stack-trace'
233-
}
234-
}
235-
$cases | ForEach-Object { $allCases.Add($_) }
236-
$cases | Format-List | Out-String
237-
}
238-
}
194+
uses: ./.github/workflows/Get-TestResults.yml
195+
secrets: inherit
196+
with:
197+
Debug: ${{ inputs.Debug }}
198+
Prerelease: ${{ inputs.Prerelease }}
199+
Verbose: ${{ inputs.Verbose }}
200+
Version: ${{ inputs.Version }}
201+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
239202

240203
# Get-CodeCoverage:
241204
# name: Get-CodeCoverage

0 commit comments

Comments
 (0)