Skip to content

Commit 530913e

Browse files
🩹 [Patch]: Fix gh auth status issue + add complex and actual use-case for Set-GitHubOutput (#41)
## Description This pull request includes significant updates to the `.github/workflows/TestWorkflow.yml` and `scripts/info.ps1` files to enhance the workflow and logging capabilities. Enhancements to `.github/workflows/TestWorkflow.yml`: * Added new outputs for `MatrixTest`, `ComplexArray`, and `ComplexArrayJson` to capture and utilize more detailed test results. * Introduced multiple `LogGroup` sections to improve the readability and organization of the workflow logs. * Added a new job `MatrixCreator` to dynamically create a matrix of test configurations and a dependent job `MatrixTest` to execute the tests based on the matrix. Enhancements to `scripts/info.ps1`: * Improved verbose logging to provide more detailed information about the authentication type and token status. * Added logic to preserve the original `$LASTEXITCODE` after checking the GitHub CLI authentication status. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [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
1 parent bbb4e4e commit 530913e

File tree

2 files changed

+186
-7
lines changed

2 files changed

+186
-7
lines changed

.github/workflows/TestWorkflow.yml

Lines changed: 176 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ jobs:
130130
ActionTestCommands:
131131
name: Commands + Outputs
132132
runs-on: ${{ inputs.runs-on }}
133+
outputs:
134+
MatrixTest: ${{ fromJson(steps.test.outputs.result).MatrixTest }}
133135
steps:
134136
# Need to check out as part of the test, as its a local action
135137
- name: Checkout repo
@@ -171,18 +173,187 @@ jobs:
171173
Set-GitHubOutput -Name 'Zen2' -Value $zen
172174
}
173175
176+
LogGroup 'Set array outputs' {
177+
$complexArray = @(
178+
[pscustomobject]@{
179+
Name = 'Test'
180+
Value = 'Value'
181+
Cars = @(
182+
@{
183+
Make = 'Toyota'
184+
Model = 'Corolla'
185+
},
186+
@{
187+
Make = 'Ford'
188+
Model = 'Fiesta'
189+
}
190+
)
191+
},
192+
[pscustomobject]@{
193+
Name = 'Test2'
194+
Value = 'Value2'
195+
Cars = @(
196+
@{
197+
Make = 'Toyota'
198+
Model = 'Corolla'
199+
},
200+
@{
201+
Make = 'Ford'
202+
Model = 'Fiesta'
203+
}
204+
)
205+
}
206+
)
207+
Set-GitHubOutput -Name 'ComplexArray' -Value $complexArray
208+
}
209+
210+
LogGroup 'Set array outputs - JSON' {
211+
$compexJson = $complexArray | ConvertTo-Json -Depth 10
212+
Set-GitHubOutput -Name 'ComplexArrayJson' -Value $compexJson
213+
}
214+
215+
LogGroup 'Set summary' {
216+
Get-Content $env:GITHUB_OUTPUT -Raw | Set-GitHubStepSummary
217+
}
218+
219+
174220
- name: Run-test
175221
shell: pwsh
176222
env:
177223
result: ${{ steps.test.outputs.result }}
178224
WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }}
225+
Zen: ${{ fromJson(steps.test.outputs.result).Zen }}
226+
Zen2: ${{ fromJson(steps.test.outputs.result).Zen2 }}
227+
Context: ${{ fromJson(steps.test.outputs.result).Context }}
228+
GitConfig: ${{ fromJson(steps.test.outputs.result).GitConfig }}
229+
ComplexArray: ${{ fromJson(steps.test.outputs.result).ComplexArray }}
230+
ComplexArrayJson: ${{ fromJson(steps.test.outputs.result).ComplexArrayJson }}
179231
run: |
180232
$result = $env:result | ConvertFrom-Json
181-
Set-GitHubStepSummary -Summary $env:WISECAT
182-
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
183-
Write-Host ($result.Zen2)
184-
$result.Context | Format-List
185-
$result.GitConfig | Format-List
233+
234+
LogGroup 'Result - Json' {
235+
$env:result
236+
}
237+
238+
LogGroup 'Result - Object' {
239+
$result
240+
}
241+
242+
LogGroup "WISECAT" {
243+
Write-Host $env:WISECAT
244+
}
245+
246+
LogGroup "Zen" {
247+
Write-Host $env:Zen
248+
}
249+
250+
LogGroup "Context" {
251+
$env:Context
252+
}
253+
254+
LogGroup "GitConfig" {
255+
$env:GitConfig
256+
}
257+
258+
LogGroup "Zen2" {
259+
Write-Host $env:Zen2
260+
}
261+
262+
LogGroup "ComplexArray" {
263+
$env:ComplexArray
264+
if (-not (Test-Json -Json $env:ComplexArray)) {
265+
Write-Host "Item is not a JSON object"
266+
exit 1
267+
}
268+
}
269+
270+
LogGroup "ComplexArrayJson" {
271+
$env:ComplexArrayJson
272+
if (-not (Test-Json -Json $env:ComplexArrayJson)) {
273+
Write-Host "Item is not a JSON object"
274+
exit 1
275+
}
276+
}
277+
278+
LogGroup "Other" {
279+
Set-GitHubStepSummary -Summary $env:WISECAT
280+
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
281+
Write-Host ($result.Zen2)
282+
$result.Context | Format-List
283+
$result.Context.GetType().Name
284+
if ($result.GitConfig -isnot [String]) {
285+
throw "GitConfig is not a PSCustomObject"
286+
}
287+
288+
$result.GitConfig | Format-List
289+
$result.GitConfig.GetType().Name
290+
if ($result.GitConfig -isnot [String]) {
291+
throw "GitConfig is a PSCustomObject"
292+
}
293+
}
294+
295+
MatrixCreator:
296+
name: Matrix Creator
297+
runs-on: ubuntu-latest
298+
outputs:
299+
MatrixTest: ${{ fromJson(steps.test.outputs.result).MatrixTest }}
300+
steps:
301+
# Need to check out as part of the test, as its a local action
302+
- name: Checkout repo
303+
uses: actions/checkout@v4
304+
305+
- name: Action-Test
306+
uses: ./
307+
id: test
308+
with:
309+
Debug: true
310+
Verbose: true
311+
Prerelease: true
312+
ShowInit: true
313+
ShowOutput: true
314+
Script: |
315+
LogGroup 'MatrixTest' {
316+
$matrixTest = @{
317+
Path = @('tests/srcTestRepo', 'tests/srcWithManifestTestRepo')
318+
RunsOn = @('ubuntu-latest', 'windows-latest', 'macos-latest')
319+
}
320+
Set-GitHubOutput -Name 'MatrixTest' -Value $matrixTest
321+
}
322+
323+
MatrixTest:
324+
needs: MatrixCreator
325+
strategy:
326+
matrix: ${{ fromJson(needs.MatrixCreator.outputs.MatrixTest) }}
327+
name: Matrix Test [${{ matrix.RunsOn }}]
328+
runs-on: ${{ matrix.RunsOn }}
329+
steps:
330+
- name: Matrix Test
331+
shell: pwsh
332+
id: test
333+
env:
334+
Path: ${{ matrix.Path }}
335+
run: |
336+
Install-PSResource -Name GitHub -TrustRepository -Prerelease
337+
if ($PSMODULE_GITHUB_SCRIPT) {
338+
throw "Is not running in GitHub-Script aciton! Failing"
339+
}
340+
$item = [pscustomobject]@{
341+
Path = $env:Path
342+
Exists = Test-Path -Path $env:Path
343+
}
344+
Set-GithubOutput -Name 'Item' -Value $item
345+
346+
- name: Matrix Test [Show]
347+
shell: pwsh
348+
env:
349+
Item: ${{ steps.test.outputs.item }}
350+
run: |
351+
$env:Item
352+
$env:Item | ConvertFrom-Json
353+
354+
if (-not (Test-Json -Json $env:Item)) {
355+
throw "Item is not a JSON object"
356+
}
186357
187358
ActionTestWithoutToken:
188359
name: WithoutToken

scripts/info.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ process {
2828
$context = Get-GitHubContext
2929
$context | Format-List
3030

31-
if ($context.AuthType -ne 'APP') {
31+
Write-Verbose "Token? [$([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token))]"
32+
Write-Verbose "AuthType? [$($context.AuthType)] - [$($context.AuthType -ne 'APP')]"
33+
Write-Verbose "gh auth? [$($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token))]"
34+
35+
if ($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Token)) {
3236
Write-Output 'GitHub CLI status:'
37+
$before = $LASTEXITCODE
3338
gh auth status
34-
$LASTEXITCODE = 0
39+
if ($LASTEXITCODE -ne $before) {
40+
Write-Warning "LASTEXITCODE has changed [$LASTEXITCODE]"
41+
$global:LASTEXITCODE = $before
42+
}
3543
}
3644
}
3745

0 commit comments

Comments
 (0)