CI/CD

GitHub Actions

Run Frontguard visual regression tests in GitHub Actions with the official action.

GitHub Actions

Frontguard provides an official GitHub Action for visual regression testing in your CI pipeline.

Quick Setup

.github/workflows/visual-regression.yml
name: Visual Regression Tests
on:
  pull_request:
    branches: [main]

jobs:
  visual-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Deploy Preview
        # Your deployment step here — Vercel, Netlify, etc.
        # Frontguard auto-detects the preview URL

      - name: Run Frontguard
        uses: ravidsrk/frontguard@main
        with:
          url: ${{ env.PREVIEW_URL }}  # Or let it auto-detect
        env:
          FRONTGUARD_OPENAI_KEY: ${{ secrets.FRONTGUARD_OPENAI_KEY }}

Action Inputs

InputRequiredDefaultDescription
urlNoAuto-detectedBase URL to test
routesNoAuto-discoveredComma-separated routes
viewportsNo375,768,1440Comma-separated viewport widths
browsersNochromiumComma-separated browsers
thresholdNo0.1Pixel diff threshold percentage
configNoAuto-detectedPath to frontguard.config.ts
ai-providerNoAI provider: openai or anthropic
ai-modelNoAI model name
update-baselinesNofalseAccept current as new baselines
github-tokenNogithub.tokenToken for PR comments

Action Outputs

OutputDescription
resultFull JSON result of the test run
regressionsNumber of regressions found
statuspass, fail, or error

Complete Example

Here's a full workflow with Vercel preview deployments:

.github/workflows/visual-regression.yml
name: Visual Regression Tests

on:
  pull_request:
    branches: [main]
  deployment_status:

jobs:
  visual-test:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' || github.event.deployment_status.state == 'success'
    steps:
      - uses: actions/checkout@v4

      - name: Run Frontguard
        id: frontguard
        uses: ravidsrk/frontguard@main
        with:
          viewports: '375,768,1440'
          browsers: 'chromium'
          threshold: '0.1'
          ai-provider: 'openai'
          ai-model: 'gpt-4o'
        env:
          FRONTGUARD_OPENAI_KEY: ${{ secrets.FRONTGUARD_OPENAI_KEY }}

      - name: Check Results
        if: always()
        run: |
          echo "Status: ${{ steps.frontguard.outputs.status }}"
          echo "Regressions: ${{ steps.frontguard.outputs.regressions }}"

What the Action Does

The action runs these steps automatically:

  1. Setup Node.js — Installs Node.js 20
  2. Install Frontguardnpm install -g frontguard@latest
  3. Install Browsersnpx playwright install --with-deps <browsers>
  4. Detect Preview URL — Checks environment variables from Vercel, Netlify, Cloudflare, Railway, Render
  5. Run Frontguard — Executes the full pipeline with your configuration
  6. Upload Report — Uploads the HTML report as a build artifact

Using with Preview Deployments

Vercel

- name: Wait for Vercel Preview
  uses: patrickedqvist/wait-for-vercel-preview@v1.3.2
  id: preview
  with:
    token: ${{ secrets.GITHUB_TOKEN }}
    max_timeout: 300

- name: Run Frontguard
  uses: ravidsrk/frontguard@main
  with:
    url: ${{ steps.preview.outputs.url }}

Netlify

Frontguard auto-detects DEPLOY_PRIME_URL set by Netlify's CI environment:

- name: Run Frontguard
  uses: ravidsrk/frontguard@main
  # URL auto-detected from DEPLOY_PRIME_URL

Updating Baselines in CI

Create a separate workflow or trigger for baseline updates:

.github/workflows/update-baselines.yml
name: Update Visual Baselines

on:
  workflow_dispatch:
  push:
    branches: [main]

jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Update Baselines
        uses: ravidsrk/frontguard@main
        with:
          url: 'https://your-production-url.com'
          update-baselines: 'true'

Secrets Configuration

Add these secrets to your repository settings (Settings → Secrets and variables → Actions):

SecretRequiredDescription
FRONTGUARD_OPENAI_KEYFor AI analysisOpenAI API key
FRONTGUARD_ANTHROPIC_KEYFor AI analysisAnthropic API key (alternative)

GITHUB_TOKEN is provided automatically by GitHub Actions. You don't need to create it as a secret.

Downloading Reports

The HTML report is uploaded as a build artifact on every run. Download it from the Actions tab:

  1. Go to your repository → Actions tab
  2. Click on the workflow run
  3. Under Artifacts, download frontguard-report
  4. Open index.html for an interactive visual diff viewer

On this page