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;
--pollwaits for completion.
Related guides
How to Measure Core Web Vitals in GitHub ActionsCapture lab Core Web Vitals (LCP, CLS, TBT) in GitHub Actions by running Lighthouse against a built site and…
How to Enforce a Lighthouse Performance Budget in GitHub ActionsFail a GitHub Actions run when a page blows its performance budget by feeding a budget.json to Lighthouse CI…