Skip to content

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

Closed

Description

@potatowagon

Summary

The Cleanup Preview Deployments workflow (.github/workflows/cleanup-previews.yml) fails with a 403 on git push to gh-pages for every PR opened from a fork. Same-repo PRs succeed. This is deterministic, not a flake.

Symptom

remote: Permission to facebook/astryx.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/facebook/astryx/': The requested URL returned error: 403
::error::Failed to push cleanup after 5 attempts

The retry loop's message ("Push rejected (concurrent gh-pages update) — retrying") is misleading: the actual failure is a permissions 403, not a fetch-first race, so all 5 retries burn against the same denial and the job exits 1.

Root cause

The workflow triggers on pull_request: [closed]. For PRs opened from a fork, GitHub caps GITHUB_TOKEN to read-only regardless of the permissions: contents: write declaration in the YAML (the declaration is a ceiling, not a grant). So the git push to gh-pages is denied.

For same-repo branches, the token gets full write, so the push succeeds.

Evidence

Split of the last ~92 cleanup runs by head_repository:

head_repository outcome
facebook/astryx (same-repo) ✅ all pass
fork (potatowagon/, athz/, humbertovirtudes/, jiunshinn/, AKnassa/, bhamodi/ …) ❌ all fail

22/22 failures are fork PRs. 0 same-repo runs failed. Two runs from the same day, both deleting exactly 1 stale path (identical work):

Same workflow, same work, opposite result — the only variable is fork vs. same-repo.

The repo already solved this for deploys

.github/workflows/deploy-preview.yml was migrated off pull_request to workflow_run for exactly this reason. Its own header comment says:

a pull_request workflow triggered by a fork gets a READ-ONLY token and can't push to gh-pages, which is why fork PRs never got a preview. workflow_run runs from the base repo with the repo's own write token…

cleanup-previews.yml was never given the same treatment.

Impact

  • Every fork contributor gets a red ❌ on the post-close cleanup job.
  • It does not block PR merge (cleanup is not a required check), so it's cosmetic noise — but it's persistent and misleading.
  • The daily schedule cron runs with the base-repo write token and eventually clears the backlog, which is why the gh-pages tree doesn't grow unbounded.

Proposed fix

Migrate cleanup-previews.yml off the fork-tainted pull_request trigger so it always runs with the base repo's write token — mirroring deploy-preview.yml. Options, in order of preference:

  1. workflow_run keyed off the PR-close signal (consistent with deploy-preview.yml).
  2. Rely on the existing daily schedule cron + workflow_dispatch and simply drop the pull_request trigger — trades prompt cleanup for guaranteed-green runs (the cron already handles correctness).

Additionally: make the push-retry loop distinguish a hard 403 (permissions) from a [rejected] (fetch first) race and fail fast on the former instead of retrying 5× with a misleading message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions