Skip to content

Commit 8b8c9ef

Browse files
Move rate limit output inside existing Info and Outputs fences
1 parent b2b048d commit 8b8c9ef

4 files changed

Lines changed: 43 additions & 41 deletions

File tree

action.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ runs:
106106
try {
107107
${{ github.action_path }}/src/init.ps1
108108
${{ github.action_path }}/src/info.ps1
109-
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Pre'
110-
${{ github.action_path }}/src/ratelimit.ps1
111109
${{ inputs.Script }}
112110
${{ github.action_path }}/src/outputs.ps1
113-
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Post'
114-
${{ github.action_path }}/src/ratelimit.ps1
115111
}
116112
finally {
117113
${{ github.action_path }}/src/clean.ps1

src/info.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules GitHub
1+
#Requires -Modules GitHub
22

33
[CmdletBinding()]
44
param()
@@ -12,14 +12,19 @@ process {
1212
try {
1313
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name
1414

15-
Write-Debug "[$scriptName] - ShowInfo: $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo"
16-
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo -ne 'true') {
15+
$showInfo = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo -eq 'true'
16+
$showRateLimit = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -eq 'true'
17+
18+
Write-Debug "[$scriptName] - ShowInfo: $showInfo"
19+
Write-Debug "[$scriptName] - ShowRateLimit: $showRateLimit"
20+
if (-not $showInfo -and -not $showRateLimit) {
1721
return
1822
}
1923

2024
$fenceStart = "┏━━┫ $fenceTitle - Info ┣━━━━━━━━┓"
2125
Write-Output $fenceStart
2226

27+
if ($showInfo) {
2328
LogGroup ' - Installed modules' {
2429
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize | Out-String
2530
}
@@ -54,6 +59,10 @@ process {
5459
LogGroup ' - Event Information' {
5560
Get-GitHubEventData | Format-List | Out-String
5661
}
62+
} # end if ($showInfo)
63+
64+
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Pre'
65+
& "$PSScriptRoot/ratelimit.ps1"
5766

5867
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
5968
Write-Output $fenceEnd

src/outputs.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules GitHub
1+
#Requires -Modules GitHub
22

33
[CmdletBinding()]
44
param()
@@ -9,18 +9,26 @@ Write-Debug "[$scriptName] - Start"
99
try {
1010
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name
1111

12-
Write-Debug "[$scriptName] - ShowOutput: $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput"
13-
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput -ne 'true') {
14-
return
12+
$showOutput = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput -eq 'true'
13+
$showRateLimit = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -eq 'true'
14+
15+
Write-Debug "[$scriptName] - ShowOutput: $showOutput"
16+
Write-Debug "[$scriptName] - ShowRateLimit: $showRateLimit"
17+
18+
$result = $null
19+
if ($showOutput) {
20+
$result = (Get-GitHubOutput).result
21+
Write-Debug "[$scriptName] - Result: $(-not $result)"
1522
}
1623

17-
$result = (Get-GitHubOutput).result
18-
Write-Debug "[$scriptName] - Result: $(-not $result)"
19-
if (-not $result) {
24+
if (-not $result -and -not $showRateLimit) {
2025
return
2126
}
27+
2228
$fenceStart = "┏━━┫ $fenceTitle - Outputs ┣━━━━━┓"
2329
Write-Output $fenceStart
30+
31+
if ($result) {
2432
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
2533
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
2634
}
@@ -36,6 +44,11 @@ try {
3644
$output.Value | Format-List | Out-String
3745
}
3846
}
47+
} # end if ($result)
48+
49+
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Post'
50+
& "$PSScriptRoot/ratelimit.ps1"
51+
3952
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
4053
Write-Output $fenceEnd
4154
} catch {

src/ratelimit.ps1

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

3-
[CmdletBinding()]
4-
param()
3+
# Helper script - called from info.ps1 and outputs.ps1 to display rate limit information.
4+
# Expects $env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL to be set to 'Pre' or 'Post'.
55

6-
$scriptName = $MyInvocation.MyCommand.Name
7-
Write-Debug "[$scriptName] - Start"
8-
9-
try {
10-
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -ne 'true') {
11-
return
12-
}
13-
14-
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name
15-
$label = $env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL
6+
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -ne 'true') {
7+
return
8+
}
169

17-
$fenceStart = "┏━━┫ $fenceTitle - Rate Limit ($label) ┣━━━━━━━━┓"
18-
Write-Output $fenceStart
10+
$label = $env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL
1911

20-
LogGroup " - Rate Limit ($label)" {
21-
try {
22-
Get-GitHubRateLimit | Format-Table -AutoSize | Out-String
23-
} catch {
24-
Write-Warning "Could not retrieve rate limit information: $($_.Exception.Message)"
25-
}
12+
LogGroup " - Rate Limit ($label)" {
13+
try {
14+
Get-GitHubRateLimit | Format-Table -AutoSize | Out-String
15+
} catch {
16+
Write-Warning "Could not retrieve rate limit information: $($_.Exception.Message)"
2617
}
27-
28-
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
29-
Write-Output $fenceEnd
30-
} catch {
31-
throw $_
3218
}
33-
34-
Write-Debug "[$scriptName] - End"

0 commit comments

Comments
 (0)