feat: per-branch preview deployments with cleanup#17
Conversation
Support any branch as a preview prefix instead of collapsing all into a single preview- project. Each non-default branch now gets its own Deno Deploy project (<sanitized-branch>-<base>-ubq-fi) with a corresponding router URL (<branch>-<sub>.ubq.fi). - Add preview_mode input (branch|shared) to reusable workflow - Sanitize branch names for DNS: lowercase, replace special chars with hyphens, truncate with hash suffix for 26-char Deno Deploy limit - Add deno-deploy-cleanup.yml reusable workflow for branch deletion events that deletes the corresponding Deno Deploy project - Cleanup is idempotent (no error if project already gone) - Backward compatible: set preview_mode: shared for legacy behavior Resolves ubiquity#7
📝 WalkthroughWalkthroughThis pull request adds per-branch Deno Deploy preview deployments alongside existing production and shared-preview options. Two new workflows are introduced: a reusable cleanup workflow that deletes preview projects when branches are deleted, and an updated main workflow supporting two preview modes (per-branch and shared). Branch names are sanitized into DNS-safe slugs with length constraints and optional hashing. Project naming conventions follow DNS requirements and include configurable sanitization rules. Supporting documentation is added explaining the naming strategy, branch deletion handling, and configuration options for reverting to legacy single-project preview behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e44d22ad-9ad5-4434-8fd2-195e16e124f4
📒 Files selected for processing (4)
.github/workflows/deno-deploy-cleanup.yml.github/workflows/deno-deploy-reusable.ymlAGENTS.mdREADME.md
| cleanup: | ||
| name: Delete branch preview project | ||
| runs-on: ubuntu-22.04 | ||
| if: github.event_name == 'delete' && github.event.ref_type == 'branch' |
There was a problem hiding this comment.
Condition will never be true in a reusable workflow context.
When invoked via workflow_call, github.event_name is 'workflow_call', not 'delete'. The delete event context exists in the caller, not here. This job will be skipped on every invocation.
Move this condition to the caller workflow (as shown in README.md line 96) and remove it here, or access the original event via github.event.action or pass it as an input.
Proposed fix
cleanup:
name: Delete branch preview project
runs-on: ubuntu-22.04
- if: github.event_name == 'delete' && github.event.ref_type == 'branch'
timeout-minutes: 5The caller already gates on github.event.ref_type == 'branch' (per README example), so removing this condition allows the job to run.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if: github.event_name == 'delete' && github.event.ref_type == 'branch' | |
| cleanup: | |
| name: Delete branch preview project | |
| runs-on: ubuntu-22.04 | |
| timeout-minutes: 5 |
| ### Branch cleanup | ||
|
|
||
| To automatically delete per-branch preview projects when branches are deleted, add a cleanup workflow to each consuming repository: | ||
|
|
||
| ```yaml | ||
| name: Deno Deploy Cleanup | ||
|
|
||
| on: | ||
| delete: | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| if: github.event.ref_type == 'branch' | ||
| permissions: | ||
| contents: read | ||
| uses: ubiquity/deno-deploy-workflow/.github/workflows/deno-deploy-cleanup.yml@main | ||
| with: | ||
| project: <subdomain>-ubq-fi | ||
| secrets: | ||
| DENO_DEPLOY_TOKEN: ${{ secrets.DENO_DEPLOY_TOKEN }} | ||
| ``` | ||
|
|
||
| The cleanup workflow is idempotent: it succeeds silently if the project does not exist or was already deleted. | ||
|
|
There was a problem hiding this comment.
Documentation is correct, but depends on the cleanup workflow fix.
The example properly places the ref_type == 'branch' check in the caller. However, this won't help unless the redundant (and broken) condition in deno-deploy-cleanup.yml line 21 is removed.
Summary
Resolves #7
preview_modeinput to the reusable deploy workflow (branchdefault,sharedfor legacy). Inbranchmode, each non-default branch gets its own Deno Deploy project (<sanitized-branch>-<base>-ubq-fi) with a unique router URL (<branch>-<sub>.ubq.fi), enabling simultaneous preview deployments across branches.deno-deploy-cleanup.ymlreusable workflow triggered ondeleteevents. When a branch is deleted, the corresponding per-branch preview project is removed via the Deno Deploy API. The cleanup is idempotent (no error if the project does not exist or was already deleted).preview_mode: sharedto retain the legacy single-projectp-<base>-ubq-fibehavior.Test plan
feat/widget) withpreview_mode: branchand verify the Deno Deploy project is created asfeat-widget-<base>-ubq-fipreview_mode: sharedand verify legacyp-<base>-ubq-fibehaviorfeat/my-feature_v2.0), branches with uppercase letters