Skip to content

Fix preview Environment cleanup under GITHUB_TOKEN limits - #33

Merged
firtoz merged 2 commits into
mainfrom
cursor/fix-preview-env-delete-perm-c596
Jul 30, 2026
Merged

firtoz merged 2 commits into
mainfrom
cursor/fix-preview-env-delete-perm-c596

Conversation

@firtoz

@firtoz firtoz commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

Default GITHUB_TOKEN cannot delete GitHub Environments (HttpError: Resource not accessible by integration). Teardown was soft-failing on that delete after a successful Cloudflare destroy.

Changes

  • Register PR Deployments under a shared Environment named preview (PR number in payload/description) so teardown only needs to inactivate deployments
  • Treat legacy preview-pr-* delete denials as expected (info, not a scary soft-fail warning) when using GITHUB_TOKEN
  • Optional secret PREVIEW_ENV_ADMIN_TOKEN (classic PAT with repo) enables actual legacy Environment deletion during teardown
  • Docs + unit tests for match/permission helpers

Cleaning up preview-pr-31 now

  • Repo Settings → Environments → preview-pr-31 → Delete, or
  • bun run preview:cleanup:orphans -- --apply (uses your gh auth, which can delete Environments)

Test plan

  • bun test packages/scripts/src/cleanup-github-preview-env.test.ts
  • Merge and close a preview PR — teardown should succeed without the inaccessible soft-fail warning for new shared-preview deploys
  • Optional: set PREVIEW_ENV_ADMIN_TOKEN and confirm legacy preview-pr-* envs delete
Open in Web Open in Cursor 

Default GITHUB_TOKEN cannot delete Environments (Resource not accessible
by integration). Register PR Deployments under a shared `preview`
environment, treat legacy preview-pr-* delete denials as expected, and
allow optional PREVIEW_ENV_ADMIN_TOKEN for actual legacy env deletion.

Co-authored-by: Firtina Ozbalikchi <firtoz@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

PR preview

Status

Removed. Preview stack destroyed after merge.

Links

  • This PR preview run — workflow run
  • GitHub deployments inactivated (legacy preview-pr-33 Environment left — GITHUB_TOKEN cannot delete Environments; optional PREVIEW_ENV_ADMIN_TOKEN or orphan sweeper)

Updates automatically while the same-repo PR preview workflow runs.

@github-actions
github-actions Bot temporarily deployed to preview July 29, 2026 23:03 Destroyed
Operators can clear leftover preview-pr-* Environments after CF destroy
without Cloudflare credentials. Document the proper shared-preview fix
and one-shot sweep commands.

Co-authored-by: Firtina Ozbalikchi <firtoz@users.noreply.github.com>
@github-actions
github-actions Bot temporarily deployed to preview July 29, 2026 23:07 Destroyed
@firtoz
firtoz marked this pull request as ready for review July 30, 2026 06:50
@cursor

cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@firtoz
firtoz merged commit 1f2e78e into main Jul 30, 2026
11 checks passed
@firtoz
firtoz deleted the cursor/fix-preview-env-delete-perm-c596 branch July 30, 2026 06:50

This branch was successfully deployed

1 inactive deployment
staging — 9c0e8d86 Deployed Jul 30, 2026 by firtoz via Destroy PR preview #71
preview — 9c0e8d86 Deployed Jul 29, 2026 by github-actions[bot]
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.

2 participants