Skip to content
Latchkey

How to Run a WebPageTest in GitHub Actions

The WebPageTest API runs a measured page test on real devices and networks and returns metrics you can assert on in CI.

Install the webpagetest CLI, supply an API key as a secret, and run a test against a public URL. Parse the JSON for Speed Index, TTFB, or LCP and fail when over budget.

Steps

  • Store a WebPageTest API key as a secret.
  • Run webpagetest test <url> --poll --key $WPT_API_KEY.
  • Read metrics from the JSON and compare to a budget.

Workflow

.github/workflows/ci.yml
jobs:
  wpt:
    runs-on: ubuntu-latest
    env:
      WPT_API_KEY: ${{ secrets.WPT_API_KEY }}
    steps:
      - run: npm install -g webpagetest
      - run: |
          webpagetest test https://example.com \
            --key "$WPT_API_KEY" --location "Dulles:Chrome" --runs 3 \
            --poll 5 --timeout 240 > result.json
      - run: |
          SI=$(node -e "console.log(require('./result.json').data.median.firstView.SpeedIndex)")
          echo "SpeedIndex=$SI budget=4000"
          awk -v s="$SI" 'BEGIN { exit (s > 4000) }'

Gotchas

  • The public API enforces a daily test quota; a private instance avoids the cap.
  • A test must finish before metrics exist; --poll waits for completion.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →