-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪲 [Fix]: Fix coverage reporting and some GHA commands (#174)
## Description - Updated the schedule for updating the coverage report to run every hour instead of on push or pull request events. - Simplified the `Set-CoverageReport.ps1` script. - Added new functions for handling GitHub Actions outputs so that we can easily convert between objects and GitHub output syntax. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ]⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
00d6200
commit ea2ddb0
Showing
12 changed files
with
1,017 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
filter ConvertFrom-GitHubOutput { | ||
<# | ||
.SYNOPSIS | ||
Gets the GitHub output. | ||
.DESCRIPTION | ||
Gets the GitHub output from $env:GITHUB_OUTPUT and creates an object with key-value pairs, | ||
supporting both single-line and multi-line values, and parsing JSON values. | ||
.EXAMPLE | ||
$content = @' | ||
zen=something else | ||
result={"MyOutput":"Hello, World!","Status":"Success"} | ||
MY_VALUE<<EOF_12a089b9-051e-4c4e-91c9-8e24fc2fbbf6 | ||
Line1 | ||
Line2 | ||
Line3 | ||
EOF_12a089b9-051e-4c4e-91c9-8e24fc2fbbf6 | ||
Config={"Nested":{"SubSetting":"SubValue"},"Setting1":"Value1","Setting2":2} | ||
Numbers=12345 | ||
'@ | ||
$content | ConvertFrom-GitHubOutput | ||
zen : something else | ||
result : @{MyOutput=Hello, World!; Status=Success} | ||
MY_VALUE : Line1 | ||
Line2 | ||
Line3 | ||
Config : {[Nested, System.Collections.Hashtable], [Setting1, Value1], [Setting2, 2]} | ||
Numbers : 12345 | ||
This will convert the GitHub Actions output syntax to a PowerShell object. | ||
#> | ||
[OutputType([pscustomobject])] | ||
[OutputType([hashtable])] | ||
[CmdletBinding()] | ||
param( | ||
# The input data to convert | ||
[Parameter( | ||
Mandatory, | ||
ValueFromPipeline | ||
)] | ||
[string[]] $InputData, | ||
|
||
# Whether to convert the input data to a hashtable | ||
[switch] $AsHashtable | ||
) | ||
|
||
begin { | ||
$lines = @() | ||
} | ||
|
||
process { | ||
foreach ($item in $InputData) { | ||
if ($item -is [string]) { | ||
$lines += $item -split "`n" | ||
} | ||
} | ||
} | ||
|
||
end { | ||
# Initialize variables | ||
$result = @{} | ||
$i = 0 | ||
|
||
while ($i -lt $lines.Count) { | ||
$line = $lines[$i].Trim() | ||
Write-Debug "[$line]" | ||
|
||
# Skip empty or delimiter lines | ||
if ($line -match '^-+$' -or [string]::IsNullOrWhiteSpace($line)) { | ||
Write-Debug "[$line] - Skipping empty line" | ||
$i++ | ||
continue | ||
} | ||
|
||
# Check for key=value pattern | ||
if ($line -match '^([^=]+)=(.*)$') { | ||
Write-Debug "[$line] - key=value pattern" | ||
$key = $Matches[1].Trim() | ||
$value = $Matches[2] | ||
|
||
# Attempt to parse JSON | ||
if (Test-Json $value -ErrorAction SilentlyContinue) { | ||
Write-Debug "[$line] - value is JSON" | ||
$value = ConvertFrom-Json $value -AsHashtable:$AsHashtable | ||
} | ||
|
||
$result[$key] = $value | ||
$i++ | ||
continue | ||
} | ||
|
||
# Check for key<<EOF pattern | ||
if ($line -match '^([^<]+)<<(\S+)$') { | ||
Write-Debug "[$line] - key<<EOF pattern" | ||
$key = $Matches[1].Trim() | ||
$eof_marker = $Matches[2] | ||
Write-Debug "[$line] - key<<EOF pattern - [$eof_marker]" | ||
$i++ | ||
$value_lines = @() | ||
|
||
while ($i -lt $lines.Count -and $lines[$i] -ne $eof_marker) { | ||
$valueItem = $lines[$i].Trim() | ||
Write-Debug "[$line] - key<<EOF pattern - [$eof_marker] - [$valueItem]" | ||
$value_lines += $valueItem | ||
$i++ | ||
} | ||
|
||
# Skip the EOF marker | ||
if ($i -lt $lines.Count -and $lines[$i] -eq $eof_marker) { | ||
Write-Debug "[$line] - key<<EOF pattern - Closing" | ||
$i++ | ||
} | ||
|
||
$value = $value_lines -join "`n" | ||
|
||
if (Test-Json $value -ErrorAction SilentlyContinue) { | ||
Write-Debug "[$line] - key<<EOF pattern - value is JSON" | ||
$value = ConvertFrom-Json $value -AsHashtable:$AsHashtable | ||
} | ||
|
||
$result[$key] = $value | ||
continue | ||
} | ||
$i++ | ||
} | ||
if ($AsHashtable) { | ||
return $result | ||
} | ||
[PSCustomObject]$result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
filter ConvertTo-GitHubOutput { | ||
<# | ||
.SYNOPSIS | ||
Converts a PowerShell object's properties to expected format for GitHub Actions output syntax. | ||
.DESCRIPTION | ||
The function iterates over each property of the provided PowerShell object and writes | ||
them to a specified file in the format used by GitHub Actions for outputs. It supports: | ||
- Single-line values (written as key=value). | ||
- Multi-line string values (using key<<EOF syntax with a unique EOF marker). | ||
- Converts hashtables and PSCustomObject values to compressed JSON strings. | ||
.EXAMPLE | ||
$object = [PSCustomObject]@{ | ||
zen = 'something else' | ||
result = [PSCustomObject]@{ MyOutput = "Hello, World!"; Status = "Success" } | ||
MY_VALUE = "Line1`nLine2`nLine3" | ||
Config = @{ Setting1 = "Value1"; Setting2 = 2; Nested = @{ SubSetting = "SubValue" } } | ||
Numbers = 12345 | ||
} | ||
$object | ConvertTo-GitHubOutput | ||
zen=something else | ||
result={"MyOutput":"Hello, World!","Status":"Success"} | ||
MY_VALUE<<EOF_12a089b9-051e-4c4e-91c9-8e24fc2fbbf6 | ||
Line1 | ||
Line2 | ||
Line3 | ||
EOF_12a089b9-051e-4c4e-91c9-8e24fc2fbbf6 | ||
Config={"Nested":{"SubSetting":"SubValue"},"Setting1":"Value1","Setting2":2} | ||
Numbers=12345 | ||
This will convert the properties of $object to GitHub Actions output syntax. | ||
#> | ||
[OutputType([string])] | ||
[CmdletBinding()] | ||
param( | ||
# The PowerShell object containing the key-value pairs to be saved. | ||
# Each property of the object represents a key. | ||
[Parameter( | ||
Mandatory, | ||
ValueFromPipeline | ||
)] | ||
[object] $InputObject | ||
) | ||
|
||
$outputLines = @() | ||
|
||
if ($InputObject -is [hashtable]) { | ||
$InputObject = [PSCustomObject]$InputObject | ||
} | ||
|
||
foreach ($property in $InputObject.PSObject.Properties) { | ||
$key = $property.Name | ||
$value = $property.Value | ||
|
||
# Convert hashtable or PSCustomObject to compressed JSON | ||
if ($value -is [hashtable] -or $value -is [PSCustomObject]) { | ||
$value = $value | ConvertTo-Json -Compress | ||
} | ||
|
||
if ($value -is [string] -and $value.Contains("`n")) { | ||
# Multi-line value | ||
$guid = [Guid]::NewGuid().ToString() | ||
$EOFMarker = "EOF_$guid" | ||
$outputLines += "$key<<$EOFMarker" | ||
$outputLines += $value | ||
$outputLines += $EOFMarker | ||
} else { | ||
# Single-line value | ||
$outputLines += "$key=$value" | ||
} | ||
} | ||
$outputLines | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function Get-GitHubOutput { | ||
<# | ||
.SYNOPSIS | ||
Gets the GitHub output. | ||
.DESCRIPTION | ||
Gets the GitHub output from $env:GITHUB_OUTPUT and creates an object with key-value pairs, supporting both single-line and multi-line values | ||
.EXAMPLE | ||
Get-GitHubOutput | ||
MY_VALUE result zen | ||
-------- ------ --- | ||
qwe… @{"MyOutput":"Hello, World!"} something else | ||
Gets the GitHub output and returns an object with key-value pairs. | ||
.EXAMPLE | ||
Get-GitHubOutput -AsHashtable | ||
Name Value | ||
---- ----- | ||
MyArray 1 2 3 | ||
MyOutput Hello, World! | ||
zen something else | ||
result {[thisisatest, a simple value]} | ||
mystuff {[MyOutput, Hello, World!]} | ||
MY_VALUE qwe… | ||
Gets the GitHub output and returns a hashtable. | ||
#> | ||
[OutputType([pscustomobject])] | ||
[CmdletBinding()] | ||
param( | ||
# Returns the output as a hashtable. | ||
[Parameter()] | ||
[switch] $AsHashtable, | ||
|
||
# The path to the GitHub output file. | ||
[Parameter()] | ||
[string] $Path = $env:GITHUB_OUTPUT | ||
) | ||
|
||
if (-not (Test-Path -Path $Path)) { | ||
throw "File not found: $Path" | ||
} | ||
|
||
Get-Content -Path $Path | ConvertFrom-GitHubOutput -AsHashtable:$AsHashtable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.