Skip to content

Add preview deployments for pull requests#30

Merged
SomeHats merged 1 commit intomainfrom
claude/preview-deploys-prs-jQcLH
Mar 1, 2026
Merged

Add preview deployments for pull requests#30
SomeHats merged 1 commit intomainfrom
claude/preview-deploys-prs-jQcLH

Conversation

@SomeHats
Copy link
Owner

@SomeHats SomeHats commented Mar 1, 2026

Summary

This PR adds preview deployment functionality for pull requests using Cloudflare Workers, while maintaining the existing production deployment pipeline for the main branch.

Key Changes

  • Pull request trigger: Added pull_request event trigger to the build workflow for opened, synchronize, and reopened events
  • Dynamic base path: Modified VITE_BASE environment variable to use / for PR builds and /toys/ for production builds
  • Improved concurrency: Updated concurrency group to use PR number for pull requests and git ref for pushes, allowing parallel builds for different PRs
  • Artifact naming: Renamed artifact from github-pages to build-output for clarity
  • Production deployment guard: Added if: github.event_name == 'push' condition to the deploy job (renamed to deploy-pages) to ensure it only runs on main branch pushes
  • New preview deployment job: Added deploy-preview job that:
    • Runs only on pull requests
    • Deploys built artifacts to Cloudflare Workers with PR-specific naming (toys-pr-{PR_NUMBER})
    • Comments on the PR with the preview URL
    • Updates existing comments if the preview is redeployed
  • Preview cleanup workflow: Added new preview-cleanup.yml workflow that automatically deletes preview workers when PRs are closed
  • Wrangler configuration: Added wrangler.toml configuration file for Cloudflare Workers deployment

Implementation Details

  • Preview URLs are generated from either the Wrangler deployment output or constructed from the Cloudflare account ID
  • PR comments include a marker (<!-- preview-deploy -->) to enable idempotent updates on subsequent deployments
  • The preview deployment requires CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets to be configured

https://claude.ai/code/session_015vs1SrQi7gY45GQJBn23w7

Extend build.yml to also trigger on pull_request events, deploying
preview builds to Cloudflare Workers (static assets). Each PR gets its
own worker (toys-pr-{number}) with a bot comment linking to the preview
URL. A separate cleanup workflow deletes the worker when the PR closes.

- build.yml: add pull_request trigger, conditional VITE_BASE ("/" for
  PRs, "/toys/" for main), deploy-preview job with wrangler + PR comment
- preview-cleanup.yml: delete worker on PR close
- wrangler.toml: minimal assets-only config for Cloudflare Workers

https://claude.ai/code/session_015vs1SrQi7gY45GQJBn23w7
@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Preview deploy is ready!

https://toys-pr-30.somehats.workers.dev

Built from 0718c27

@SomeHats SomeHats merged commit bcdaaf4 into main Mar 1, 2026
3 checks passed
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