Skip to main content

Quick Start

  1. Create a project in ScanU dashboard.
  2. Open Settings → API Keys and create a token for that project. It has the scans:write and scans:read permissions the workflow needs: one starts the scan, the other reads its result.
  3. Add the GitHub repository secret SCANU_TOKEN.
  4. Create .github/workflows/visual-regression.yml with the workflow below and replace YOUR_PROJECT_ID.
  5. Open a PR: the job starts a scan, waits up to 20 minutes for it to finish, and fails if ScanU rejects the request or the scan fails, is cancelled, finishes partially or finds a visual difference. The job log links to the report in ScanU.
yaml
name: Visual checks
on:
  pull_request:

jobs:
  visual-regression:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      contents: read
    steps:
      - name: Run a ScanU scan and wait for the result
        env:
          SCANU_TOKEN: ${{ secrets.SCANU_TOKEN }}
        run: |
          set -euo pipefail
          start=$(curl --fail-with-body -sS -X POST https://scanyou.eu/api/v1/scan \
            -H "Authorization: Bearer $SCANU_TOKEN" \
            -H "Content-Type: application/json" \
            -d '{"project_id":"YOUR_PROJECT_ID","urls":["https://staging.example.com"],"browsers":["chromium"],"devices":["desktop-fhd"]}') \
            || { echo "::error::ScanU did not start the scan: $start"; exit 1; }
          scan_id=$(jq -er '.scanId' <<<"$start")
          echo "Started ScanU scan $scan_id"
          # Poll every 15 seconds, for up to 20 minutes.
          for attempt in $(seq 80); do
            scan=$(curl --fail-with-body -sS --retry 3 "https://scanyou.eu/api/v1/scan/$scan_id" \
              -H "Authorization: Bearer $SCANU_TOKEN") \
              || { echo "::error::Reading the scan status failed: $scan"; exit 1; }
            status=$(jq -er '.status' <<<"$scan")
            echo "Scan status: $status"
            case "$status" in
              completed|completed_partial|failed|cancelled) break ;;
            esac
            if [ "$attempt" -eq 80 ]; then
              echo "::error::ScanU scan $scan_id did not finish within 20 minutes (last status: $status)"
              exit 1
            fi
            sleep 15
          done
          echo "Report: $(jq -r '.reportUrl' <<<"$scan")"
          if [ "$status" != "completed" ]; then
            echo "::error::ScanU scan ended as $status"
            exit 1
          fi
          changed=$(jq -r '.summary.changed' <<<"$scan")
          if [ "$changed" != "0" ]; then
            echo "::error::$changed visual difference(s) found"
            exit 1
          fi
          echo "No visual differences."

The first scan of a project becomes its baseline; later scans are compared against it. Approve intentional changes as the new baseline in ScanU.

The result is the job's pass or fail status and the report link in its log; this workflow does not post PR comments. A dedicated ScanU GitHub Action with PR comments is planned but not published yet; see GitHub Action (planned).

Run a test integration checklist

  • âś… Workflow appears in GitHub Actions tab.
  • âś… The job log prints the scan id, its status while it runs, and a report link.
  • âś… After the first scan has set the baseline, an intentional UI change makes the job fail with a visual difference.