Skip to content

feat(ci): add isolated PR preview environments#24

Merged
tindotdev merged 3 commits intomainfrom
feat/pr-preview-environments
Jan 2, 2026
Merged

feat(ci): add isolated PR preview environments#24
tindotdev merged 3 commits intomainfrom
feat/pr-preview-environments

Conversation

@tindotdev
Copy link
Copy Markdown
Owner

Summary

Add automated PR preview deployments with fully isolated infrastructure to safely test changes before merging to production.

Changes

Infrastructure Setup

  • ✅ Preview D1 database: append-db-preview
  • ✅ Preview R2 bucket: append-imports-preview
  • ✅ Preview Worker: append-api-preview
  • ✅ Google OAuth configured for preview auth
  • ✅ Stub AI provider (no OpenAI costs)

GitHub Actions

  • New: .github/workflows/preview.yml - PR preview deployments
    • Deploys API to preview environment
    • Deploys web with branch-specific URLs
    • Applies migrations to preview database
    • Posts deployment URLs as PR comment
  • Updated: .github/workflows/deploy.yml - Explicit production API URL

Web Configuration

  • Dynamic API URL: packages/web/src/lib/api-rpc.ts
    • Preview builds → Preview API
    • Production builds → Production API
    • Local dev → localhost
  • TypeScript: Added VITE_API_URL env var definitions

API Configuration

  • Preview environment: packages/api/wrangler.jsonc
    • Separate database and storage bindings
    • Stub AI provider configuration
    • Environment-specific configuration

Documentation

  • Updated: docs/runbook.md
    • Preview environment setup guide
    • Manual deployment commands
    • API URL configuration reference

How It Works

When a PR is opened:

  1. GitHub Actions workflow triggers
  2. API deploys to preview environment
  3. Web builds with preview API URL
  4. Web deploys to Cloudflare Pages (branch-specific URL)
  5. Both URLs posted as PR comment

Preview URLs

  • API: https://append-api-preview.tindejphachon.workers.dev
  • Web: https://<branch>.append-web.pages.dev

Test Plan

  • Preview infrastructure created (D1, R2, Worker)
  • Google OAuth secrets configured
  • Workflows validated (syntax check)
  • Test PR preview deployment (this PR!)
  • Verify preview web connects to preview API
  • Test Google OAuth login in preview
  • Verify isolation (no production data impact)

🤖 Generated with Claude Code

Add GitHub Actions workflow for PR preview deployments with isolated infrastructure:
- Preview API Worker (append-api-preview) with separate D1 database and R2 bucket
- Preview web deployment that connects to preview API instead of production
- Google OAuth configured for preview environments
- Automatic PR comments with deployment URLs

Infrastructure:
- Created preview D1 database (append-db-preview)
- Created preview R2 bucket (append-imports-preview)
- Configured preview environment in wrangler.jsonc with stub AI provider
- Set up Google OAuth secrets for preview worker

Web configuration:
- Add VITE_API_URL environment variable support for dynamic API URLs
- Preview builds now point to preview API
- Production builds explicitly set production API URL
- Add TypeScript definitions for VITE_API_URL

Workflows:
- New .github/workflows/preview.yml for PR preview deployments
- Updated .github/workflows/deploy.yml to explicitly set production API URL
- Both workflows post deployment URLs as PR comments

Documentation:
- Updated docs/runbook.md with preview environment setup and usage
- Documented preview secrets configuration
- Added manual preview deployment commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jan 2, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
append-api 0778fcb Commit Preview URL

Branch Preview URL
Jan 02 2026, 05:18 PM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jan 2, 2026

Deploying append-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0778fcb
Status: ✅  Deploy successful!
Preview URL: https://50d732a6.append-web.pages.dev
Branch Preview URL: https://feat-pr-preview-environments.append-web.pages.dev

View logs

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 2, 2026

🚀 Preview Deployments

API: https://append-api-preview.tindotdev.workers.dev
Web: ❌ Deployment failed

tindotdev and others added 2 commits January 3, 2026 00:11
When wrangler deploy fails, the error output is captured but never printed
due to bash's `set -e` flag causing immediate exit. This makes debugging
deployment failures impossible.

Changes:
- Use `set +e` before capturing wrangler output
- Store exit code in variable
- Always print deployment output
- Exit with proper code if deployment failed

This ensures error messages are visible in GitHub Actions logs, making it
easier to diagnose issues like missing secrets or configuration problems.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@tindotdev tindotdev merged commit 05c900a into main Jan 2, 2026
10 checks passed
@tindotdev tindotdev deleted the feat/pr-preview-environments branch January 2, 2026 17:28
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.

1 participant