Skip to content

Harden stats workflow against invalid METRICS_TOKEN and document fine-grained PAT setup - #5

Merged
whozahm3d merged 2 commits into
mainfrom
copilot/fix-github-actions-build-job
Jun 6, 2026
Merged

Harden stats workflow against invalid METRICS_TOKEN and document fine-grained PAT setup#5
whozahm3d merged 2 commits into
mainfrom
copilot/fix-github-actions-build-job

Conversation

Copilot AI commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

The build job in Generate GitHub Stats failed because lowlighter/metrics received 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

    • Added a pre-check step that emits a warning when METRICS_TOKEN is absent or not a fine-grained PAT (github_pat_...).
    • Gated all metrics-generation steps so they only run when the token format is valid, preventing hard failure from token misconfiguration.
  • Setup/troubleshooting docs alignment

    • Updated token setup from classic PAT guidance to fine-grained PAT guidance.
    • Added required permission guidance and a troubleshooting entry for legacy or invalid token.
- name: Generate Stats Card
  if: ${{ startsWith(secrets.METRICS_TOKEN, 'github_pat_') }}
  uses: lowlighter/metrics@latest
  with:
    token: ${{ secrets.METRICS_TOKEN }}

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
Copilot AI requested a review from whozahm3d June 6, 2026 13:43

@whozahm3d whozahm3d left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

@whozahm3d
whozahm3d marked this pull request as ready for review June 6, 2026 13:45
Copilot AI review requested due to automatic review settings June 6, 2026 13:45
@whozahm3d
whozahm3d merged commit 674c72d into main Jun 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/metrics steps behind a METRICS_TOKEN prefix 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 thread SETUP.md
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 thread SETUP.md
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 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants