Skip to content

vercel.deployment.success #56

vercel.deployment.success

vercel.deployment.success #56

# E2E Tests against Vercel Preview Deployments
#
# This workflow runs Playwright tests against Vercel preview deployments.
# It is triggered automatically by Vercel when a deployment to preview succeeds.
#
# How it works:
# 1. Vercel deploys your code to a preview URL
# 2. On success, Vercel sends a repository_dispatch event to GitHub
# 3. This workflow receives the event with the preview URL in the payload
# 4. Playwright tests run against the live Vercel preview deployment
#
# This provides confidence before merging to main (which triggers production deploy).
#
# Reference: https://vercel.com/guides/how-can-i-run-end-to-end-tests-after-my-vercel-preview-deployment
name: E2E Tests (Vercel Preview)
permissions:
contents: read
statuses: write
on:
# Triggered by Vercel when a deployment succeeds
repository_dispatch:
types:
- "vercel.deployment.success"
# Cancel in-progress runs when a newer deployment succeeds on the same branch.
# Groups by git.ref (branch name) from Vercel's payload, not URL (which is unique per deploy).
concurrency:
group: ${{ github.workflow }}-${{ github.event.client_payload.git.ref }}
cancel-in-progress: true
# Note: If you have Deployment Protection enabled on Vercel,
# you'll need to configure Protection Bypass for Automation.
# See: https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation
jobs:
e2e-preview:
name: Run E2E Tests on Preview
# Only run for repository_dispatch events (safety check)
if: github.event_name == 'repository_dispatch'
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
# Step: Checkout the exact commit that was deployed
# Uses the SHA from Vercel's payload to ensure we test the right code
- uses: actions/checkout@v6
with:
ref: ${{ github.event.client_payload.git.sha }}
# Step: Setup Node.js
- uses: actions/setup-node@v6
with:
node-version: "lts/*"
cache: "npm"
# Step: Install dependencies
- name: Install dependencies
run: npm ci
# Step: Install Playwright Browsers
- name: Install Playwright Browsers
run: npx playwright install chromium webkit --with-deps
# Step: Run E2E tests against Vercel preview URL
# No build needed — we're testing the deployed preview, not localhost
- name: Run Playwright tests
run: npx playwright test
env:
# The Vercel preview URL from the deployment event payload
# This is passed to playwright.config.ts which uses it as baseURL
BASE_URL: ${{ github.event.client_payload.url }}
# Bypass secret for Vercel Deployment Protection (required when protection is enabled)
# This allows Playwright to access protected preview deployments
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
# Clerk auth testing variables
CLERK_PUBLISHABLE_KEY: ${{ secrets.CLERK_PUBLISHABLE_KEY }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
E2E_TEST_EMAIL: ${{ secrets.E2E_TEST_EMAIL }}
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
E2E_TEST_OTP: ${{ secrets.E2E_TEST_OTP }}
# Step: Upload test report
- uses: actions/upload-artifact@v6
if: ${{ !cancelled() }}
with:
name: playwright-report-vercel-preview
path: .playwright/playwright-report/
retention-days: 30
# Step: Report status back to the PR commit
# Since repository_dispatch runs on main, we must explicitly report status
# to the original commit SHA so the PR's required check is satisfied
- name: Report status to PR
if: always()
uses: actions/github-script@v8
with:
script: |
const state = '${{ job.status }}' === 'cancelled' ? 'error' : '${{ job.status }}';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ github.event.client_payload.git.sha }}',
state: state,
context: 'Run E2E Tests on Preview',
description: 'E2E tests against Vercel preview',
target_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
});