Skip to content

Commit 7f22b12

Browse files
🩹 [Patch]: Update scripts to output as strings (#44)
## Description This pull request includes changes to improve output formatting and enable ANSI output rendering, including adding `Out-String` to several `Format-*` cmdlets and setting `OutputRendering` to 'Ansi'. This is to avoid table and list output to wrap or cut of text. ### Improvements to output formatting: * `scripts/info.ps1`: * Added `Out-String` to the output of `Format-Table` and `Format-List` cmdlets. * `scripts/init.ps1`: * Added `Out-String` to the output of `Format-List` cmdlets. * Set `$PSStyle.OutputRendering` to 'Ansi' to enable ANSI output rendering. * `tests/info.ps1`: * Added `Out-String` to the output of `Format-List` cmdlets. ### Enabling ANSI output rendering: * `scripts/outputs.ps1`: * Modified the script to use `Out-String` for output formatting and added a loop to log each output property with ANSI color styling. ### Tests * `.github/workflows/TestWorkflow.yml`: * Enabled ANSI output rendering and used `Out-String` to format various outputs in multiple sections, including `Result - Json`, `Result - Object`, `Context`, `GitConfig`, `WISECAT`, and `Get-GitHubUser`. ## 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 fe43ffe commit 7f22b12

File tree

5 files changed

+46
-37
lines changed

5 files changed

+46
-37
lines changed

.github/workflows/TestWorkflow.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ jobs:
216216
Get-Content $env:GITHUB_OUTPUT -Raw | Set-GitHubStepSummary
217217
}
218218
219-
220219
- name: Run-test
221220
shell: pwsh
222221
env:
@@ -230,13 +229,14 @@ jobs:
230229
ComplexArrayJson: ${{ fromJson(steps.test.outputs.result).ComplexArrayJson }}
231230
run: |
232231
$result = $env:result | ConvertFrom-Json
232+
$PSStyle.OutputRendering = 'Ansi'
233233
234234
LogGroup 'Result - Json' {
235-
$env:result
235+
$env:result | Format-List | Out-String
236236
}
237237
238238
LogGroup 'Result - Object' {
239-
$result
239+
$result | Format-List | Out-String
240240
}
241241
242242
LogGroup "WISECAT" {
@@ -248,11 +248,11 @@ jobs:
248248
}
249249
250250
LogGroup "Context" {
251-
$env:Context
251+
$env:Context | Format-List | Out-String
252252
}
253253
254254
LogGroup "GitConfig" {
255-
$env:GitConfig
255+
$env:GitConfig | Format-List | Out-String
256256
}
257257
258258
LogGroup "Zen2" {
@@ -279,13 +279,13 @@ jobs:
279279
Set-GitHubStepSummary -Summary $env:WISECAT
280280
Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen'
281281
Write-Host ($result.Zen2)
282-
$result.Context | Format-List
282+
$result.Context | Format-List | Out-String
283283
$result.Context.GetType().Name
284284
if ($result.GitConfig -isnot [String]) {
285285
throw "GitConfig is not a PSCustomObject"
286286
}
287287
288-
$result.GitConfig | Format-List
288+
$result.GitConfig | Format-List | Out-String
289289
$result.GitConfig.GetType().Name
290290
if ($result.GitConfig -isnot [String]) {
291291
throw "GitConfig is a PSCustomObject"
@@ -348,7 +348,8 @@ jobs:
348348
env:
349349
Item: ${{ steps.test.outputs.item }}
350350
run: |
351-
$env:Item
351+
$PSStyle.OutputRendering = 'Ansi'
352+
$env:Item | Format-Table | Out-String
352353
$env:Item | ConvertFrom-Json
353354
354355
if (-not (Test-Json -Json $env:Item)) {
@@ -388,7 +389,7 @@ jobs:
388389
Prerelease: ${{ inputs.Prerelease }}
389390
Script: |
390391
LogGroup 'Get-GitHubUser' {
391-
Get-GitHubUser | Format-Table -AutoSize
392+
Get-GitHubUser | Format-Table -AutoSize | Out-String
392393
}
393394
394395
ActionTestWithUSERFGPAT:
@@ -406,7 +407,7 @@ jobs:
406407
Prerelease: ${{ inputs.Prerelease }}
407408
Script: |
408409
LogGroup 'Get-GitHubUser' {
409-
Get-GitHubUser | Format-Table -AutoSize
410+
Get-GitHubUser | Format-Table -AutoSize | Out-String
410411
}
411412
412413
ActionTestWithORGFGPAT:
@@ -424,7 +425,7 @@ jobs:
424425
Prerelease: ${{ inputs.Prerelease }}
425426
Script: |
426427
LogGroup 'Get-GitHubUser' {
427-
Get-GitHubUser | Format-Table -AutoSize
428+
Get-GitHubUser | Format-Table -AutoSize | Out-String
428429
}
429430
430431
ActionTestWithGitHubAppEnt:
@@ -443,18 +444,18 @@ jobs:
443444
Prerelease: ${{ inputs.Prerelease }}
444445
Script: |
445446
LogGroup 'Get-GitHubApp' {
446-
Get-GitHubApp | Format-Table -AutoSize
447+
Get-GitHubApp | Format-Table -AutoSize | Out-String
447448
}
448449
449450
LogGroup 'Get-GitHubAppInstallation' {
450-
Get-GitHubAppInstallation | Format-Table -AutoSize
451+
Get-GitHubAppInstallation | Format-Table -AutoSize | Out-String
451452
}
452453
453454
LogGroup 'Do something as an installation' {
454455
Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object {
455456
Connect-GitHub -Token $_.token -Silent
456-
Get-GitHubContext | Format-Table -AutoSize
457-
Get-GitHubGitConfig | Format-Table -AutoSize
457+
Get-GitHubContext | Format-Table -AutoSize | Out-String
458+
Get-GitHubGitConfig | Format-Table -AutoSize | Out-String
458459
}
459460
}
460461
@@ -474,17 +475,17 @@ jobs:
474475
Prerelease: ${{ inputs.Prerelease }}
475476
Script: |
476477
LogGroup 'Get-GitHubApp' {
477-
Get-GitHubApp | Format-Table -AutoSize
478+
Get-GitHubApp | Format-Table -AutoSize | Out-String
478479
}
479480
480481
LogGroup 'Get-GitHubAppInstallation' {
481-
Get-GitHubAppInstallation | Format-Table -AutoSize
482+
Get-GitHubAppInstallation | Format-Table -AutoSize | Out-String
482483
}
483484
484485
LogGroup 'Do something as an installation' {
485486
Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object {
486487
Connect-GitHub -Token $_.token -Silent
487-
Get-GitHubContext | Format-Table -AutoSize
488-
Get-GitHubGitConfig | Format-Table -AutoSize
488+
Get-GitHubContext | Format-Table -AutoSize | Out-String
489+
Get-GitHubGitConfig | Format-Table -AutoSize | Out-String
489490
}
490491
}

scripts/info.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ process {
2121
Write-Output $fenceStart
2222

2323
LogGroup ' - Installed modules' {
24-
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
24+
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize | Out-String
2525
}
2626

2727
LogGroup ' - GitHub connection - Default' {
2828
$context = Get-GitHubContext
29-
$context | Format-List
29+
$context | Format-List | Out-String
3030

3131
Write-Verbose "Token? [$([string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token))]"
3232
Write-Verbose "AuthType? [$($context.AuthType)] - [$($context.AuthType -ne 'APP')]"
@@ -44,11 +44,11 @@ process {
4444
}
4545

4646
LogGroup ' - GitHub connection - List' {
47-
Get-GitHubContext -ListAvailable | Format-Table
47+
Get-GitHubContext -ListAvailable | Format-Table | Out-String
4848
}
4949

5050
LogGroup ' - Configuration' {
51-
Get-GitHubConfig | Format-List
51+
Get-GitHubConfig | Format-List | Out-String
5252
}
5353

5454
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''

scripts/init.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ param()
44
begin {
55
$scriptName = $MyInvocation.MyCommand.Name
66
Write-Debug "[$scriptName] - Start"
7+
$PSStyle.OutputRendering = 'Ansi'
78
}
89

910
process {
@@ -35,7 +36,7 @@ process {
3536

3637
if ($showInit) {
3738
Write-Output 'Already installed:'
38-
$alreadyInstalled | Format-List
39+
$alreadyInstalled | Format-List | Out-String
3940
}
4041
if (-not $alreadyInstalled) {
4142
$params = @{
@@ -66,7 +67,7 @@ process {
6667
$alreadyImported = Get-Module -Name $Name
6768
if ($showInit) {
6869
Write-Output 'Already imported:'
69-
$alreadyImported | Format-List
70+
$alreadyImported | Format-List | Out-String
7071
}
7172
if (-not $alreadyImported) {
7273
Write-Verbose "Importing module: $Name"
@@ -88,7 +89,7 @@ process {
8889
}
8990
if ($showInit) {
9091
Write-Output 'Module status:'
91-
$moduleStatus | Format-List
92+
$moduleStatus | Format-List | Out-String
9293
Write-Output '::endgroup::'
9394
Write-Output '::group:: - Connect to GitHub'
9495
}

scripts/outputs.ps1

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ try {
2323
}
2424
$fenceStart = "┏━━┫ $fenceTitle - Outputs ┣━━━━━┓"
2525
Write-Output $fenceStart
26-
LogGroup ' - Outputs' {
27-
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
28-
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
29-
}
26+
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
27+
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
28+
}
3029

31-
if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
32-
Write-Warning "File not found: $env:GITHUB_OUTPUT"
33-
}
30+
if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
31+
Write-Warning "File not found: $env:GITHUB_OUTPUT"
32+
}
3433

35-
$result | Format-List
36-
Write-Output "Access outputs using `${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result).<output-name> }}"
34+
foreach ($output in $result.PSObject.Properties) {
35+
$blue = $PSStyle.Foreground.Blue
36+
$reset = $PSStyle.Reset
37+
LogGroup " - $blue$($output.Name)$reset" {
38+
$outputAccess = "Accessible via: [$blue`${{ fromJson(steps.$env:GITHUB_ACTION.outputs.result).$($output.Name) }}$reset]"
39+
$outputFence = ('' * ($outputAccess.Length - 9))
40+
Write-Output $outputAccess
41+
Write-Output $outputFence
42+
$output.Value | Format-List | Out-String
43+
}
3744
}
3845
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
3946
Write-Output $fenceEnd

tests/info.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#Requires -Modules GitHub
22

33
LogGroup ' - Get-GithubEventData' {
4-
Get-GitHubEventData | Format-List
4+
Get-GitHubEventData | Format-List | Out-String
55
}
66

77
LogGroup ' - Get-GithubRunnerData' {
8-
Get-GitHubRunnerData | Format-List
8+
Get-GitHubRunnerData | Format-List | Out-String
99
}

0 commit comments

Comments
 (0)