Harden stats workflow against invalid METRICS_TOKEN and document fine-grained PAT setup - #5
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix the failing GitHub Actions job build
Harden stats workflow against invalid METRICS_TOKEN and document fine-grained PAT setup
Jun 6, 2026
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent the “Generate GitHub Stats” workflow from hard-failing when METRICS_TOKEN is misconfigured, and to update SETUP.md so token setup matches what the workflow expects.
Changes:
- Added a token-format precheck warning step in the stats workflow.
- Gated all
lowlighter/metricssteps behind aMETRICS_TOKENprefix check. - Updated setup/troubleshooting docs to recommend fine-grained PAT creation and related permissions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
SETUP.md |
Updates token creation and troubleshooting guidance for METRICS_TOKEN. |
.github/workflows/generate-stats.yml |
Adds token precheck + conditional gating around metrics generation steps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+20
to
+24
| - name: Check METRICS_TOKEN format | ||
| if: ${{ !startsWith(secrets.METRICS_TOKEN, 'github_pat_') }} | ||
| run: | | ||
| echo "::warning::METRICS_TOKEN is missing or uses a legacy format. Add a fine-grained personal access token (github_pat_) as the METRICS_TOKEN secret to generate stats cards." | ||
|
|
|
|
||
| # ── Card 1: General Stats ────────────────────────────────────────────── | ||
| - name: Generate Stats Card | ||
| if: ${{ startsWith(secrets.METRICS_TOKEN, 'github_pat_') }} |
|
|
||
| # ── Card 2: Top Languages ────────────────────────────────────────────── | ||
| - name: Generate Languages Card | ||
| if: ${{ startsWith(secrets.METRICS_TOKEN, 'github_pat_') }} |
|
|
||
| # ── Card 3: Contribution Calendar ───────────────────────────────────── | ||
| - name: Generate Isometric Calendar | ||
| if: ${{ startsWith(secrets.METRICS_TOKEN, 'github_pat_') }} |
Comment on lines
+6
to
10
| ### Step 1 — Create a Fine-Grained Personal Access Token | ||
|
|
||
| 1. Go to **GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)** | ||
| 2. Click **"Generate new token (classic)"** | ||
| 1. Go to **GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens** | ||
| 2. Click **"Generate new token"** | ||
| 3. Name it: `METRICS_TOKEN` |
Comment on lines
+75
to
+76
| | Action fails with "legacy or invalid token" | Regenerate a **fine-grained** PAT (`github_pat_...`) and save it as `METRICS_TOKEN` | | ||
| | Action fails with "403 forbidden" | Token permissions are wrong — ensure **Contents: Read and write** plus profile/metadata read access | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
buildjob inGenerate GitHub Statsfailed becauselowlighter/metricsreceived a missing/legacy token (legacy or invalid token), causing the first card generation step to exit non-zero. This change makes token handling explicit in workflow logic and aligns setup docs with the token format the action expects.Workflow guardrails
METRICS_TOKENis absent or not a fine-grained PAT (github_pat_...).Setup/troubleshooting docs alignment
legacy or invalid token.