A workflow skeleton for Playwright in GitHub Actions
A Playwright workflow is YAML in .github/workflows/ with triggers and jobs that run in parallel by default, each on its own runner. A job is made of steps. A typical skeleton is checkout, Node, npm ci, browsers, tests and a report upload with the !cancelled() condition so it is saved even after a failure. timeout-minutes and minimal permissions are added.
CI/CD · GitHub Actions
Tests are green locally and red in Actions, with no report. What is a workflow made of?
A QA Engineer adds the first Playwright workflow to a repository. The tests fail, and the report button is empty: the artifact upload step did not run, because it came after a red step. A small detail like this if condition can cost an hour until you know how Actions decides what to run. This lesson walks through the skeleton of a workflow and its usual traps.
How it works and why. A workflow is a YAML file in .github/workflows/. It consists of jobs, which run in parallel by default, each on its own runner (a clean virtual machine). A job is a sequence of steps on one machine with a shared file system. A step is either run: (a shell command) or uses: (a ready-made action). Data does not flow between jobs on its own: that takes artifacts, a cache or outputs.
Workflow structure
Triggers (on:): pull_request (a PR), push with a branch filter, schedule (cron) and workflow_dispatch (a manual run). Cron runs in UTC by default, such runs start only from the default branch and may be late at peak hours. Another zone is set with a timezone key holding an IANA name.
A step after failing tests
The default condition
A step has the success() condition: after a red test step it is skipped, and the report you need most is missing.
if: !cancelled()
The step runs after failing tests, but not after a run was cancelled by hand or by concurrency.
Example: a working skeleton. Everything needed for a first Playwright run:
name: e2e
on:
pull_request:
push:
branches: [main]
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
permissions:
contents: read
jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx playwright test
- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 14
What matters here. timeout-minutes protects against hangs (by default a job may run up to 360 minutes). permissions: contents: read limits the GITHUB_TOKEN to a minimum. npm ci installs dependencies strictly from the lock file. cache: npm caches the global npm cache. playwright install --with-deps installs a browser with system libraries. Playwright's CI config (workers, retries) is in the lesson “CI: sharding, Docker and fast reruns”.
A nightly run on Kyiv time:
on:
schedule:
# every day at 02:00 Kyiv time
- cron: '0 2 * * *'
timezone: 'Europe/Kyiv'
Limits and alternatives. Actions can be pinned by a tag (@v7) or by a full commit SHA: a SHA protects against a moved tag, a tag is easier to update. Action versions change, so check them on the releases page before use and update them along with dependencies. For constant runs on your own hardware there are self-hosted runners, but then the team keeps the environment clean. Sharding and matrix are in the next lesson: “Cache, matrix, concurrency and sharding”.
Typical mistakes.
- No
timeout-minutes: a hung test holds a runner for six hours. - A report upload without
!cancelled(): no report after a failure. - Token permissions wider than needed:
permissionsnot set. - Cron expected in local time while it runs in UTC.
- Expecting one job to see another job's files: artifacts are needed.
Check yourself
The tests failed, the npx playwright test step is red and the next upload-artifact is "skipped". Why, and how to fix it?
Answer
A step's default condition is success(): after a failed step the next ones are skipped. Add if: ${{ !cancelled() }} so the upload runs after failing tests.
Will a second job see files created by the first?
Answer
No: each job runs on its own runner. Data is passed through artifacts, a cache or outputs, and order is set with needs.