Reproduction of reading the Playwright version in package.json
and using it to set a dynamic version of the Playwright Docker container image in GitHub Actions:
- Playwright version set in
package.json
(@playwright/test
version indevDependencies
) - GitHub Actions workflow
.github/workflows/ci-container.yml
which reads this version and runs tests in a container with two jobs:resolve-playwright-version
: Read exact version of@playwright/test
frompackage.json
and set it as output for theci
jobci
: Uses the resolved Playwright version in thejobs.<job_id>.container.image
expression to run tests in a container using an image version matching the Playwright version
If you don't use an exact version of @playwright/test
in package.json
, then try either of these approaches:
- Retrieving the version from your package manager's lockfile (
package-lock.json
,yarn.lock
,pnpm-lock.yaml
,bun.lock
, etc.) - Installing all packages and retrieving the version from
node_modules/@playwright/test/package.json
Playwright docs mention two ways of installing Playwright browsers in CI:
Installing Playwright browsers with playwright install --with-deps
can lead to long installation times (can be multiple minutes to install dependencies):
- Install dependencies: 2m24s
- Total: 2m42s
Running Playwright via container (using the official Microsoft Docker image) is faster:
- Initialize Docker container: 25s
- Total: 50s
However, the Docker container approach hardcodes the Playwright version in a new place in the codebase - the GitHub Actions workflow files - requiring effort or automation to keep the Playwright versions in sync in both package.json
and the GitHub Actions workflow files. There is a high chance of these versions getting out of sync as Playwright is upgraded.
This reproduction treats the version in package.json
as the single source of truth and uses it to dynamically set the Docker image version in the GitHub Actions workflow.