Skip to content

Commit e871c34

Browse files
mydeaclaude
andcommitted
fix(ci): Install Node/Yarn in Playwright image from package.json versions
Read node and yarn versions from the root package.json volta config and pass them as build args to the Dockerfile. This ensures the Docker image always has Node and Yarn installed at the same versions the repo pins. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7ec2329 commit e871c34

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

.github/actions/ensure-playwright-image/action.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ outputs:
1414
runs:
1515
using: 'composite'
1616
steps:
17-
- name: Get Playwright version
18-
id: playwright
17+
- name: Get versions
18+
id: versions
1919
run: |
20-
VERSION=$(node -p "
20+
PLAYWRIGHT_VERSION=$(node -p "
2121
const pkg = require('./dev-packages/browser-integration-tests/package.json');
2222
const v = (pkg.dependencies || {})['@playwright/test'] || (pkg.devDependencies || {})['@playwright/test'];
2323
v.replace(/[~^]/, '')
2424
")
25-
echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
ROOT_PKG=$(node -p "JSON.stringify(require('./package.json').volta)")
26+
NODE_VERSION=$(echo "$ROOT_PKG" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).node")
27+
YARN_VERSION=$(echo "$ROOT_PKG" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).yarn")
28+
echo "playwright=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT
29+
echo "node=$NODE_VERSION" >> $GITHUB_OUTPUT
30+
echo "yarn=$YARN_VERSION" >> $GITHUB_OUTPUT
2631
shell: bash
2732

2833
- name: Verify @playwright/test version consistency
@@ -69,7 +74,7 @@ runs:
6974
shell: bash
7075
run: |
7176
DOCKERFILE_HASH=$(sha256sum .github/docker/playwright.Dockerfile | cut -c1-8)
72-
TAG="v${{ steps.playwright.outputs.version }}-${DOCKERFILE_HASH}"
77+
TAG="v${{ steps.versions.outputs.playwright }}-${DOCKERFILE_HASH}"
7378
echo "ref=ghcr.io/${{ github.repository }}/playwright:${TAG}" >> $GITHUB_OUTPUT
7479
7580
- name: Check if image already exists
@@ -101,6 +106,8 @@ runs:
101106
file: .github/docker/playwright.Dockerfile
102107
push: true
103108
build-args: |
104-
PLAYWRIGHT_VERSION=${{ steps.playwright.outputs.version }}
109+
PLAYWRIGHT_VERSION=${{ steps.versions.outputs.playwright }}
110+
NODE_VERSION=${{ steps.versions.outputs.node }}
111+
YARN_VERSION=${{ steps.versions.outputs.yarn }}
105112
tags: |
106113
${{ steps.image.outputs.ref }}

.github/docker/playwright.Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
FROM ghcr.io/actions/actions-runner:2.333.1
44

55
ARG PLAYWRIGHT_VERSION
6+
ARG NODE_VERSION
7+
ARG YARN_VERSION
68

79
# Prevent interactive prompts during package installation
810
ENV DEBIAN_FRONTEND=noninteractive
911

10-
# Install a temporary Node.js to bootstrap Playwright browser installation.
11-
# At runtime, actions/setup-node handles Node/Yarn from the workflow steps.
12-
RUN sudo curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - && \
12+
# Install Node.js and Yarn at the versions pinned in the repo's package.json.
13+
RUN sudo curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION%%.*}.x | sudo bash - && \
1314
sudo apt-get install -y --no-install-recommends nodejs && \
14-
sudo rm -rf /var/lib/apt/lists/*
15+
sudo rm -rf /var/lib/apt/lists/* && \
16+
sudo npm install -g yarn@${YARN_VERSION}
1517

1618
# Install Playwright browsers and their OS-level dependencies.
1719
# `--with-deps` installs required system libraries (libglib, libatk, libnss, etc.).

0 commit comments

Comments
 (0)