Document setting Docker image version dynamically (JS)#37637
Document setting Docker image version dynamically (JS)#37637karlhorky wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Signed-off-by: Karl Horky <karl.horky@gmail.com>
| - name: resolve-playwright-version | ||
| id: resolve-playwright-version | ||
| run: | | ||
| version="$(yq -r '.devDependencies["@playwright/test"] // ""' package.json)" |
There was a problem hiding this comment.
I think we should read it from the lockfile instead - because ^1.30 could also end up in v1.55.0 - wdyt?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Retrieve the version using
npm list,yarn list,pnpm list, etc - Retrieve the version from
node_modules/@playwright/test/package.json(downside: this wouldn't work for package managers which don't usenode_modules)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Yeah, that's the situation that I described above:
But exact versions are pretty uncommon in
package.jsonfiles, so maybe worth doing something about it.
So probably worth it to either:
- Write some commands / a small script to read the version from all common lockfile formats
- Install
@playwright/testusing package manager + retrieve version using package manager commands likenpm list
@mxschmitt what do you think?
There was a problem hiding this comment.
For this item:
It looks like we may be able to use lockparse from @43081j, ("tiny zero-dependency lockfile parser for npm, Yarn, pnpm, and Bun"):
import { parse } from 'lockparse';
import { readFile } from 'node:fs/promises';
const lockfileContent = await readFile('./pnpm-lock.yaml', 'utf-8');
const packageJson = JSON.parse(await readFile('./package.json', 'utf-8'));
const lockfile = await parse(lockfileContent, 'pnpm', packageJson);
console.log(lockfile);Output:
{
type: 'pnpm',
packages: [
{ /* ... */ },
// ...
],
root: {
name: 'root',
version: '',
dependencies: [
// ...
],
devDependencies: [
{
name: '@playwright/test',
version: '1.56.1',
dependencies: [
{
name: 'playwright',
version: '1.56.1',
dependencies: [Array],
devDependencies: [],
optionalDependencies: [Array],
peerDependencies: []
}
],
devDependencies: [],
optionalDependencies: [],
peerDependencies: []
},
// ...
],
optionalDependencies: [],
peerDependencies: []
}
}Or something with higher usage numbers (118k downloads / week as of writing):
|
What are you trying to solve? Could you file an issue instead? |
|
@pavelfeldman ah sorry, forgot to copy the problem description to the PR, I've added it to the top of the PR description now Main idea is: the version in the workflow yaml files gets easily forgotten and outdated as Playwright versions in Keeping |
|
@pavelfeldman @mxschmitt I opened a new PR (including companion issue) - found what seems to be a pretty elegant solution: |
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.
The container image version can be kept up to date with the Playwright version in
package.jsonwith configuring a previous GitHub Actions job, as documented in the following resources:Alternatives Considered