Skip to content

feat: per-branch preview deployments with cleanup#17

Open
CelebrityPunks wants to merge 1 commit into
ubiquity:mainfrom
CelebrityPunks:feat/all-branches-preview
Open

feat: per-branch preview deployments with cleanup#17
CelebrityPunks wants to merge 1 commit into
ubiquity:mainfrom
CelebrityPunks:feat/all-branches-preview

Conversation

@CelebrityPunks
Copy link
Copy Markdown

Summary

Resolves #7

  • Adds preview_mode input to the reusable deploy workflow (branch default, shared for legacy). In branch mode, 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.
  • Branch names are sanitized for DNS/Deno Deploy compatibility: lowercased, special characters replaced with hyphens, truncated with a 4-char hash suffix when the project name exceeds the 26-character Deno Deploy limit.
  • Adds deno-deploy-cleanup.yml reusable workflow triggered on delete events. 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).
  • Fully backward compatible: existing repos can set preview_mode: shared to retain the legacy single-project p-<base>-ubq-fi behavior.

Test plan

  • Push to a non-default branch (e.g., feat/widget) with preview_mode: branch and verify the Deno Deploy project is created as feat-widget-<base>-ubq-fi
  • Push to the same repo's production branch and confirm production deploy is unchanged
  • Set preview_mode: shared and verify legacy p-<base>-ubq-fi behavior
  • Delete a branch and verify the cleanup workflow removes the corresponding Deno Deploy project
  • Test edge cases: long branch names (>20 chars), branch names with special characters (feat/my-feature_v2.0), branches with uppercase letters
  • Verify the cleanup workflow is a no-op when the project does not exist

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
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

This 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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main feature: per-branch preview deployments with automatic cleanup on branch deletion.
Description check ✅ Passed The description is well-structured, covering the new preview_mode input, branch sanitization logic, cleanup workflow, and backward compatibility. It relates directly to all changes in the PR.
Linked Issues check ✅ Passed All requirements from issue #7 are met: per-branch preview support with distinct router URLs, branch name sanitization, separate Deno Deploy projects per branch, branch deletion detection with cleanup, and edge case handling.
Out of Scope Changes check ✅ Passed All changes directly support the linked objective. Documentation updates (README, AGENTS) explain the new feature; workflows implement branch-mode and shared-mode previews; cleanup workflow handles deletion events as required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e44d22ad-9ad5-4434-8fd2-195e16e124f4

📥 Commits

Reviewing files that changed from the base of the PR and between 9c32848 and 879e170.

📒 Files selected for processing (4)
  • .github/workflows/deno-deploy-cleanup.yml
  • .github/workflows/deno-deploy-reusable.yml
  • AGENTS.md
  • README.md

cleanup:
name: Delete branch preview project
runs-on: ubuntu-22.04
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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: 5

The 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.

Suggested change
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
cleanup:
name: Delete branch preview project
runs-on: ubuntu-22.04
timeout-minutes: 5

Comment thread README.md
Comment on lines +84 to +107
### 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

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.

All Branches Supported for Previews

2 participants