Skip to content

Add option to display GitHub API rate limits before and after script execution #88

@MariusStorhaug

Description

Context

When running GitHub Actions workflows that make many GitHub API calls, it is important to understand rate limit
consumption. Currently, the action provides no visibility into how many API requests have been used or remain
available for the authenticated runner. Without this information, diagnosing rate-limit-related failures requires
manually querying the API or adding temporary debugging steps to workflows.

Request

The action should optionally display the GitHub API rate limit status for the current runner — both before and
after the user script executes. Showing rate limits at both points makes it easy to see how many API calls the
script consumed during a run.

The feature should be off by default to keep logs clean for workflows that do not need this information, and
toggled on via an input parameter when visibility is needed.

Desired experience

When the feature is enabled, the action log output includes two fenced rate limit sections — one appearing before the
user script runs and one after — using the same visual border style (┏━━┫ ... ┣━━━━━━━━┓ / ┗━━━━━━━━━━━━━━━━━━┛)
used by the existing Info and Outputs sections. Each section should display rate limit details for core, search,
graphql, and other resource categories as returned by
Get-GitHubRateLimit,
including remaining quota, limit, used count, and reset time.

Acceptance criteria

  • A new input parameter controls whether rate limit information is displayed, defaulting to off
  • Rate limit information is displayed inside fenced borders before the user script runs
  • Rate limit information is displayed inside fenced borders after the user script runs
  • The output uses the same visual fence style as the existing Info and Outputs sections
  • When the feature is off (default), no rate limit output appears in the logs
  • The rate limit data covers all resource categories returned by the GitHub API
    (GET /rate_limit)

Technical decisions

Input naming: Add a ShowRateLimit input defaulting to 'false', following the existing convention
of ShowInfo, ShowInit, and ShowOutput.

Environment variable: Pass the value via PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit, consistent with
all other inputs.

Script placement: Create a new file src/ratelimit.ps1 responsible for displaying rate limit information.
This script is called twice in the action.yml run block:

  1. After info.ps1 and before the user script (${{ inputs.Script }})
  2. After outputs.ps1 and before the finally/clean.ps1 block

This placement ensures the rate limit borders appear inside the action's data output region, sandwiching the
user script execution.

Fence labels: Use Rate Limit (Pre) and Rate Limit (Post) as the fence title suffixes to distinguish the
two sections. The script should accept a parameter or use an environment variable to differentiate between the
pre and post invocations.

Rate limit command: Use Get-GitHubRateLimit
from the GitHub PowerShell module. This returns objects with Name, Limit, Used, Remaining, ResetsAt,
and ResetsIn properties per resource category. Display these in a formatted table inside a LogGroup for
collapsibility.

Guard pattern: Follow the same early-return pattern used in info.ps1 and outputs.ps1 — check the
environment variable at the top and return immediately if the feature is disabled:

if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -ne 'true') {
    return
}

Module dependency: The script requires the GitHub module (#Requires -Modules GitHub), same as info.ps1
and outputs.ps1.


Implementation plan

Action definition

  • Add ShowRateLimit input to action.yml with description, required: false, and default: 'false'
  • Add PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit: ${{ inputs.ShowRateLimit }} to the environment variables in the composite step

Rate limit script

  • Create src/ratelimit.ps1 with #Requires -Modules GitHub and [CmdletBinding()] param() header
  • Add environment variable guard — return early if ShowRateLimit is not 'true'
  • Accept a label parameter (e.g., via an environment variable PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL) to distinguish Pre vs Post
  • Render fenced border using the ┏━━┫ {Name} - Rate Limit ({Label}) ┣━━━━━━━━┓ / ┗━━━━━━━━━━━━━━━━━━┛ pattern
  • Call Get-GitHubRateLimit and display the results in a formatted table inside a LogGroup

Execution flow

  • Add first invocation of src/ratelimit.ps1 in action.yml after info.ps1 and before ${{ inputs.Script }}, setting the label to Pre
  • Add second invocation of src/ratelimit.ps1 in action.yml after outputs.ps1 and before the finally block, setting the label to Post

Tests

  • Add test coverage in tests/ to verify rate limit output appears when ShowRateLimit is enabled
  • Verify no output when ShowRateLimit is disabled or not set

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions