Skip to content

feat: auto-cleanup Cloudflare preview alias on PR close - #189

Merged
ayoub3bidi merged 2 commits into
developfrom
feat/pr-preview-cleanup
Jun 27, 2026
Merged

feat: auto-cleanup Cloudflare preview alias on PR close#189
ayoub3bidi merged 2 commits into
developfrom
feat/pr-preview-cleanup

Conversation

@ayoub3bidi

@ayoub3bidi ayoub3bidi commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Contribution workflow

  • Base branch is develop: This PR targets develop, not main.
  • Guidelines and docs: I have read CONTRIBUTING.md and the docs relevant to my change.
  • This template: I kept the PR template structure and filled in the sections below that apply to this change.

Description

Adds an automatic cleanup job that deletes the Cloudflare Workers preview alias (pr-N-bayan-flow-staging.workers.dev) when a PR is closed or merged. Without this, orphaned preview aliases accumulate indefinitely — they still resolve and consume from the free tier request pool.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)

Related Issues

N/A

Changes Made

  • Added closed to the pull_request trigger types in preview-cloudflare.yml
  • Split the workflow into two jobs:
    • preview — runs only on opened | synchronize | reopened (lint, tests, build, upload, comment)
    • cleanup — runs only on closed (minimal checkout + wrangler versions delete --alias)
  • Old preview job now guards against running on closed via github.event.action != 'closed'

Testing

  • No existing tests affected (workflow change only)
  • Manual testing completed (workflow is self-validating on next PR close)

Code Quality

  • Code follows the project's coding standards
  • ESLint passes (pnpm lint)
  • Prettier formatting applied (pnpm format)

Performance Impact

  • No performance impact

Breaking Changes

  • None

Checklist

  • I have completed the Contribution workflow checklist at the top of this template
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Additional Notes

The cleanup job still does a minimal checkout + pnpm install because wrangler versions delete needs the wrangler.jsonc config to resolve the staging environment.

Summary by CodeRabbit

  • Chores
    • Improved preview environment handling for pull requests.
    • Preview builds now avoid running in cases where they shouldn’t, helping prevent unnecessary updates.
    • When a pull request is closed, its associated preview version is automatically cleaned up to keep environments tidy.

Only the  job runs on  events (no lint/tests/build).
The  job skips closed PRs entirely.
@netlify

netlify Bot commented Jun 27, 2026

Copy link
Copy Markdown

Deploy Preview for dev-bayanflow ready!

Name Link
🔨 Latest commit a7e6935
🔍 Latest deploy log https://app.netlify.com/projects/dev-bayanflow/deploys/6a3faa8d60a2ee000879cba3
😎 Deploy Preview https://deploy-preview-189--dev-bayanflow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the ci Workflows label Jun 27, 2026
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 810cb505-e6b7-4081-bf00-4d8d43acdce9

📥 Commits

Reviewing files that changed from the base of the PR and between a2f0f31 and a7e6935.

📒 Files selected for processing (1)
  • .github/workflows/preview-cloudflare.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/preview-cloudflare.yml

📝 Walkthrough

Walkthrough

The workflow now includes pull_request closed events. The preview upload job skips closed actions, and a new close-time job sets up Node and pnpm, installs dependencies, finds the matching Cloudflare Workers staging version tagged for the PR, and deletes it if present.

Changes

Cloudflare PR preview lifecycle

Layer / File(s) Summary
Closed-event trigger and upload gate
.github/workflows/preview-cloudflare.yml
The pull_request trigger includes closed, and the upload job skips closed events while keeping the same-repo check.
Preview cleanup job
.github/workflows/preview-cloudflare.yml
A close-only job sets up checkout, Node, pnpm, and dependencies, then lists staging versions tagged pr-<PR number> and deletes the matching version when found.

Sequence Diagram(s)

sequenceDiagram
  participant PR as GitHub pull request
  participant WF as preview-cloudflare workflow
  participant Script as cleanup shell script
  participant CF as Cloudflare Workers staging
  PR->>WF: pull_request closed event
  WF->>Script: run Cleanup preview on PR close
  Script->>CF: wrangler versions list tag pr-<PR number>
  CF-->>Script: matching staging version or none
  alt version found
    Script->>CF: delete the matched version
  else no version found
    Script-->>WF: log no preview version exists
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ayoub3bidi/bayan-flow#183: Adds pr-<N> preview upload/commenting, and this PR adds the close-time cleanup for the same preview versions.

Poem

A little rabbit hopped through the cloud,
Saw preview branches buzzing loud.
On close I nibble the old tag away,
Then tidy the sky for a fresher day.
Hop hop! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main workflow change: automatic cleanup of Cloudflare preview aliases when a PR closes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pr-preview-cleanup

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 27, 2026

Copy link
Copy Markdown

Preview for Bayan Flow Staging ready!

Name Link
🔨 Latest commit a7e6935
🔍 Latest deploy log https://github.com/ayoub3bidi/bayan-flow/actions/runs/28286977086
😎 Deploy Preview https://pr-189-bayan-flow-staging.ayoub3bidi.workers.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

Preview alias pr-189 on the staging worker. Updates automatically with new commits.

@ayoub3bidi ayoub3bidi self-assigned this Jun 27, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/preview-cloudflare.yml:
- Around line 140-151: The cleanup job in the workflow is still checking out the
repository with default credentials and using pnpm caching before running
dependency installation, which should be hardened. Update the checkout step in
this cleanup path to disable persisted credentials the same way as the preview
job, and remove the pnpm cache configuration from actions/setup-node before the
pnpm install step. Keep the changes localized to the cleanup job steps around
actions/checkout, actions/setup-node, and pnpm install.
- Line 135: The cleanup step in the preview workflow is missing the same
same-repo guard used by the preview upload job, so it can run for closed PRs
from forks and attempt to delete aliases it never created. Update the cleanup
condition in the workflow so the job gated by github.event.action == 'closed'
also checks the same repository ownership/same-repo criteria as the preview job,
using the existing preview job gate logic as the reference.
- Around line 153-161: The preview cleanup step is using an unsupported Wrangler
alias flag, so update the Delete preview alias workflow step to use the
supported Wrangler preview-alias cleanup approach instead of versions delete
--alias. Adjust the command in the cloudflare/wrangler-action invocation so it
matches the same preview alias mechanism used by the upload step, and keep the
pr-${{ github.event.pull_request.number }} alias reference consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ec6a51a2-378d-46e5-b3ad-ed80f2c6511d

📥 Commits

Reviewing files that changed from the base of the PR and between d88dc58 and 8e2ba0c.

📒 Files selected for processing (1)
  • .github/workflows/preview-cloudflare.yml

Comment thread .github/workflows/preview-cloudflare.yml Outdated
Comment thread .github/workflows/preview-cloudflare.yml
Comment thread .github/workflows/preview-cloudflare.yml Outdated
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

The agent generated fixes only for .github/workflows/ files, which cannot be committed due to permission restrictions. Please apply these changes manually.


⚠️ 1 file(s) could not be committed — the agent does not have permission to push to .github/workflows/. Please apply these changes manually:

.github/workflows/preview-cloudflare.yml — 3 changes:

Lines 132–143
 
   cleanup:
     name: Cleanup preview on PR close
-    if: github.event.action == 'closed'
+    if: github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository
     runs-on: ubuntu-latest
     permissions:
       contents: read
     steps:
       - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
+        with:
+          persist-credentials: false
 
       - uses: pnpm/action-setup@f40ffcd9367d9f12939873eb1018b921a783ffaa # v4
         with:
Lines 146–152
       - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
         with:
           node-version: 24.11.1
-          cache: pnpm
 
       - run: pnpm install --frozen-lockfile
Lines 157–161
           accountId: ${{ secrets.CF_ACCOUNT_ID }}
           packageManager: pnpm
           command: >-
-            versions delete --alias pr-${{ github.event.pull_request.number }}
-            --env staging
+            versions upload --env staging
+            --preview-alias ""
+            --tag pr-${{ github.event.pull_request.number }}

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 3 unresolved review comments.

Files modified:

  • package.json

Commit: a2f0f31ad0e0b7202260217df7920485c8814cda

The changes have been pushed to the feat/pr-preview-cleanup branch.

Time taken: 3m 46s


⚠️ 1 file(s) could not be committed — the agent does not have permission to push to .github/workflows/. Please apply these changes manually:

.github/workflows/preview-cloudflare.yml — 3 changes:

Lines 132–143
 
   cleanup:
     name: Cleanup preview on PR close
-    if: github.event.action == 'closed'
+    if: github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository
     runs-on: ubuntu-latest
     permissions:
       contents: read
     steps:
       - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
+        with:
+          persist-credentials: false
 
       - uses: pnpm/action-setup@f40ffcd9367d9f12939873eb1018b921a783ffaa # v4
         with:
Lines 146–152
       - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
         with:
           node-version: 24.11.1
