🚀 [Minor]: GitHub API rate limit details now available in action logs by MariusStorhaug · Pull Request #89 · PSModule/GitHub-Script · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/TestWorkflow.yml
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ inputs:
description: Show the output of the script.
required: false
default: 'false'
ShowRateLimit:
description: Show GitHub API rate limit information before and after script execution.
required: false
default: 'false'
ErrorView:
description: Configure the PowerShell `$ErrorView` variable. You can use full names ('NormalView', 'CategoryView', 'ConciseView', 'DetailedView'). It matches on partials.
required: false
Expand Down Expand Up @@ -91,6 +95,7 @@ runs:
PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo: ${{ inputs.ShowInfo }}
PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }}
PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit: ${{ inputs.ShowRateLimit }}
PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }}
PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }}
run: |
Expand Down
69 changes: 39 additions & 30 deletions src/info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,57 @@ process {
try {
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name

Write-Debug "[$scriptName] - ShowInfo: $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo"
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo -ne 'true') {
$showInfo = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo -eq 'true'
$showRateLimit = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -eq 'true'

Write-Debug "[$scriptName] - ShowInfo: $showInfo"
Write-Debug "[$scriptName] - ShowRateLimit: $showRateLimit"
if (-not $showInfo -and -not $showRateLimit) {
return
}

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

LogGroup ' - Installed modules' {
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize | Out-String
}
if ($showInfo) {
LogGroup ' - Installed modules' {
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize | Out-String
}

LogGroup ' - GitHub connection - Default' {
$context = Get-GitHubContext
$context | Format-List | Out-String

LogGroup ' - GitHub connection - Default' {
$context = Get-GitHubContext
$context | Format-List | Out-String

Write-Verbose "Token? [$([string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token))]"
Write-Verbose "AuthType? [$($context.AuthType)] - [$($context.AuthType -ne 'APP')]"
Write-Verbose "gh auth? [$($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token))]"

if ($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token)) {
Write-Output 'GitHub CLI status:'
$before = $LASTEXITCODE
gh auth status
if ($LASTEXITCODE -ne $before) {
Write-Warning "LASTEXITCODE has changed [$LASTEXITCODE]"
$global:LASTEXITCODE = $before
Write-Verbose "Token? [$([string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token))]"
Write-Verbose "AuthType? [$($context.AuthType)] - [$($context.AuthType -ne 'APP')]"
Write-Verbose "gh auth? [$($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token))]"

if ($context.AuthType -ne 'APP' -and -not [string]::IsNullOrEmpty($env:PSMODULE_GITHUB_SCRIPT_INPUT_Token)) {
Write-Output 'GitHub CLI status:'
$before = $LASTEXITCODE
gh auth status
if ($LASTEXITCODE -ne $before) {
Write-Warning "LASTEXITCODE has changed [$LASTEXITCODE]"
$global:LASTEXITCODE = $before
}
}
}
}

LogGroup ' - GitHub connection - List' {
Get-GitHubContext -ListAvailable | Format-Table | Out-String
}
LogGroup ' - GitHub connection - List' {
Get-GitHubContext -ListAvailable | Format-Table | Out-String
}

LogGroup ' - Configuration' {
Get-GitHubConfig | Format-List | Out-String
}
LogGroup ' - Configuration' {
Get-GitHubConfig | Format-List | Out-String
}

LogGroup ' - Event Information' {
Get-GitHubEventData | Format-List | Out-String
}
LogGroup ' - Event Information' {
Get-GitHubEventData | Format-List | Out-String
}
} # end if ($showInfo)

$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Pre'
& "$PSScriptRoot/ratelimit.ps1"

$fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛'
Write-Output $fenceEnd
Expand Down
49 changes: 31 additions & 18 deletions src/outputs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,46 @@ Write-Debug "[$scriptName] - Start"
try {
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name

Write-Debug "[$scriptName] - ShowOutput: $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput"
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput -ne 'true') {
return
$showOutput = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput -eq 'true'
$showRateLimit = $env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -eq 'true'

Write-Debug "[$scriptName] - ShowOutput: $showOutput"
Write-Debug "[$scriptName] - ShowRateLimit: $showRateLimit"

$result = $null
if ($showOutput) {
$result = (Get-GitHubOutput).result
Write-Debug "[$scriptName] - Result: $(-not $result)"
}

$result = (Get-GitHubOutput).result
Write-Debug "[$scriptName] - Result: $(-not $result)"
if (-not $result) {
if (-not $result -and -not $showRateLimit) {
return
}

$fenceStart = "┏━━┫ $fenceTitle - Outputs ┣━━━━━┓"
Write-Output $fenceStart
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
}

if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
Write-Warning "File not found: $env:GITHUB_OUTPUT"
}
if ($result) {
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) {
Write-GitHubWarning 'Outputs cannot be accessed as the step has no ID.'
}

foreach ($output in $result.PSObject.Properties) {
$blue = $PSStyle.Foreground.Blue
$reset = $PSStyle.Reset
LogGroup " - $blue$($output.Name)$reset" {
$output.Value | Format-List | Out-String
if (-not (Test-Path -Path $env:GITHUB_OUTPUT)) {
Write-Warning "File not found: $env:GITHUB_OUTPUT"
}
}

foreach ($output in $result.PSObject.Properties) {
$blue = $PSStyle.Foreground.Blue
$reset = $PSStyle.Reset
LogGroup " - $blue$($output.Name)$reset" {
$output.Value | Format-List | Out-String
}
}
} # end if ($result)

$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Post'
& "$PSScriptRoot/ratelimit.ps1"

$fenceEnd = '┗' + ('━' * ($fenceStart.Length - 2)) + '┛'
Write-Output $fenceEnd
} catch {
Expand Down
18 changes: 18 additions & 0 deletions src/ratelimit.ps1
Loading