Skip to content

fix(ci): run cleanup-previews on workflow_run so fork PRs get a write token - #4674

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/cleanup-previews-fork-403
Aug 3, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/cleanup-previews-fork-403

Conversation

@potatowagon

@potatowagon potatowagon commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes the Cleanup Preview Deployments workflow, which 403'd on the gh-pages push for every fork PR.

Closes #4672.

Why

The workflow triggered on pull_request: [closed]. For PRs from a fork, GitHub hands the workflow a read-only GITHUB_TOKEN regardless of the permissions: contents: write declaration (the declaration is a ceiling, not a grant), so git push origin gh-pages was denied:

remote: Permission to facebook/astryx.git denied to github-actions[bot].
fatal: ... error: 403

Evidence: 22/22 recent cleanup failures were fork PRs; 0 same-repo runs failed. Two same-day runs deleting identical work (both Summary: 1 items deleted) — the only variable was fork vs. same-repo:

The retry loop made it worse: it treated the 403 as a [rejected] (fetch first) race and burned all 5 attempts behind a misleading "concurrent gh-pages update" message.

How

  1. Trigger on workflow_run (CI completed) instead of pull_request — same migration deploy-preview.yml already did for the exact same reason. workflow_run runs from the base repo with the repo's own write token, so cleanup works for fork PRs too. The daily schedule cron and workflow_dispatch are kept.
    • The cleanup doesn't need the closed event: it reconciles on-disk pr/ dirs against the live open-PR list (gh pr list) every run, so firing on any PR's CI completion is sufficient to GC closed/merged previews.
    • Added an if: guard so only pull_request-triggered CI runs react (matches deploy-preview.yml); scheduled/manual runs always proceed.
  2. Fail fast on a real 403/permission denial in the push-retry loop instead of retrying 5× — retrying can never fix a permissions cap. Genuine fetch-first races still retry as before.

Safety

No change to what the job touches — it still only checks out gh-pages and deletes stale paths. It never checks out or runs PR-controlled code.

Testing

  • YAML validated.
  • Push-failure branch logic tested under set -eo pipefail (GitHub's bash default): a 403 output is detected and fast-aborts with the real cause; a fetch-first rejection falls through to retry.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 3, 2026
@vercel

vercel Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 3, 2026 8:45am

Request Review

@cixzhang
cixzhang enabled auto-merge (squash) August 3, 2026 09:27
@cixzhang
cixzhang merged commit a2cd9dd into main Aug 3, 2026
19 of 20 checks passed
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 3, 2026
@github-actions
github-actions Bot deleted the navi/fix/cleanup-previews-fork-403 branch August 4, 2026 19:16

This branch was successfully deployed

1 active deployment
Preview — 0f8fca95 Deployed Aug 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cleanup-previews.yml 403s on gh-pages push for all fork PRs (fork GITHUB_TOKEN is read-only)

2 participants