-          cache: pnpm
 
       - run: pnpm install --frozen-lockfile
Lines 157–161
           accountId: ${{ secrets.CF_ACCOUNT_ID }}
           packageManager: pnpm
           command: >-
-            versions delete --alias pr-${{ github.event.pull_request.number }}
-            --env staging
+            versions upload --env staging
+            --preview-alias ""

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Around line 100-101: Move the vite substitution from the top-level overrides
block into pnpm’s override configuration so it continues to apply. Update the
package.json pnpm.overrides section for pnpm <11, or place the mapping in
pnpm-workspace.yaml for pnpm 11+, and remove the top-level overrides entry.
- Around line 100-101: The Vite override is currently placed in package.json,
but pnpm will not apply this top-level override there on clean installs. Move
the vite-to-rolldown-vite@7.2.10 substitution into pnpm-workspace.yaml and
remove it from package.json so the dependency replacement is applied
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d07f11d-cf7e-45ca-bd7c-453418a1785c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e2ba0c and a2f0f31.

📒 Files selected for processing (1)
  • package.json

Comment thread package.json Outdated
Comment on lines +100 to +101
"overrides": {
"vite": "npm:rolldown-vite@7.2.10"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Determine pnpm version intent and current overrides placement
fd -t f 'package.json' --max-depth 2 --exec sh -c '
  echo "=== {} ==="
  jq "{packageManager, engines, topOverrides: .overrides, pnpmOverrides: .pnpm.overrides}" "{}"
'
echo "=== pnpm-workspace.yaml (v11 overrides destination) ==="
fd -t f 'pnpm-workspace.yaml' --exec cat {}
echo "=== lockfileVersion + overrides block ==="
fd -t f 'pnpm-lock.yaml' --exec sed -n '1,25p' {}

Repository: ayoub3bidi/bayan-flow

Length of output: 1074


🌐 Web query:

pnpm overrides package.json top-level overrides pnpm.overrides documentation

💡 Result:

As of pnpm version 11, the pnpm.overrides configuration is no longer supported within the package.json file [1][2][3]. Any overrides defined there will be silently ignored [1][2]. To use overrides in pnpm v11 and later, you must define them in a pnpm-workspace.yaml file located at the root of your project [4][5][2]. The overrides field allows you to force specific versions of dependencies, including transitive dependencies, which is useful for security patches or compatibility fixes [4][6][7]. Configuration in pnpm-workspace.yaml uses the following syntax: overrides: "foo": "^1.0.0" "bar@^2.1.0": "3.0.0" "qar@1>zoo": "2" Key points for migration and usage: - Location: The overrides field must be at the root of the project in pnpm-workspace.yaml [4][5]. - Legacy Support: Versions of pnpm prior to 11 supported the pnpm.overrides field in package.json, but this has been deprecated and removed in favor of the workspace configuration [8][1][3]. - Granularity: You can override a dependency globally or specify that an override should only apply when a dependency is used by a specific parent package using the > syntax (e.g., parent>child) [4][6]. - Referencing: You can reference a direct dependency's spec by using the $ prefix (e.g., foo: $foo) [4][5]. - Removal: Use the - value to remove a dependency entirely (e.g., foo: -) [4][6]. If you are upgrading from an older version of pnpm, you should move your overrides from package.json to pnpm-workspace.yaml, then delete your node_modules and lockfile (pnpm-lock.yaml) to ensure a clean re-installation [2].

Citations:


Move the vite override into pnpm’s config.

Top-level overrides in package.json is not the pnpm location, so this vite -> npm:rolldown-vite@7.2.10 substitution can stop applying. Keep it under pnpm.overrides for pnpm <11, or in pnpm-workspace.yaml for pnpm 11+.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 100 - 101, Move the vite substitution from the
top-level overrides block into pnpm’s override configuration so it continues to
apply. Update the package.json pnpm.overrides section for pnpm <11, or place the
mapping in pnpm-workspace.yaml for pnpm 11+, and remove the top-level overrides
entry.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect full overrides-related structure and pnpm version pinning
fd -t f 'package.json' --max-depth 2 --exec sh -c '
  echo "=== {} ==="
  jq "{overrides, pnpm, packageManager, devVite: .devDependencies.vite, depVite: .dependencies.vite}" "{}"
'
echo "=== pnpm-lock overrides block ==="
fd -t f 'pnpm-lock.yaml' --exec sed -n "1,20p" {}

Repository: ayoub3bidi/bayan-flow

Length of output: 811


🌐 Web query:

Does pnpm support the top-level overrides field in package.json or only pnpm.overrides

💡 Result:

In modern versions of pnpm (specifically starting from v11), configuration settings, including overrides, are no longer supported in the package.json file [1][2]. The pnpm field in package.json is ignored, and pnpm does not support the top-level overrides field used by npm [1][2]. All configuration for overrides must now be defined in the workspace manifest file, pnpm-workspace.yaml, at the root of the project [3][4][1]. Key points regarding the current configuration model: - Location: The canonical location for overrides is now pnpm-workspace.yaml [4][1][2]. - Compatibility: pnpm does not use the standard npm top-level overrides field in package.json [1][5]. It maintains its own specific syntax and functionality (such as the ability to remove dependencies using - or scope overrides via the > selector) within the overrides block of pnpm-workspace.yaml [3][4][6]. - Migration: If you are upgrading to pnpm v11 or later, you must move any previous pnpm.overrides settings from your package.json into pnpm-workspace.yaml, as they will be ignored in the former location [2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== package.json manifest fields around overrides ==="
sed -n '85,110p' package.json | cat -n

echo "=== workspace / pnpm config files ==="
fd -a 'pnpm-workspace.yaml' .
fd -a '.npmrc' .
fd -a 'package.json' . | head -n 20

Repository: ayoub3bidi/bayan-flow

Length of output: 937


🌐 Web query:

pnpm package.json top-level overrides support official docs

💡 Result:

As of pnpm version 11, pnpm no longer supports defining overrides within the package.json file [1]. Settings that were previously defined in the pnpm field of package.json, including overrides, must now be defined in the pnpm-workspace.yaml file [1]. In versions of pnpm prior to v11, overrides were typically configured under the pnpm.overrides key within package.json [2]. However, upgrading to pnpm v11 or later will cause any overrides defined in the legacy package.json location to be ignored, often without an explicit error or warning [3][4][5]. To correctly implement overrides in modern pnpm, you must move the configuration to the root of your project in a pnpm-workspace.yaml file [6][3]: overrides: package-name: "version-or-range" This configuration ensures that pnpm properly applies the specified version overrides across your project's dependency graph [6].

Citations:


🌐 Web query:

site:pnpm.io package_json overrides pnpm package.json top-level overrides

💡 Result:

In modern versions of pnpm, the overrides feature is not configured directly in the top-level package.json file [1][2]. Instead, it must be defined in the pnpm-workspace.yaml file located at the root of your project [1][3]. Key points regarding pnpm overrides: - Location: The overrides field is strictly enforced at the root of the project within the pnpm-workspace.yaml file [1][3]. - Functionality: It allows you to force a specific version of a dependency throughout your dependency graph, replace a dependency with a fork, backport fixes, or remove an unnecessary dependency [1][3]. - Usage: You define overrides by mapping a package selector to a version specifier. You can also target specific dependencies of a parent package using the > syntax (e.g., pkg@version>dependency: new-version) [1][2]. - Removal: To remove a dependency entirely, you can set the override value to "-" (e.g., "foo@1.0.0>bar": "-") [1][2]. - Legacy/Alternative Methods: - While older versions of pnpm may have allowed certain configurations within the pnpm field of package.json, pnpm (since v11) no longer reads settings from that field [4]. - For advanced, dynamic manipulation of manifests during installation, the.pnpmfile.mjs (readPackage hook) can be used, though this is distinct from the declarative overrides feature [5]. - For permanent changes to a dependency's source code or its manifest file, pnpm patch is the recommended approach rather than attempting to override dependencies via patching [6].

Citations:


Move this override out of package.json. pnpm doesn’t read top-level overrides here, so the viterolldown-vite@7.2.10 substitution won’t apply on clean installs. Put it in pnpm-workspace.yaml instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 100 - 101, The Vite override is currently placed
in package.json, but pnpm will not apply this top-level override there on clean
installs. Move the vite-to-rolldown-vite@7.2.10 substitution into
pnpm-workspace.yaml and remove it from package.json so the dependency
replacement is applied consistently.

@ayoub3bidi
ayoub3bidi force-pushed the feat/pr-preview-cleanup branch from a2f0f31 to a7e6935 Compare June 27, 2026 10:48
@ayoub3bidi
ayoub3bidi merged commit 3d008c0 into develop Jun 27, 2026
16 checks passed
@ayoub3bidi
ayoub3bidi deleted the feat/pr-preview-cleanup branch June 27, 2026 10:55
@ayoub3bidi ayoub3bidi mentioned this pull request Jul 16, 2026
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant