GitHub Actions

Run Bug0 tests automatically on pull requests and deployments using GitHub Actions.

Prerequisites

Before setting up GitHub Actions:

  1. Create a Bug0 project with tests
  2. Generate an API key (see API Keys)
  3. Add the secret to your GitHub repository

Adding the Secret

  1. Go to your GitHub repository
  2. Navigate to SettingsSecrets and variablesActions
  3. Click New repository secret
  4. Name: BUG0_API_KEY
  5. Value: Your Bug0 API key
  6. Click Add secret

Also add your project ID:

Basic Workflow

Create .github/workflows/bug0-tests.yml:

name: Bug0 Tests

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Bug0 Tests
        run: |
          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d '{
              "projectId": "${{ secrets.BUG0_PROJECT_ID }}",
              "gitCommitSha": "${{ github.event.pull_request.head.sha }}",
              "gitBranch": "${{ github.head_ref }}",
              "prNumber": "${{ github.event.pull_request.number }}"
            }'

With Vercel Preview URLs

If you use Vercel, wait for the preview deployment:

name: Bug0 Tests

on:
  deployment_status

jobs:
  test:
    runs-on: ubuntu-latest
    if: github.event.deployment_status.state == 'success'
    steps:
      - name: Trigger Bug0 Tests
        run: |
          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d '{
              "projectId": "${{ secrets.BUG0_PROJECT_ID }}",
              "url": "${{ github.event.deployment_status.target_url }}",
              "gitCommitSha": "${{ github.event.deployment.sha }}",
              "gitBranch": "${{ github.event.deployment.ref }}",
              "prNumber": "${{ github.event.deployment.payload.pr_number }}"
            }'

With Netlify Preview URLs

For Netlify deployments:

name: Bug0 Tests

on:
  deployment_status

jobs:
  test:
    runs-on: ubuntu-latest
    if: github.event.deployment_status.state == 'success' && contains(github.event.deployment_status.target_url, 'netlify')
    steps:
      - name: Trigger Bug0 Tests
        run: |
          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d '{
              "projectId": "${{ secrets.BUG0_PROJECT_ID }}",
              "url": "${{ github.event.deployment_status.target_url }}"
            }'

Manual Trigger

Add manual workflow dispatch:

name: Bug0 Tests

on:
  workflow_dispatch:
    inputs:
      url:
        description: 'URL to test'
        required: false
        default: ''

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Bug0 Tests
        run: |
          URL="${{ github.event.inputs.url }}"
          if [ -z "$URL" ]; then
            URL_PARAM=""
          else
            URL_PARAM='"url": "'"$URL"'",'
          fi

          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d '{
              '"$URL_PARAM"'
              "projectId": "${{ secrets.BUG0_PROJECT_ID }}"
            }'

Full Example with All Features

name: Bug0 E2E Tests

on:
  pull_request:
    types: [opened, synchronize, reopened]
  deployment_status:
  workflow_dispatch:
    inputs:
      url:
        description: 'Custom URL to test'
        required: false

jobs:
  test-on-preview:
    runs-on: ubuntu-latest
    if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
    steps:
      - name: Run Bug0 Tests on Preview
        run: |
          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d '{
              "projectId": "${{ secrets.BUG0_PROJECT_ID }}",
              "url": "${{ github.event.deployment_status.target_url }}",
              "gitCommitSha": "${{ github.event.deployment.sha }}",
              "gitBranch": "${{ github.event.deployment.ref }}"
            }'

  test-manual:
    runs-on: ubuntu-latest
    if: github.event_name == 'workflow_dispatch'
    steps:
      - name: Run Bug0 Tests Manually
        run: |
          URL="${{ github.event.inputs.url }}"
          BODY='{"projectId": "${{ secrets.BUG0_PROJECT_ID }}"'
          if [ -n "$URL" ]; then
            BODY="$BODY"', "url": "'"$URL"'"'
          fi
          BODY="$BODY}"

          curl -X POST https://app.bug0.com/api/run-tests \
            -H "x-api-key: ${{ secrets.BUG0_API_KEY }}" \
            -H "Content-Type: application/json" \
            -d "$BODY"

GitHub Integration Features

When you include git information in the request:

Commit Status

GitHub shows test status on commits:

PR Comments

Bug0 comments on PRs with:

For PR comments and commit status, connect your GitHub repository in Bug0's project integrations settings.

Troubleshooting

Tests Not Triggering

Wrong URL Being Tested

No PR Comments