Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/src/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,49 @@ jobs:
run: dotnet test
```

#### Via Containers (dynamic)
* langs: js

Setting the version of the container dynamically can be performed by retrieving the version of Playwright in a previous job. For example, if you install an exact version of Playwright, then it can be retrieved from `package.json`:

```yml js title=".github/workflows/playwright.yml"
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
resolve-playwright-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps['resolve-playwright-version'].outputs.version }}
steps:
- uses: actions/checkout@v5
- name: resolve-playwright-version
id: resolve-playwright-version
run: |
version="$(yq -r '.devDependencies["@playwright/test"] // ""' package.json)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should read it from the lockfile instead - because ^1.30 could also end up in v1.55.0 - wdyt?

Copy link
Contributor Author

@karlhorky karlhorky Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I considered that: downside would be complexity - since there are a lot of people not on npm, should be provided for every lockfile format (npm-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock).

I was also looking into possible CLI commands (eg. npm, yarn, pnpm, bun commands) or trusted npm packages which would make this simple, but I didn't see something simple and unified in half an hour of research.

That's why I ended up with the extra text in the paragraph:

if you install an exact version of Playwright, then it can be retrieved from package.json

But exact versions are pretty uncommon in package.json files, so maybe worth doing something about it.


If it's worth it, I could try writing some commands / a small script in this direction.

Copy link
Contributor Author

@karlhorky karlhorky Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another (more expensive) alternative would be to install Playwright from the package.json + lockfile using the detected package manager (minimal command branching here) and either:

  1. Retrieve the version using npm list, yarn list, pnpm list, etc
  2. Retrieve the version from node_modules/@playwright/test/package.json (downside: this wouldn't work for package managers which don't use node_modules)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this doesn't work, because I have a ^ in my package.json

  Warning: Docker pull failed with exit code 1, back off 5.126 seconds before retry.
  /usr/bin/docker pull mcr.microsoft.com/playwright:v^1.56.0-noble
  invalid reference format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's the situation that I described above:

But exact versions are pretty uncommon in package.json files, so maybe worth doing something about it.

So probably worth it to either:

  1. Write some commands / a small script to read the version from all common lockfile formats
  2. Install @playwright/test using package manager + retrieve version using package manager commands like npm list

@mxschmitt what do you think?

test -n "$version" || { echo "No @playwright/test version found in package.json"; exit 1; }
echo "version=$version" >> "$GITHUB_OUTPUT"
playwright:
name: 'Playwright Tests'
runs-on: ubuntu-latest
needs: resolve-playwright-version
container:
image: mcr.microsoft.com/playwright:v${{ needs['resolve-playwright-version'].outputs.version }}-noble
options: --user 1001
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Run your tests
run: npx playwright test
```

#### On deployment

This will start the tests after a [GitHub Deployment](https://developer.github.com/v3/repos/deployments/) went into the `success` state.
Expand Down