Skip to content

Commit b71ca93

Browse files
hesreallyhimclaude
andcommitted
docs: write comprehensive README.md
Add usage example, inputs/outputs reference, example summary output, how it works overview, supported platforms, limitations, and development instructions. Replaces the empty placeholder. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e238003 commit b71ca93

1 file changed

Lines changed: 86 additions & 1 deletion

File tree

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,86 @@
1-
# Github Activity Usage Monitor
1+
# github-api-usage-monitor
2+
3+
A GitHub Action that monitors API rate-limit usage during a CI job. It polls `/rate_limit` in a background process throughout the job, then renders a per-bucket usage summary in the step summary.
4+
5+
## Why
6+
7+
GitHub Actions workflows consume API rate limits, but there's no built-in way to see how much. This action runs a lightweight background poller for the duration of your job and reports exactly which buckets were used, how much, and how close you are to the ceiling.
8+
9+
## Quick Start
10+
11+
```yaml
12+
- uses: hesreallyhim/github-api-usage-monitor@main
13+
```
14+
15+
That's it. The action uses the pre/post hook lifecycle — it starts monitoring automatically before your first step and reports after your last step. No `start`/`stop` steps needed.
16+
17+
## How It Works
18+
19+
1. **Pre hook** — spawns a detached background process that polls `GET /rate_limit` with adaptive scheduling
20+
2. **Main** — no-op (your workflow steps run here)
21+
3. **Post hook** — kills the poller, performs a final poll, and writes a summary to `$GITHUB_STEP_SUMMARY`
22+
23+
The poller uses constant-space aggregation — it tracks per-bucket deltas across reset windows without storing historical samples.
24+
25+
## Inputs
26+
27+
| Input | Required | Default | Description |
28+
|-------|----------|---------|-------------|
29+
| `token` | No | `${{ github.token }}` | GitHub token for API authentication |
30+
31+
## Outputs
32+
33+
| Output | Description |
34+
|--------|-------------|
35+
| `state_json` | Finalized reducer state as a JSON string |
36+
| `poll_log_json` | Poll log entries as a JSON array string |
37+
38+
### Using outputs in downstream steps
39+
40+
```yaml
41+
- uses: hesreallyhim/github-api-usage-monitor@main
42+
id: monitor
43+
44+
- name: Check usage
45+
run: |
46+
echo '${{ steps.monitor.outputs.state_json }}' | jq '.buckets.core.total_used'
47+
```
48+
49+
## Example Summary Output
50+
51+
The action writes a markdown table to the GitHub step summary:
52+
53+
> **Duration:** 5m 32s | **Polls:** 12 | **Failures:** 0
54+
>
55+
> | Bucket | Used (this job) | Remaining | Limit | Windows Crossed |
56+
> |--------|---------------:|----------:|------:|:-:|
57+
> | core | 47 | 4,953 | 5,000 | 0 |
58+
> | graphql | 12 | 4,988 | 5,000 | 0 |
59+
> | search | 3 | 27 | 30 | 1 |
60+
61+
## Supported Platforms
62+
63+
- Linux (GitHub-hosted runners)
64+
- macOS (GitHub-hosted runners)
65+
66+
Windows is not supported (the action will fail fast with a clear error).
67+
68+
## Limitations
69+
70+
- **Shared rate-limit pool** — all jobs in a repository share the same token's rate limits. If concurrent workflows run, usage from other jobs will appear in the totals.
71+
- **Polling resolution** — the adaptive poller targets polls near bucket resets, but there's an inherent ~3-5s uncertainty window. Usage between the last poll and a reset boundary may be missed.
72+
- **No per-request attribution** — the action reports aggregate bucket usage, not which specific API calls consumed quota.
73+
74+
## Development
75+
76+
```bash
77+
npm install
78+
npm test # Unit tests (vitest, 128 tests)
79+
npm run typecheck # tsc --noEmit
80+
npm run lint # ESLint
81+
npm run build:all # Bundle all 4 entry points with ncc
82+
```
83+
84+
## License
85+
86+
MIT

0 commit comments

Comments
 (0)