From 7167b03a7d924b09e90ac7efb6dcd222e5278a76 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 11:34:58 -0800 Subject: [PATCH 1/2] devops: build the driver from source at a pinned commit scripts/DRIVER_VERSION now holds a microsoft/playwright commit instead of a published playwright-core version. scripts/build_driver.sh (was download_driver.sh) clones microsoft/playwright into .upstream/, checks the commit out and builds the playwright-core package from it. The first pin is a1f35e1955976e84411f9c10358228a80b763ebe, the commit of v1.65.0, the driver version before this change. --- .azure-pipelines/publish-docker.yml | 5 +- .azure-pipelines/publish.yml | 7 +- .../skills/playwright-java-release/SKILL.md | 2 +- .claude/skills/playwright-roll/SKILL.md | 41 +++-- .github/workflows/test.yml | 24 ++- .github/workflows/test_cli.yml | 8 +- .github/workflows/test_docker.yml | 6 + .github/workflows/verify_api.yml | 8 +- .gitignore | 3 + AGENTS.md | 8 +- CONTRIBUTING.md | 14 +- ROLLING.md | 5 +- scripts/DRIVER_VERSION | 2 +- scripts/build_driver.sh | 165 ++++++++++++++++++ scripts/download_driver.sh | 107 ------------ scripts/generate_api.sh | 35 ++-- scripts/roll_driver.sh | 54 ++++-- scripts/roll_node.sh | 2 +- utils/docker/build.sh | 4 +- 19 files changed, 303 insertions(+), 197 deletions(-) create mode 100755 scripts/build_driver.sh delete mode 100755 scripts/download_driver.sh diff --git a/.azure-pipelines/publish-docker.yml b/.azure-pipelines/publish-docker.yml index 1eece8256..4b5a44fbe 100644 --- a/.azure-pipelines/publish-docker.yml +++ b/.azure-pipelines/publish-docker.yml @@ -69,8 +69,9 @@ extends: echo '{ "data-root": "/mnt/docker" }' | sudo tee /etc/docker/daemon.json sudo service docker start - # Used by scripts/download_driver.sh on the host. The Docker build context is - # utils/docker (see build.sh), so this file never reaches the images. + # scripts/build_driver.sh builds the driver from .upstream/ on the host with `npm ci`, + # which picks up the registry and the credentials from this .npmrc. The Docker build + # context is utils/docker (see build.sh), so this file never reaches the images. - task: Bash@3 displayName: "setup .npmrc" inputs: diff --git a/.azure-pipelines/publish.yml b/.azure-pipelines/publish.yml index c17cd96c3..a6c2255be 100644 --- a/.azure-pipelines/publish.yml +++ b/.azure-pipelines/publish.yml @@ -79,8 +79,11 @@ extends: inputs: workingFile: .npmrc - - bash: ./scripts/download_driver.sh - displayName: 'Download driver' + # Clones microsoft/playwright into .upstream/ at the commit in scripts/DRIVER_VERSION + # and builds the driver from it with `npm ci`, which picks up the registry and + # the credentials from the .npmrc above. + - bash: ./scripts/build_driver.sh + displayName: 'Build the driver' # Must run before MavenAuthenticate@0 so the credentials it injects into # ~/.m2/settings.xml are not overwritten by the copy. diff --git a/.claude/skills/playwright-java-release/SKILL.md b/.claude/skills/playwright-java-release/SKILL.md index d5a02d16c..1ded10c27 100644 --- a/.claude/skills/playwright-java-release/SKILL.md +++ b/.claude/skills/playwright-java-release/SKILL.md @@ -3,7 +3,7 @@ name: playwright-java-release description: Prepare a Playwright Java release after the rolling PR has merged — cut the release branch, mark the Maven version, add Java-specific changes to the release notes, draft the GitHub release, and tick the Java boxes in the internal checklist. --- -Use this skill once the `chore: roll driver to 1.X.0` PR has merged into `main` and the upstream JS `v1.X.0` is published. The rolling work itself is covered by the [[playwright-roll]] skill. +Use this skill once the `chore: roll driver to 1.X.0` PR has merged into `main` and the upstream JS `v1.X.0` is published. The driver is built from the `microsoft/playwright` commit in `scripts/DRIVER_VERSION`: for a release it must be the commit of the upstream tag `v1.X.0` (`scripts/roll_driver.sh v1.X.0`), so that the driver reports `1.X.0`. The rolling work itself is covered by the [[playwright-roll]] skill. Throughout this doc, replace `X` with the minor version (e.g. `60` for `1.60.0`) and `` with the fork owner (`gh api user --jq .login`). diff --git a/.claude/skills/playwright-roll/SKILL.md b/.claude/skills/playwright-roll/SKILL.md index 1efb5db90..5c5c86036 100644 --- a/.claude/skills/playwright-roll/SKILL.md +++ b/.claude/skills/playwright-roll/SKILL.md @@ -6,12 +6,14 @@ description: Roll Playwright Java to a new version Help the user roll to a new version of Playwright. ROLLING.md contains general instructions and scripts. -Start with running ./scripts/roll_driver.sh to update the version and generate the API to see the state of things. +The driver is built from source: `scripts/DRIVER_VERSION` holds one `microsoft/playwright` commit, and `.upstream/` (gitignored) is a clone of `microsoft/playwright` at that commit. Do not edit, commit or switch branches in it. + +Start with running `./scripts/roll_driver.sh ` to pin the new commit, build the driver from it and generate the API to see the state of things. `` is a branch (`main`, the default, or `release-1.X`), a tag (`v1.X.0`) or a commit of `microsoft/playwright`. Afterwards, walk through the upstream changes that affect the Java client and port the relevant ones. ## Determining what to port -List the upstream commits that touched a client-relevant path since the last release. The paths cover everything that can change the public Java surface or the wire protocol: +List the upstream commits that touched a client-relevant path since the previous pin. The paths cover everything that can change the public Java surface or the wire protocol: - `docs/src/api/` — the source of truth for `api.json`. Method/option additions, removals, and `langs:` filter changes flow from here. - `packages/playwright-core/src/client/` — the JS client implementation that the Java client mirrors. @@ -20,9 +22,9 @@ List the upstream commits that touched a client-relevant path since the last rel - `packages/protocol/spec/` — the wire protocol schema (one `*.yml` file per area). Method/event additions, parameter renames, and result-shape changes affect what the Java `*Impl` classes need to send/receive. ```bash -cd ~/playwright -PREV_TAG=$(git tag | grep -E '^v1\.[0-9]+\.[0-9]+$' | sort -V | tail -1) # e.g. v1.59.1 -git log "$PREV_TAG"..HEAD --oneline -- \ +old=$(git show HEAD:scripts/DRIVER_VERSION) +new=$(cat scripts/DRIVER_VERSION) +git -C .upstream log "$old..$new" --oneline -- \ 'docs/src/api/' \ 'packages/playwright-core/src/client/' \ 'packages/isomorphic/' \ @@ -31,7 +33,7 @@ git log "$PREV_TAG"..HEAD --oneline -- \ ``` Walk that list top-to-bottom (oldest-first is easier — newest is at top, so reverse). For each commit: -1. Read the commit (`git show `) to see what client/protocol/docs changed. +1. Read the commit (`git -C .upstream show `) to see what client/protocol/docs changed. 2. If it's JS-internal (bundling, dispatcher conventions, electron, mcp, dashboard, trace-viewer, test-runner) — skip. 3. If it touches `docs/src/api/` or types, check `langs:` annotations — features marked `langs: js`/`langs: js, python` don't apply to Java. 4. If it adds/changes a public API method or option that applies to Java, port it. The api.json regenerated by `roll_driver.sh` already contains the new types/options, so the generated Java interfaces usually pick them up automatically — what's typically missing is the `*Impl` wiring. @@ -40,7 +42,7 @@ Walk that list top-to-bottom (oldest-first is easier — newest is at top, so re ## What to include in the rolling PR -- Driver version bump +- Driver commit bump in `scripts/DRIVER_VERSION` - Generated interface diffs from `roll_driver.sh` - `*Impl` wiring for each ported feature - Generator updates (import lists, special-cases) if new types appeared @@ -48,20 +50,20 @@ Walk that list top-to-bottom (oldest-first is easier — newest is at top, so re - PR description: list each upstream PR ported, each skipped (with reason), and each verified-already-supported Rolling includes: -- updating client implementation to match changes in the upstream JS implementation (see ../playwright/packages/playwright-core/src/client) +- updating client implementation to match changes in the upstream JS implementation (see .upstream/packages/playwright-core/src/client) - adding a couple of new tests to verify new/changed functionality ## Mimicking the JavaScript implementation -The Java client is a port of the JS client in `../playwright/packages/playwright-core/src/client/`. When implementing a new or changed method, always read the corresponding JS file first and mirror its logic: +The Java client is a port of the JS client in `.upstream/packages/playwright-core/src/client/`. When implementing a new or changed method, always read the corresponding JS file first and mirror its logic: ``` -../playwright/packages/playwright-core/src/client/browserContext.ts -../playwright/packages/playwright-core/src/client/page.ts -../playwright/packages/playwright-core/src/client/tracing.ts -../playwright/packages/playwright-core/src/client/video.ts -../playwright/packages/playwright-core/src/client/locator.ts -../playwright/packages/playwright-core/src/client/network.ts +.upstream/packages/playwright-core/src/client/browserContext.ts +.upstream/packages/playwright-core/src/client/page.ts +.upstream/packages/playwright-core/src/client/tracing.ts +.upstream/packages/playwright-core/src/client/video.ts +.upstream/packages/playwright-core/src/client/locator.ts +.upstream/packages/playwright-core/src/client/network.ts ... ``` @@ -138,12 +140,13 @@ Common patterns: ## Rebuilding the driver-bundle after a roll -`./scripts/roll_driver.sh` does the whole roll pipeline end-to-end: bumps `DRIVER_VERSION`, downloads new driver files into `driver-bundle/src/main/resources/driver//`, regenerates `api.json` and the Java interfaces, and updates the README. When all of that succeeds, the next `mvn` invocation that touches `driver-bundle` will pick up the new files and you don't need to think about it. +`./scripts/roll_driver.sh` does the whole roll pipeline end-to-end: moves `DRIVER_VERSION` to the new commit, builds the driver from `.upstream/` into `driver/src/main/resources/driver/package/` and `driver-bundle/src/main/resources/driver//`, regenerates `api.json` and the Java interfaces, and updates the README. When all of that succeeds, the next `mvn` invocation that touches `driver-bundle` will pick up the new files and you don't need to think about it. -But if any step in the pipeline fails (the very common case is the API generator throwing on a new type — see *Fixing generator and compilation errors*), the run aborts before `driver-bundle/target/classes/` has been refreshed. From that point on, until you manually rebuild `driver-bundle`, the test JVM will load the **old** driver from the cached `target/classes`/installed jar even though the source resources have already been swapped to the new version. +But if any step in the pipeline fails (the very common case is the API generator throwing on a new type — see *Fixing generator and compilation errors*), the run aborts before `driver-bundle/target/classes/` has been refreshed. From that point on, until you manually rebuild `driver` and `driver-bundle`, the test JVM will load the **old** driver from the cached `target/classes`/installed jar even though the source resources have already been swapped to the new version. -Fix — rebuild `driver-bundle` once before re-running tests: +Fix — rebuild both once before re-running tests: ``` +mvn -f driver/pom.xml install -DskipTests mvn -f driver-bundle/pom.xml install -DskipTests ``` @@ -178,5 +181,5 @@ Each line is a stack frame inside a test method — typically you'll see one or When you've identified a hanging test: 1. Run it in isolation: `mvn -f playwright/pom.xml test -Dtest='TestClass#testMethod'`. If it passes alone, it's a parallel-load flake — note it but move on. -2. If it still hangs in isolation, look for a recent fix in the upstream repo for the *same* test name. Use `git log --oneline tests/library/.spec.ts` in `~/playwright`. Upstream fixes for client-side hangs are often small and portable (e.g. `about:blank` → `server.EMPTY_PAGE` from microsoft/playwright#39840 fixed `route-web-socket.spec.ts` arraybuffer hangs — apparently some browser changed the WebSocket origin policy on `about:blank`). +2. If it still hangs in isolation, look for a recent fix in the upstream repo for the *same* test name. Use `git -C .upstream log --oneline -- tests/library/.spec.ts`. Upstream fixes for client-side hangs are often small and portable (e.g. `about:blank` → `server.EMPTY_PAGE` from microsoft/playwright#39840 fixed `route-web-socket.spec.ts` arraybuffer hangs — apparently some browser changed the WebSocket origin policy on `about:blank`). 3. When porting an upstream fix, mirror the helper signature change rather than hard-coding workarounds. E.g. if upstream added a `server` parameter to `setupWS`, do the same in Java by injecting `Server server` via the JUnit fixture (`@FixtureTest` already wires up `ServerLifecycle`, so adding `Server server` to the test method signature is enough — no class-level boilerplate). Watch for local-variable shadowing when you add a `Server server` parameter to a method that already has a `WebSocketRoute server` local; rename the local. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72ea4d8f8..e0ded9c8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,9 +30,13 @@ jobs: with: distribution: zulu java-version: 8 - - name: Download drivers + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Build the driver shell: bash - run: scripts/download_driver.sh + run: scripts/build_driver.sh - name: Build & Install run: mvn -B install -D skipTests --no-transfer-progress - name: Install browsers @@ -81,9 +85,13 @@ jobs: with: distribution: zulu java-version: 8 - - name: Download drivers + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Build the driver shell: bash - run: scripts/download_driver.sh + run: scripts/build_driver.sh - name: Build & Install run: mvn -B install -D skipTests --no-transfer-progress - name: Install browsers @@ -109,9 +117,13 @@ jobs: with: distribution: temurin java-version: 25 - - name: Download drivers + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Build the driver shell: bash - run: scripts/download_driver.sh + run: scripts/build_driver.sh - name: Build & Install run: mvn -B install -D skipTests --no-transfer-progress # Runs on JDK 25: with JDK 8 the javadoc plugin never uses the module path. diff --git a/.github/workflows/test_cli.yml b/.github/workflows/test_cli.yml index 9f61bdd4c..c6b0bda5f 100644 --- a/.github/workflows/test_cli.yml +++ b/.github/workflows/test_cli.yml @@ -20,8 +20,12 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - name: Download drivers - run: scripts/download_driver.sh + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Build the driver + run: scripts/build_driver.sh - name: Intall Playwright run: mvn install -D skipTests --no-transfer-progress - name: Test CLI diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index b6f601177..7d9ade745 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -36,6 +36,10 @@ jobs: arch: arm64 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 - name: Build Docker image run: | bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} @@ -56,6 +60,8 @@ jobs: - name: Copy repository inside docker container run: | + # The driver is built already; the microsoft/playwright checkout it was built from is large. + rm -rf .upstream docker cp . "$CONTAINER_ID":/home/pwuser/playwright # build.sh installed the SNAPSHOT artifacts into the local Maven repository # of the runner; give them to pwuser so the test projects resolve them. diff --git a/.github/workflows/verify_api.yml b/.github/workflows/verify_api.yml index 8cedfb20f..1c6025d26 100644 --- a/.github/workflows/verify_api.yml +++ b/.github/workflows/verify_api.yml @@ -20,8 +20,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Download drivers - run: scripts/download_driver.sh + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Build the driver + run: scripts/build_driver.sh - name: Regenerate APIs run: scripts/generate_api.sh - name: Build & Install diff --git a/.gitignore b/.gitignore index 33685ce73..5a150e817 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ target/ *.iml .npmrc + +# The microsoft/playwright checkout that the driver is built from (scripts/build_driver.sh). +.upstream/ diff --git a/AGENTS.md b/AGENTS.md index 78ee63543..33477eca1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,15 +6,15 @@ Paths such as `~/code/playwright` in this file assume that you check the repos o ## How this repo depends on Playwright -- **The driver.** The Java client talks to the Node.js driver that `microsoft/playwright` publishes: the `playwright-core` npm package, which `scripts/download_driver.sh` unpacks into `driver/src/main/resources/driver/package/`. `scripts/DRIVER_VERSION` names its version, and `npm view playwright@ gitHead` prints its upstream commit. Upstream `main` is close to it. Release `1.X.0` bundles the driver of `scripts/DRIVER_VERSION` at tag `v1.X.0`. -- **Upstream code.** In `~/code/playwright`: the client in `packages/playwright-core/src/client/`, the API docs in `docs/src/api/`, the tests in `tests/page/` and `tests/library/`. Its `AGENTS.md` says how to build it and run a test. +- **The driver.** The Java client talks to the Node.js driver, the `playwright-core` package of `microsoft/playwright`, built from source at the commit in `scripts/DRIVER_VERSION`. `scripts/build_driver.sh` clones `microsoft/playwright` into `.upstream/` (gitignored), checks that commit out, builds it and unpacks the package into `driver/src/main/resources/driver/package/`. Do not edit, commit or switch branches in `.upstream/`. `git show v1.X.0:scripts/DRIVER_VERSION` prints the upstream commit of a release, or, for releases up to 1.65, the `playwright-core` version of its driver. +- **Upstream code.** In `.upstream/`, at the commit of the driver, or in `~/code/playwright`, which may be ahead of it: the client in `packages/playwright-core/src/client/`, the API docs in `docs/src/api/`, the tests in `tests/page/` and `tests/library/`. Its `AGENTS.md` says how to build it and run a test. - **Where a bug is.** When the same calls fail in a Node.js test upstream too, the cause is in the driver or a browser, and the fix lands in `microsoft/playwright`. When Node.js passes, the bug is in the Java client: compare the `*Impl.java` with its JavaScript counterpart, and fix it here. -- **The generated API.** `scripts/generate_api.sh` runs upstream's `utils/doclint/generateApiJson.js` at the commit of the driver, and `tools/api-generator` writes every interface and options class in `playwright/src/main/java/com/microsoft/playwright/`, `options/` and `assertions/`. Only `CLI.java`, `PlaywrightException.java`, `TimeoutError.java`, `assertions/PlaywrightAssertions.java` and the `package-info.java` files there are written by hand. Never edit a generated file: the next roll reverts it. A missing method or option is a change to `docs/src/api/` upstream. +- **The generated API.** `scripts/generate_api.sh` runs `utils/doclint/generateApiJson.js` of `.upstream/`, and `tools/api-generator` writes every interface and options class in `playwright/src/main/java/com/microsoft/playwright/`, `options/` and `assertions/`. Only `CLI.java`, `PlaywrightException.java`, `TimeoutError.java`, `assertions/PlaywrightAssertions.java` and the `package-info.java` files there are written by hand. Never edit a generated file: the next roll reverts it. A missing method or option is a change to `docs/src/api/` upstream. ## Build and test ```bash -scripts/download_driver.sh # the driver, once per DRIVER_VERSION +scripts/build_driver.sh # the driver, once per DRIVER_VERSION; needs git and Node.js mvn -B install -D skipTests --no-transfer-progress # build and install every module mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps" -f playwright/pom.xml --no-transfer-progress BROWSER=chromium mvn test -f playwright/pom.xml -D test=TestPageScreenshot --no-transfer-progress diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4622489f0..627f93e93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,13 +35,13 @@ git clone https://github.com/microsoft/playwright-java cd playwright-java ``` -2. Run the following script to download and assemble the Playwright driver. The platform-independent `playwright-core` package is assembled once into `driver/src/main/resources/driver/package/`, and the Node.js binary for each platform into `driver-bundle/src/main/resources/driver//` (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run). +2. Run the following script to build and assemble the Playwright driver; it needs git and Node.js with npm. The platform-independent `playwright-core` package is assembled once into `driver/src/main/resources/driver/package/`, and the Node.js binary for each platform into `driver-bundle/src/main/resources/driver//` (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run). ```bash -scripts/download_driver.sh +scripts/build_driver.sh ``` -Each driver is assembled from the [`playwright-core`](https://www.npmjs.com/package/playwright-core) npm package (version pinned in [scripts/DRIVER_VERSION](scripts/DRIVER_VERSION)) and the Node.js binary of the version pinned in [scripts/NODE_VERSION](scripts/NODE_VERSION) from https://nodejs.org, the same way the upstream Playwright build does it. `scripts/roll_driver.sh` updates the pinned Node.js version to the latest release of the same major version on each roll. To update only Node.js, run `scripts/roll_node.sh` and then `scripts/download_driver.sh`. +The driver is built from source: the script clones [microsoft/playwright](https://github.com/microsoft/playwright) into `.upstream/` (gitignored), checks out the commit pinned in [scripts/DRIVER_VERSION](scripts/DRIVER_VERSION) and builds the `playwright-core` package from it (`npm ci`, `npm run build`, `npm pack`). The build of `.upstream/` is reused until the commit changes. Each driver also gets the Node.js binary of the version pinned in [scripts/NODE_VERSION](scripts/NODE_VERSION) from https://nodejs.org, the same way the upstream Playwright build does it. Run the script again when `scripts/DRIVER_VERSION` or `scripts/NODE_VERSION` changes, for example after a pull. `scripts/roll_driver.sh` updates the pinned Node.js version to the latest release of the same major version on each roll. To update only Node.js, run `scripts/roll_node.sh` and then `scripts/build_driver.sh`. ### Building and running the tests with Maven @@ -96,7 +96,7 @@ with a `@Fixture` method reading its `@Parameter` field to run the same tests wi ### Generating API -Public Java API is generated from api.json, which is generated from the upstream Playwright source at the exact commit that produced the driver version in [scripts/DRIVER_VERSION](scripts/DRIVER_VERSION) (resolved via `npm view playwright@ gitHead`). `scripts/generate_api.sh` fetches a minimal upstream checkout automatically; set `PW_SRC_DIR` to reuse an existing `microsoft/playwright` checkout instead. To regenerate Java interfaces for the current driver run: +Public Java API is generated from api.json, which is generated from `.upstream/`, the `microsoft/playwright` checkout at the commit in [scripts/DRIVER_VERSION](scripts/DRIVER_VERSION) that the driver is built from (run `scripts/build_driver.sh` first). Set `PW_SRC_DIR` to generate from another `microsoft/playwright` checkout instead, to try a change to the upstream docs; the committed files must come from `.upstream/`. To regenerate Java interfaces for the current driver run: ```bash ./scripts/generate_api.sh @@ -104,12 +104,14 @@ Public Java API is generated from api.json, which is generated from the upstream #### Updating driver version -Versions of published driver archives can be found in [publish canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) and [publish release](https://github.com/microsoft/playwright/actions/workflows/publish_release_driver.yml) actions logs. To update the driver to a particular version run the following command: +To roll the driver to a branch (`main`, `release-1.66`), a tag (`v1.66.0`) or a commit of `microsoft/playwright` run the following command; the default is the tip of `main`: ```bash -scripts/roll_driver.sh [version] +scripts/roll_driver.sh [ref] ``` +It pins the commit in `scripts/DRIVER_VERSION`, builds the driver from it and regenerates the API. The driver reports the version of `packages/playwright-core/package.json` at that commit: `1.66.0` on a release tag, `1.67.0-next` on `main`. + ### Code Style - We try to follow [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) diff --git a/ROLLING.md b/ROLLING.md index bb57d2577..7fb64c37d 100644 --- a/ROLLING.md +++ b/ROLLING.md @@ -1,7 +1,8 @@ # Rolling Playwright-Java to the latest Playwright driver -* make sure to have at least Java 8 and Maven 3.6.3 +* make sure to have at least Java 8 and Maven 3.6.3, git, and Node.js with npm * clone playwright for java: http://github.com/microsoft/playwright-java -* roll the driver and update generated sources: `./scripts/roll_driver.sh next` +* roll the driver and update generated sources: `./scripts/roll_driver.sh `, where `` is a branch (`main`, the default, or `release-1.66`), a tag (`v1.66.0`) or a commit of `microsoft/playwright`. It pins the commit in `scripts/DRIVER_VERSION`, checks it out in `.upstream/` (a gitignored clone of `microsoft/playwright`) and builds the driver from it +* list the upstream commits to port: `git -C .upstream log --oneline --reverse $(git show HEAD:scripts/DRIVER_VERSION)..$(cat scripts/DRIVER_VERSION)` * fix any errors * commit & send PR with the roll diff --git a/scripts/DRIVER_VERSION b/scripts/DRIVER_VERSION index 902c74186..7f0db5693 100644 --- a/scripts/DRIVER_VERSION +++ b/scripts/DRIVER_VERSION @@ -1 +1 @@ -1.65.0 +a1f35e1955976e84411f9c10358228a80b763ebe diff --git a/scripts/build_driver.sh b/scripts/build_driver.sh new file mode 100755 index 000000000..f989d8e52 --- /dev/null +++ b/scripts/build_driver.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +set -e +set +x + +trap "cd $(pwd -P)" EXIT +cd "$(dirname $0)" + +if [[ ($1 == '-h') || ($1 == '--help') ]]; then + echo "" + echo "This script builds the Playwright driver from source and assembles it for all platforms." + echo "It clones microsoft/playwright into '.upstream/' (gitignored), checks out the commit" + echo "pinned in scripts/DRIVER_VERSION and builds the 'playwright-core' npm package from it." + echo "The platform-independent package is assembled once into the driver module" + echo "('driver/src/main/resources/driver/package'), and the Node.js binary from" + echo "https://nodejs.org (version pinned in scripts/NODE_VERSION) for each platform goes" + echo "into the driver-bundle module ('driver-bundle/src/main/resources/driver/')." + echo "" + echo "Requires git and Node.js with npm." + echo "" + echo "Usage: scripts/build_driver.sh [option]" + echo "" + echo "Options:" + echo " -h, --help display help information" + echo "" + exit 0 +fi + +# Ubuntu 24.04-arm64 emulated via qemu has a bug, so we prefer wget over curl. +# See https://github.com/microsoft/playwright-java/issues/1678. +download() { + local url=$1 + local out=$2 + echo "Downloading $url" + if command -v wget &> /dev/null; then + wget -q -O "$out" "$url" + else + curl --retry 5 --retry-delay 2 -fL -o "$out" "$url" + fi +} + +ROOT="$(cd .. && pwd)" +UPSTREAM_URL="https://github.com/microsoft/playwright.git" +UPSTREAM_DIR="$ROOT/.upstream" + +# scripts/DRIVER_VERSION pins the microsoft/playwright commit. scripts/roll_driver.sh updates it. +DRIVER_VERSION=$(head -1 ./DRIVER_VERSION) +if [[ ! "$DRIVER_VERSION" =~ ^[0-9a-f]{40}$ ]]; then + echo "scripts/DRIVER_VERSION must hold one microsoft/playwright commit (40 hex digits), got '$DRIVER_VERSION'" + exit 1 +fi +# scripts/NODE_VERSION pins the exact Node.js version. scripts/roll_node.sh updates it. +NODE_VERSION=$(head -1 ./NODE_VERSION) + +echo "Driver commit: $DRIVER_VERSION" +echo "Node.js version: $NODE_VERSION" + +# npm uses the registry and the credentials of a root-level .npmrc when there is one (e.g. +# the one the release pipeline writes to point at the internal Azure Artifacts feed). +# Locally, NPM_CONFIG_REGISTRY= can be used to the same effect. +npm_in() { + local dir=$1 + shift + echo "Running npm $* in $dir" + if [[ -f "$ROOT/.npmrc" ]]; then + (cd "$dir" && npm_config_userconfig="$ROOT/.npmrc" npm "$@") + else + (cd "$dir" && npm "$@") + fi +} + +upstream_has_local_changes() { + [[ -n "$(git -C "$UPSTREAM_DIR" status --porcelain)" ]] +} + +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "$TMP_DIR"' EXIT + +# 1. .upstream/ at the commit in scripts/DRIVER_VERSION. +CLONED="" +if [[ ! -e "$UPSTREAM_DIR/.git" ]]; then + echo "Cloning $UPSTREAM_URL into $UPSTREAM_DIR" + # The whole history, for listing the changes of a roll; file contents are fetched on demand. + git clone --quiet --filter=blob:none --no-checkout "$UPSTREAM_URL" "$UPSTREAM_DIR" + CLONED=1 +fi +if [[ -n "$CLONED" || "$(git -C "$UPSTREAM_DIR" rev-parse HEAD)" != "$DRIVER_VERSION" ]]; then + if [[ -z "$CLONED" ]] && upstream_has_local_changes; then + echo "$UPSTREAM_DIR has local changes. Commit or discard them before checking out $DRIVER_VERSION." + exit 1 + fi + if ! git -C "$UPSTREAM_DIR" cat-file -e "$DRIVER_VERSION^{commit}" 2> /dev/null; then + git -C "$UPSTREAM_DIR" fetch --quiet --tags origin + # A commit that no branch or tag reaches any more, for example on a deleted branch. + git -C "$UPSTREAM_DIR" cat-file -e "$DRIVER_VERSION^{commit}" 2> /dev/null \ + || git -C "$UPSTREAM_DIR" fetch --quiet origin "$DRIVER_VERSION" + fi + git -C "$UPSTREAM_DIR" checkout --quiet --detach "$DRIVER_VERSION" +fi +echo "$UPSTREAM_DIR is at $DRIVER_VERSION" + +# 2. Build it, once per commit. +if upstream_has_local_changes; then + echo "$UPSTREAM_DIR has local changes. The driver is pinned to a commit, so build it from a clean checkout." + exit 1 +fi +UPSTREAM_CORE_DIR="$UPSTREAM_DIR/packages/playwright-core" +# npm ci removes node_modules, and the stamp with it. +STAMP="$UPSTREAM_DIR/node_modules/.playwright-java-build" +if [[ "$(cat "$STAMP" 2> /dev/null)" != "$DRIVER_VERSION" || ! -d "$UPSTREAM_CORE_DIR/lib" ]]; then + npm_in "$UPSTREAM_DIR" ci --no-audit --no-fund + npm_in "$UPSTREAM_DIR" run build + echo "$DRIVER_VERSION" > "$STAMP" +fi + +# The platform-independent driver code (playwright-core) is assembled once into the driver module; +# the Node.js binary for each platform is assembled into the driver-bundle module. See issue #1196. +CORE_DEST="$ROOT/driver/src/main/resources/driver" +NODE_DEST="$ROOT/driver-bundle/src/main/resources/driver" + +# 3. playwright-core package -> driver module (once, shared by every platform). +echo "Assembling playwright-core package to $CORE_DEST/package" +npm_in "$UPSTREAM_CORE_DIR" pack --pack-destination "$TMP_DIR" --silent > /dev/null +CORE_TGZ=$(ls "$TMP_DIR"/playwright-core-*.tgz) +rm -rf "$CORE_DEST/package" +mkdir -p "$CORE_DEST" +# The npm tarball has a top-level package/ directory, so this creates $CORE_DEST/package. +tar -xzf "$CORE_TGZ" -C "$CORE_DEST" +rm -f "$CORE_TGZ" +# Upstream copies these into the package before it publishes it (LICENCE_FILES in utils/workspace.js). +cp "$UPSTREAM_DIR/NOTICE" "$UPSTREAM_DIR/LICENSE" "$CORE_DEST/package/" + +# 4. Node.js binary for each platform -> driver-bundle module. +# :: +for ENTRY in \ + "mac:darwin-x64:tar.gz" \ + "mac-arm64:darwin-arm64:tar.gz" \ + "linux:linux-x64:tar.gz" \ + "linux-arm64:linux-arm64:tar.gz" \ + "win32_x64:win-x64:zip" +do + IFS=':' read -r PLATFORM NODE_SUFFIX ARCHIVE <<< "$ENTRY" + DEST="$NODE_DEST/$PLATFORM" + echo "Assembling Node.js for $PLATFORM to $DEST" + rm -rf "$DEST" + mkdir -p "$DEST" + + # Node.js binary and its license from the official Node.js distribution. + NODE_DIR="node-v$NODE_VERSION-$NODE_SUFFIX" + NODE_ARCHIVE="$TMP_DIR/$NODE_DIR.$ARCHIVE" + download "https://nodejs.org/dist/v$NODE_VERSION/$NODE_DIR.$ARCHIVE" "$NODE_ARCHIVE" + if [[ $ARCHIVE == "zip" ]]; then + unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/node.exe" -d "$DEST" + unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/LICENSE" -d "$DEST" + else + tar -xzf "$NODE_ARCHIVE" -C "$DEST" --strip-components=2 "$NODE_DIR/bin/node" + tar -xzf "$NODE_ARCHIVE" -C "$DEST" --strip-components=1 "$NODE_DIR/LICENSE" + fi + rm -f "$NODE_ARCHIVE" +done + +UPSTREAM_VERSION=$(cd "$UPSTREAM_CORE_DIR" && node -p "require('./package.json').version") +echo "" +echo "The driver has been built from microsoft/playwright $DRIVER_VERSION; it reports version $UPSTREAM_VERSION." +echo "" diff --git a/scripts/download_driver.sh b/scripts/download_driver.sh deleted file mode 100755 index 935b8a306..000000000 --- a/scripts/download_driver.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -set -e -set +x - -trap "cd $(pwd -P)" EXIT -cd "$(dirname $0)" - -if [[ ($1 == '-h') || ($1 == '--help') ]]; then - echo "" - echo "This script downloads and assembles the Playwright driver for all platforms." - echo "The platform-independent 'playwright-core' npm package is assembled once into the driver" - echo "module ('driver/src/main/resources/driver/package'), and the Node.js binary from" - echo "https://nodejs.org (version pinned in scripts/NODE_VERSION) for each platform goes" - echo "into the driver-bundle module ('driver-bundle/src/main/resources/driver/'), the" - echo "same way the upstream Playwright build does it." - echo "" - echo "Usage: scripts/download_driver.sh [option]" - echo "" - echo "Options:" - echo " -h, --help display help information" - echo "" - exit 0 -fi - -# Ubuntu 24.04-arm64 emulated via qemu has a bug, so we prefer wget over curl. -# See https://github.com/microsoft/playwright-java/issues/1678. -download() { - local url=$1 - local out=$2 - echo "Downloading $url" - if command -v wget &> /dev/null; then - wget -q -O "$out" "$url" - else - curl --retry 5 --retry-delay 2 -fL -o "$out" "$url" - fi -} - -DRIVER_VERSION=$(head -1 ./DRIVER_VERSION) -ROOT="$(cd .. && pwd)" - -# All npm commands run from the repository root so that a root-level .npmrc (e.g. the one -# the release pipeline writes to point at the internal Azure Artifacts feed) is honoured. -# Locally, NPM_CONFIG_REGISTRY= can be used to the same effect. -npm_at_root() { - (cd "$ROOT" && npm "$@") -} - -TMP_DIR="$(mktemp -d)" -trap 'rm -rf "$TMP_DIR"' EXIT - -# scripts/NODE_VERSION pins the exact Node.js version. scripts/roll_node.sh updates it. -NODE_VERSION=$(head -1 ./NODE_VERSION) - -echo "Driver version: $DRIVER_VERSION" -echo "Node.js version: $NODE_VERSION" - -# The platform-independent driver code (playwright-core) is assembled once into the driver module; -# the Node.js binary for each platform is assembled into the driver-bundle module. See issue #1196. -CORE_DEST="$ROOT/driver/src/main/resources/driver" -NODE_DEST="$ROOT/driver-bundle/src/main/resources/driver" - -# 1. playwright-core package -> driver module (once, shared by every platform). -echo "Assembling playwright-core package to $CORE_DEST/package" -rm -rf "$CORE_DEST/package" -mkdir -p "$CORE_DEST" -# Fetched via npm rather than a hard-coded registry URL so that the configured registry -# (and its credentials) are used. -CORE_TGZ="$TMP_DIR/playwright-core-$DRIVER_VERSION.tgz" -echo "Downloading playwright-core@$DRIVER_VERSION from $(npm_at_root config get registry)" -npm_at_root pack "playwright-core@$DRIVER_VERSION" --pack-destination "$TMP_DIR" --silent > /dev/null -# The npm tarball has a top-level package/ directory, so this creates $CORE_DEST/package. -tar -xzf "$CORE_TGZ" -C "$CORE_DEST" -rm -f "$CORE_TGZ" - -# 2. Node.js binary for each platform -> driver-bundle module. -# :: -for ENTRY in \ - "mac:darwin-x64:tar.gz" \ - "mac-arm64:darwin-arm64:tar.gz" \ - "linux:linux-x64:tar.gz" \ - "linux-arm64:linux-arm64:tar.gz" \ - "win32_x64:win-x64:zip" -do - IFS=':' read -r PLATFORM NODE_SUFFIX ARCHIVE <<< "$ENTRY" - DEST="$NODE_DEST/$PLATFORM" - echo "Assembling Node.js for $PLATFORM to $DEST" - rm -rf "$DEST" - mkdir -p "$DEST" - - # Node.js binary and its license from the official Node.js distribution. - NODE_DIR="node-v$NODE_VERSION-$NODE_SUFFIX" - NODE_ARCHIVE="$TMP_DIR/$NODE_DIR.$ARCHIVE" - download "https://nodejs.org/dist/v$NODE_VERSION/$NODE_DIR.$ARCHIVE" "$NODE_ARCHIVE" - if [[ $ARCHIVE == "zip" ]]; then - unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/node.exe" -d "$DEST" - unzip -joq "$NODE_ARCHIVE" "$NODE_DIR/LICENSE" -d "$DEST" - else - tar -xzf "$NODE_ARCHIVE" -C "$DEST" --strip-components=2 "$NODE_DIR/bin/node" - tar -xzf "$NODE_ARCHIVE" -C "$DEST" --strip-components=1 "$NODE_DIR/LICENSE" - fi - rm -f "$NODE_ARCHIVE" -done - -echo "" -echo "All drivers have been successfully assembled." -echo "" diff --git a/scripts/generate_api.sh b/scripts/generate_api.sh index 78ed6d4ad..44ff6ca8b 100755 --- a/scripts/generate_api.sh +++ b/scripts/generate_api.sh @@ -8,38 +8,25 @@ cd "$(dirname "$0")/.." DRIVER_VERSION=$(head -1 ./scripts/DRIVER_VERSION) -# api.json is generated from the upstream Playwright source at the exact commit -# that produced this driver version. Set PW_SRC_DIR to reuse an existing upstream -# checkout, otherwise a minimal one is fetched into a temporary directory. -GIT_HEAD=$(npm view playwright@"$DRIVER_VERSION" gitHead) -if [[ -z "$GIT_HEAD" ]]; then - echo "Failed to resolve upstream commit (gitHead) for playwright@$DRIVER_VERSION" - exit 1 -fi - -CLONED_UPSTREAM="" +# api.json is generated from .upstream/, the microsoft/playwright checkout at the commit in +# scripts/DRIVER_VERSION that the driver is built from (scripts/build_driver.sh). PW_SRC_DIR +# generates it from another checkout, to try a change to the docs or to the generator. The +# committed files must come from .upstream/: CI generates them again and fails when they differ. if [[ -n "$PW_SRC_DIR" ]]; then UPSTREAM_DIR="$PW_SRC_DIR" - echo "Using upstream Playwright checkout at $UPSTREAM_DIR (PW_SRC_DIR)" + echo "Generating from $UPSTREAM_DIR (PW_SRC_DIR), not from .upstream/" else - UPSTREAM_DIR=$(mktemp -d) - CLONED_UPSTREAM="$UPSTREAM_DIR" - echo "Fetching upstream Playwright source at $GIT_HEAD" - # generateApiJson.js only needs utils/ and docs/, so fetch just those. - git clone --quiet --filter=blob:none --no-checkout https://github.com/microsoft/playwright.git "$UPSTREAM_DIR" - git -C "$UPSTREAM_DIR" sparse-checkout init --cone - git -C "$UPSTREAM_DIR" sparse-checkout set utils docs - git -C "$UPSTREAM_DIR" checkout --quiet "$GIT_HEAD" + UPSTREAM_DIR="./.upstream" + if [[ "$(git -C "$UPSTREAM_DIR" rev-parse HEAD 2> /dev/null)" != "$DRIVER_VERSION" ]]; then + echo ".upstream/ is not at $DRIVER_VERSION, the commit in scripts/DRIVER_VERSION. Run: scripts/build_driver.sh" + exit 1 + fi fi -echo "Updating api.json from upstream playwright@$DRIVER_VERSION ($GIT_HEAD)" +echo "Updating api.json from $UPSTREAM_DIR" API_JSON_MODE=1 node "$UPSTREAM_DIR/utils/doclint/generateApiJson.js" \ > ./tools/api-generator/src/main/resources/api.json -if [[ -n "$CLONED_UPSTREAM" ]]; then - rm -rf "$CLONED_UPSTREAM" -fi - mvn compile -f ./tools/api-generator --no-transfer-progress echo "Regenerating Java interfaces" diff --git a/scripts/roll_driver.sh b/scripts/roll_driver.sh index f4a3c3f03..8d4e404e1 100755 --- a/scripts/roll_driver.sh +++ b/scripts/roll_driver.sh @@ -6,20 +6,35 @@ set +x trap "cd $(pwd -P)" EXIT cd "$(dirname $0)" -if [ "$#" -gt 1 ]; then +if [[ "$#" -gt 1 || ($1 == '-h') || ($1 == '--help') ]]; then echo "" - echo "Usage: scripts/roll_driver.sh [next|beta|]" + echo "Rolls the driver to a microsoft/playwright branch (main, release-1.66), tag (v1.66.0)" + echo "or commit: pins its commit in scripts/DRIVER_VERSION, rolls Node.js, builds the driver" + echo "from source and regenerates the API. The default is the tip of main." + echo "" + echo "Usage: scripts/roll_driver.sh []" echo "" exit 1 fi -ARG=${1:-next} -if [[ "$ARG" == "next" ]]; then - NEW_VERSION=$(npm view playwright@next version) -elif [[ "$ARG" == "beta" ]]; then - NEW_VERSION=$(npm view playwright@beta version) +UPSTREAM_URL="https://github.com/microsoft/playwright.git" +REF=${1:-main} +if [[ "$REF" =~ ^[0-9a-f]{40}$ ]]; then + NEW_VERSION=$REF else - NEW_VERSION=$ARG + # "^{}" is the commit that an annotated tag points to. + REFS=$(git ls-remote "$UPSTREAM_URL" "refs/tags/$REF^{}" "refs/tags/$REF" "refs/heads/$REF") + NEW_VERSION="" + for NAME in "refs/tags/$REF^{}" "refs/tags/$REF" "refs/heads/$REF"; do + NEW_VERSION=$(echo "$REFS" | awk -v name="$NAME" '$2 == name { print $1 }') + if [[ -n "$NEW_VERSION" ]]; then + break + fi + done + if [[ -z "$NEW_VERSION" ]]; then + echo "$REF is not a branch, a tag or a full commit of $UPSTREAM_URL" + exit 1 + fi fi CURRENT_VERSION=$(head -1 ./DRIVER_VERSION) echo "Rolling driver from $CURRENT_VERSION to $NEW_VERSION" @@ -27,17 +42,24 @@ echo "Rolling driver from $CURRENT_VERSION to $NEW_VERSION" echo $NEW_VERSION > ./DRIVER_VERSION # Each roll also moves the driver to the latest Node.js release of the pinned major version. ./roll_node.sh -./download_driver.sh +./build_driver.sh ./generate_api.sh ./update_readme.sh -node -e "$(cat < parseInt(part, 10)); - minorVersion[1]--; - const previousMajorVersion = majorVersion + '.' + minorVersion + '.0'; +# The version that the driver reports: 1.66.0 on a release tag, 1.67.0-next on main. +PACKAGE_VERSION=$(node -p "require('../.upstream/packages/playwright-core/package.json').version") +node -e "$(cat < parseInt(part, 10)); + const exampleVersion = majorVersion + '.' + minorVersion + '.0'; fs.writeFileSync('../examples/pom.xml', fs.readFileSync('../examples/pom.xml', 'utf8') - .replace(/.*<\/playwright\.version>/, '' + previousMajorVersion + '') + .replace(/.*<\/playwright\.version>/, '' + exampleVersion + '') ); -EOF -)" $NEW_VERSION +EOF2 +)" $PACKAGE_VERSION + +echo "" +echo "Rolled to microsoft/playwright $NEW_VERSION; the driver reports version $PACKAGE_VERSION." +echo "The upstream commits since the previous pin:" +echo " git -C .upstream log --oneline --reverse $CURRENT_VERSION..$NEW_VERSION" +echo "" diff --git a/scripts/roll_node.sh b/scripts/roll_node.sh index e101a911e..4059da0ad 100755 --- a/scripts/roll_node.sh +++ b/scripts/roll_node.sh @@ -9,7 +9,7 @@ cd "$(dirname $0)" if [ "$#" -gt 0 ]; then echo "" echo "Updates scripts/NODE_VERSION to the latest Node.js release of the same major version." - echo "Run scripts/download_driver.sh after that to download the new Node.js binaries." + echo "Run scripts/build_driver.sh after that to download the new Node.js binaries." echo "" echo "Usage: scripts/roll_node.sh" echo "" diff --git a/utils/docker/build.sh b/utils/docker/build.sh index 2494eade8..b00b5d603 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -10,7 +10,7 @@ if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then echo "" echo " docker run --rm -it playwright:localbuild-noble /bin/bash" echo "" - echo "NOTE: this requires a JDK, Maven and npm on the host: the client is built here" + echo "NOTE: this requires git, a JDK, Maven and Node.js with npm on the host: the driver and the client are built here" echo "and the image only runs it to install the browsers." echo "" exit 0 @@ -43,7 +43,7 @@ MVN=(mvn --no-transfer-progress) # Maven are available, and stage the client jar and its runtime dependencies under # dist/. The Dockerfile runs the CLI from there to install the browsers and their # dependencies. The build context is this directory, so nothing else reaches the image. -../../scripts/download_driver.sh +../../scripts/build_driver.sh "${MVN[@]}" -B install -D skipTests -f ../../pom.xml if ! PW_VERSION=$("${MVN[@]}" -q -N -f ../../pom.xml exec:exec -D exec.executable=echo \ From 585c3349a313d0abba1aa939aeca835c2478dc25 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 13:37:48 -0800 Subject: [PATCH 2/2] devops: roll the driver to main, a release branch or a commit only The roll no longer refers to published driver versions or tags. scripts/roll_driver.sh takes main, release-1. or a full commit hash, and no longer edits examples/pom.xml. --- .azure-pipelines/publish-docker.yml | 6 +- .azure-pipelines/publish.yml | 6 +- .../skills/playwright-java-release/SKILL.md | 13 ++- .claude/skills/playwright-roll/SKILL.md | 93 ++++++++++++------- .github/workflows/test_docker.yml | 2 +- .gitignore | 2 +- AGENTS.md | 4 +- CONTRIBUTING.md | 6 +- ROLLING.md | 2 +- scripts/build_driver.sh | 57 ++++++------ scripts/generate_api.sh | 9 +- scripts/roll_driver.sh | 66 ++++++------- utils/docker/build.sh | 2 +- 13 files changed, 150 insertions(+), 118 deletions(-) diff --git a/.azure-pipelines/publish-docker.yml b/.azure-pipelines/publish-docker.yml index 4b5a44fbe..c9b3b0528 100644 --- a/.azure-pipelines/publish-docker.yml +++ b/.azure-pipelines/publish-docker.yml @@ -69,9 +69,9 @@ extends: echo '{ "data-root": "/mnt/docker" }' | sudo tee /etc/docker/daemon.json sudo service docker start - # scripts/build_driver.sh builds the driver from .upstream/ on the host with `npm ci`, - # which picks up the registry and the credentials from this .npmrc. The Docker build - # context is utils/docker (see build.sh), so this file never reaches the images. + # scripts/build_driver.sh builds the driver from .upstream/ on the host. `npm ci` uses + # the registry and the credentials of this .npmrc file. The Docker build context is + # utils/docker (see build.sh), thus this file does not go into the images. - task: Bash@3 displayName: "setup .npmrc" inputs: diff --git a/.azure-pipelines/publish.yml b/.azure-pipelines/publish.yml index a6c2255be..1478ea8cb 100644 --- a/.azure-pipelines/publish.yml +++ b/.azure-pipelines/publish.yml @@ -79,9 +79,9 @@ extends: inputs: workingFile: .npmrc - # Clones microsoft/playwright into .upstream/ at the commit in scripts/DRIVER_VERSION - # and builds the driver from it with `npm ci`, which picks up the registry and - # the credentials from the .npmrc above. + # The script clones microsoft/playwright into .upstream/ at the commit in + # scripts/DRIVER_VERSION and builds the driver from it. `npm ci` uses the registry + # and the credentials of the .npmrc file above. - bash: ./scripts/build_driver.sh displayName: 'Build the driver' diff --git a/.claude/skills/playwright-java-release/SKILL.md b/.claude/skills/playwright-java-release/SKILL.md index 1ded10c27..988f39b19 100644 --- a/.claude/skills/playwright-java-release/SKILL.md +++ b/.claude/skills/playwright-java-release/SKILL.md @@ -3,7 +3,18 @@ name: playwright-java-release description: Prepare a Playwright Java release after the rolling PR has merged — cut the release branch, mark the Maven version, add Java-specific changes to the release notes, draft the GitHub release, and tick the Java boxes in the internal checklist. --- -Use this skill once the `chore: roll driver to 1.X.0` PR has merged into `main` and the upstream JS `v1.X.0` is published. The driver is built from the `microsoft/playwright` commit in `scripts/DRIVER_VERSION`: for a release it must be the commit of the upstream tag `v1.X.0` (`scripts/roll_driver.sh v1.X.0`), so that the driver reports `1.X.0`. The rolling work itself is covered by the [[playwright-roll]] skill. +Use this skill after the roll PR for `1.X` is in `main`. The [[playwright-roll]] skill does the roll. + +First, check the driver. We build the driver from the `microsoft/playwright` commit in `scripts/DRIVER_VERSION`, not from a published npm package. For a release, that commit must be on the upstream `release-1.X` branch, and the driver must report `1.X.y`: + +```bash +scripts/build_driver.sh +git -C .upstream fetch origin release-1.X +git -C .upstream merge-base --is-ancestor "$(cat scripts/DRIVER_VERSION)" FETCH_HEAD && echo "on release-1.X" +git -C .upstream show "$(cat scripts/DRIVER_VERSION)":packages/playwright-core/package.json | grep '"version"' +``` + +If a check fails, tell the user, and roll with `scripts/roll_driver.sh release-1.X` (the tip of the branch) or `scripts/roll_driver.sh ` (the commit that the user gives). Throughout this doc, replace `X` with the minor version (e.g. `60` for `1.60.0`) and `` with the fork owner (`gh api user --jq .login`). diff --git a/.claude/skills/playwright-roll/SKILL.md b/.claude/skills/playwright-roll/SKILL.md index 5c5c86036..9649b9eed 100644 --- a/.claude/skills/playwright-roll/SKILL.md +++ b/.claude/skills/playwright-roll/SKILL.md @@ -1,30 +1,45 @@ --- name: playwright-roll -description: Roll Playwright Java to a new version +description: Roll Playwright Java to a new microsoft/playwright commit. Moves the commit in scripts/DRIVER_VERSION, builds the driver from source, generates the API, and ports the upstream changes of the client. --- -Help the user roll to a new version of Playwright. -ROLLING.md contains general instructions and scripts. +# Rolling Playwright -The driver is built from source: `scripts/DRIVER_VERSION` holds one `microsoft/playwright` commit, and `.upstream/` (gitignored) is a clone of `microsoft/playwright` at that commit. Do not edit, commit or switch branches in it. +Read `AGENTS.md` and `ROLLING.md` first. -Start with running `./scripts/roll_driver.sh ` to pin the new commit, build the driver from it and generate the API to see the state of things. `` is a branch (`main`, the default, or `release-1.X`), a tag (`v1.X.0`) or a commit of `microsoft/playwright`. -Afterwards, walk through the upstream changes that affect the Java client and port the relevant ones. +`scripts/DRIVER_VERSION` holds one commit of `microsoft/playwright`. We build the driver from source at that commit. `.upstream/` (gitignored) is a clone of `microsoft/playwright` at that commit. Read the upstream code there. Do not edit, commit or switch branches in `.upstream/`. -## Determining what to port +A roll moves `scripts/DRIVER_VERSION` to a newer commit and ports the changes between the two commits. A roll does not use the published npm packages or their versions. -List the upstream commits that touched a client-relevant path since the previous pin. The paths cover everything that can change the public Java surface or the wire protocol: +## 1. Roll -- `docs/src/api/` — the source of truth for `api.json`. Method/option additions, removals, and `langs:` filter changes flow from here. -- `packages/playwright-core/src/client/` — the JS client implementation that the Java client mirrors. -- `packages/isomorphic/` — selector engines, locator generation/parsing, and aria-snapshot logic shared between client and server. Changes here can affect client-side helpers like `getByRoleSelector`. -- `packages/playwright/src/matchers/matchers.ts` — assertion-method definitions. Changes here usually correspond to new options on `LocatorAssertions` / `PageAssertions`. -- `packages/protocol/spec/` — the wire protocol schema (one `*.yml` file per area). Method/event additions, parameter renames, and result-shape changes affect what the Java `*Impl` classes need to send/receive. +```bash +./scripts/roll_driver.sh # the tip of upstream main +./scripts/roll_driver.sh release-1.X # the tip of an upstream release branch +./scripts/roll_driver.sh # an exact commit (40 hex digits) +``` + +Use the target that the user gives. If the user gives no target, roll `main` to upstream `main`, and roll a `release-1.X` branch of this repository to upstream `release-1.X`. + +The script writes the commit to `scripts/DRIVER_VERSION`, rolls Node.js, builds the driver from `.upstream/`, generates the API and updates the README. Then get the two commits: ```bash old=$(git show HEAD:scripts/DRIVER_VERSION) new=$(cat scripts/DRIVER_VERSION) -git -C .upstream log "$old..$new" --oneline -- \ +``` + +## 2. Find the changes to port + +List the upstream commits between the two commits that changed a path the Java client depends on: + +- `docs/src/api/` — the source of `api.json`. A new or removed method or option, or a changed `langs:` filter, comes from here. +- `packages/playwright-core/src/client/` — the JS client. The Java client is a port of it. +- `packages/isomorphic/` — selector engines, locator generation and parsing, and the aria snapshot code. The client and the server share this code. A change here can change client helpers such as `getByRoleSelector`. +- `packages/playwright/src/matchers/matchers.ts` — the assertion methods. A change here is usually a new option of `LocatorAssertions` or `PageAssertions`. +- `packages/protocol/spec/` — the wire protocol, one `*.yml` file for each area. A new method or event, a renamed parameter or a changed result changes the messages that the Java `*Impl` classes send and receive. + +```bash +git -C .upstream log "$old..$new" --oneline --reverse -- \ 'docs/src/api/' \ 'packages/playwright-core/src/client/' \ 'packages/isomorphic/' \ @@ -32,26 +47,32 @@ git -C .upstream log "$old..$new" --oneline -- \ 'packages/protocol/spec/' ``` -Walk that list top-to-bottom (oldest-first is easier — newest is at top, so reverse). For each commit: -1. Read the commit (`git -C .upstream show `) to see what client/protocol/docs changed. -2. If it's JS-internal (bundling, dispatcher conventions, electron, mcp, dashboard, trace-viewer, test-runner) — skip. -3. If it touches `docs/src/api/` or types, check `langs:` annotations — features marked `langs: js`/`langs: js, python` don't apply to Java. -4. If it adds/changes a public API method or option that applies to Java, port it. The api.json regenerated by `roll_driver.sh` already contains the new types/options, so the generated Java interfaces usually pick them up automatically — what's typically missing is the `*Impl` wiring. -5. Watch for follow-up reverts — a "feat: X" commit might be undone by a later "Revert X". Check whether the change still exists in HEAD before porting. -6. Maintain a running notes file (e.g. `/tmp/roll-notes.md`) listing each upstream PR as ported / skipped / verified-already-supported, with a one-line reason. This file becomes the body of the eventual PR. +The list starts with the oldest commit. Do these steps for each commit: + +1. Read the commit: `git -C .upstream show `. +2. If the change is internal to JS (bundling, dispatchers, electron, mcp, dashboard, trace viewer, test runner), skip it. +3. If the commit changes `docs/src/api/` or types, read the `langs:` annotations. A feature with `langs: js` or `langs: js, python` does not apply to Java. +4. If the commit adds or changes a public method or option that applies to Java, port it. `roll_driver.sh` already generated the new types and options in the Java interfaces. Usually only the `*Impl` code is missing. +5. Make sure that a later commit did not revert the change. Look at the code at `$new` before you port. +6. Keep notes in a file (for example `/tmp/roll-notes.md`). For each upstream PR, write one line: ported, skipped or already supported, with the reason. The PR description comes from this file. + +## 3. The roll PR + +The PR contains: -## What to include in the rolling PR +- the new commit in `scripts/DRIVER_VERSION`, and the new `scripts/NODE_VERSION` if Node.js changed; +- the generated interfaces from `roll_driver.sh`; +- the `*Impl` code for each ported feature, the same as the upstream JS client (`.upstream/packages/playwright-core/src/client`); +- changes to the generator (import lists, special cases) if there are new types; +- one small test for each new public API: a listener for a new event, a call for a new method, a regression test for a changed return type. -- Driver commit bump in `scripts/DRIVER_VERSION` -- Generated interface diffs from `roll_driver.sh` -- `*Impl` wiring for each ported feature -- Generator updates (import lists, special-cases) if new types appeared -- A small test per new public API surface — listener for new events, basic call for new methods, regression for changed return types -- PR description: list each upstream PR ported, each skipped (with reason), and each verified-already-supported +Title: `chore(driver): roll to ()`. `` is the version that the driver reports. Read it from the source, not from npm: -Rolling includes: -- updating client implementation to match changes in the upstream JS implementation (see .upstream/packages/playwright-core/src/client) -- adding a couple of new tests to verify new/changed functionality +```bash +node -p "require('./.upstream/packages/playwright-core/package.json').version" # for example 1.67.0-next +``` + +Description: list each upstream PR that you ported, each PR that you skipped (with the reason), and each PR that Java already supported. ## Mimicking the JavaScript implementation @@ -138,18 +159,20 @@ Common patterns: **Protocol parameter renames** — protocol parameter names can change between versions (e.g. `wsEndpoint` → `endpoint` in `BrowserType.connect`). When a test fails with `expected string, got undefined` or similar validation errors from the driver, check `packages/protocol/spec/*.yml` for the current parameter names and update the corresponding `params.addProperty(...)` call in the Impl class. Also check the JS client (`src/client/`) to see how it builds the params object. -## Rebuilding the driver-bundle after a roll +## Rebuilding the driver modules after a roll -`./scripts/roll_driver.sh` does the whole roll pipeline end-to-end: moves `DRIVER_VERSION` to the new commit, builds the driver from `.upstream/` into `driver/src/main/resources/driver/package/` and `driver-bundle/src/main/resources/driver//`, regenerates `api.json` and the Java interfaces, and updates the README. When all of that succeeds, the next `mvn` invocation that touches `driver-bundle` will pick up the new files and you don't need to think about it. +`./scripts/roll_driver.sh` does the full roll. It moves `scripts/DRIVER_VERSION` to the new commit. It builds the driver from `.upstream/` into `driver/src/main/resources/driver/package/` and `driver-bundle/src/main/resources/driver//`. It generates `api.json` and the Java interfaces, and it updates the README. If all steps pass, the next `mvn` command uses the new driver. -But if any step in the pipeline fails (the very common case is the API generator throwing on a new type — see *Fixing generator and compilation errors*), the run aborts before `driver-bundle/target/classes/` has been refreshed. From that point on, until you manually rebuild `driver` and `driver-bundle`, the test JVM will load the **old** driver from the cached `target/classes`/installed jar even though the source resources have already been swapped to the new version. +If a step fails, the script stops before Maven installs the new driver. The most frequent cause is the API generator, which fails on a new type (see *Fixing generator and compilation errors*). After that, the test JVM loads the **old** driver from `target/classes` or from the installed jar, although the source resources already hold the new driver. -Fix — rebuild both once before re-running tests: +To correct this, install the two driver modules one time before you run the tests again: ``` mvn -f driver/pom.xml install -DskipTests mvn -f driver-bundle/pom.xml install -DskipTests ``` +If `scripts/generate_api.sh` prints `.upstream/ is not at ...`, run `scripts/build_driver.sh`. + ## Porting and verifying tests **Before porting an upstream test file, check the API exists in Java.** The upstream repo may have test files for brand-new APIs that haven't been added to the Java interface yet (e.g., `screencast.spec.ts` tests `page.screencast` which may not be in the generated `Page.java`). Check `git diff main --name-only` to see what interfaces were added this roll, and verify the method exists in the generated Java interface before porting. diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 7d9ade745..24c949cc5 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -60,7 +60,7 @@ jobs: - name: Copy repository inside docker container run: | - # The driver is built already; the microsoft/playwright checkout it was built from is large. + # The container does not need .upstream/, and it is large. rm -rf .upstream docker cp . "$CONTAINER_ID":/home/pwuser/playwright # build.sh installed the SNAPSHOT artifacts into the local Maven repository diff --git a/.gitignore b/.gitignore index 5a150e817..80cb47576 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,5 @@ target/ .npmrc -# The microsoft/playwright checkout that the driver is built from (scripts/build_driver.sh). +# The microsoft/playwright checkout. scripts/build_driver.sh builds the driver from it. .upstream/ diff --git a/AGENTS.md b/AGENTS.md index 33477eca1..21dbae869 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ Paths such as `~/code/playwright` in this file assume that you check the repos o ## How this repo depends on Playwright -- **The driver.** The Java client talks to the Node.js driver, the `playwright-core` package of `microsoft/playwright`, built from source at the commit in `scripts/DRIVER_VERSION`. `scripts/build_driver.sh` clones `microsoft/playwright` into `.upstream/` (gitignored), checks that commit out, builds it and unpacks the package into `driver/src/main/resources/driver/package/`. Do not edit, commit or switch branches in `.upstream/`. `git show v1.X.0:scripts/DRIVER_VERSION` prints the upstream commit of a release, or, for releases up to 1.65, the `playwright-core` version of its driver. +- **The driver.** The Java client talks to the Node.js driver. The driver is the `playwright-core` package of `microsoft/playwright`. We build it from source at the commit in `scripts/DRIVER_VERSION`. `scripts/build_driver.sh` clones `microsoft/playwright` into `.upstream/` (gitignored), checks out that commit, builds it and puts the package into `driver/src/main/resources/driver/package/`. Do not edit, commit or switch branches in `.upstream/`. `scripts/roll_driver.sh` moves the commit: to the tip of upstream `main`, to the tip of an upstream `release-1.X` branch, or to an exact commit. We do not use the published npm packages or their versions. `git show v1.X.0:scripts/DRIVER_VERSION` prints the upstream commit of a release. For releases up to 1.65, it prints the `playwright-core` version of the driver. - **Upstream code.** In `.upstream/`, at the commit of the driver, or in `~/code/playwright`, which may be ahead of it: the client in `packages/playwright-core/src/client/`, the API docs in `docs/src/api/`, the tests in `tests/page/` and `tests/library/`. Its `AGENTS.md` says how to build it and run a test. - **Where a bug is.** When the same calls fail in a Node.js test upstream too, the cause is in the driver or a browser, and the fix lands in `microsoft/playwright`. When Node.js passes, the bug is in the Java client: compare the `*Impl.java` with its JavaScript counterpart, and fix it here. - **The generated API.** `scripts/generate_api.sh` runs `utils/doclint/generateApiJson.js` of `.upstream/`, and `tools/api-generator` writes every interface and options class in `playwright/src/main/java/com/microsoft/playwright/`, `options/` and `assertions/`. Only `CLI.java`, `PlaywrightException.java`, `TimeoutError.java`, `assertions/PlaywrightAssertions.java` and the `package-info.java` files there are written by hand. Never edit a generated file: the next roll reverts it. A missing method or option is a change to `docs/src/api/` upstream. @@ -77,6 +77,6 @@ Branch naming for issue fixes: `fix-`. ## Skills -- **playwright-roll** (`.claude/skills/playwright-roll/SKILL.md`) — roll Playwright Java to a new upstream version: bump the driver, regenerate the API, and port relevant upstream changes. +- **playwright-roll** (`.claude/skills/playwright-roll/SKILL.md`) — roll Playwright Java to a new upstream commit: move `scripts/DRIVER_VERSION`, build the driver, regenerate the API, and port relevant upstream changes. - **playwright-java-release** (`.claude/skills/playwright-java-release/SKILL.md`) — prepare a release after the rolling PR merges: cut the release branch, mark the Maven version, and draft the GitHub release. - **playwright-cherry-pick** (upstream, `~/code/playwright/.claude/skills/playwright-cherry-pick/SKILL.md`) — cherry-pick a merged PR into a `release-1.X` branch as `cherry-pick(#): `. Use the same rules for this repo's release branches. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 627f93e93..85b707fce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,13 +104,13 @@ Public Java API is generated from api.json, which is generated from `.upstream/` #### Updating driver version -To roll the driver to a branch (`main`, `release-1.66`), a tag (`v1.66.0`) or a commit of `microsoft/playwright` run the following command; the default is the tip of `main`: +The driver does not depend on a published Playwright version. To roll the driver to a newer commit of `microsoft/playwright`, run the following command: ```bash -scripts/roll_driver.sh [ref] +scripts/roll_driver.sh [main|release-1.|] ``` -It pins the commit in `scripts/DRIVER_VERSION`, builds the driver from it and regenerates the API. The driver reports the version of `packages/playwright-core/package.json` at that commit: `1.66.0` on a release tag, `1.67.0-next` on `main`. +`main` (the default) is the tip of upstream `main`, `release-1.` is the tip of that upstream release branch, and `` is a full commit hash. The script writes the commit to `scripts/DRIVER_VERSION`, builds the driver from it and regenerates the API. The driver reports the version of `packages/playwright-core/package.json` at that commit: `1.67.0-next` on `main`, `1.66.0` on `release-1.66`. ### Code Style diff --git a/ROLLING.md b/ROLLING.md index 7fb64c37d..8407d21b7 100644 --- a/ROLLING.md +++ b/ROLLING.md @@ -2,7 +2,7 @@ * make sure to have at least Java 8 and Maven 3.6.3, git, and Node.js with npm * clone playwright for java: http://github.com/microsoft/playwright-java -* roll the driver and update generated sources: `./scripts/roll_driver.sh `, where `` is a branch (`main`, the default, or `release-1.66`), a tag (`v1.66.0`) or a commit of `microsoft/playwright`. It pins the commit in `scripts/DRIVER_VERSION`, checks it out in `.upstream/` (a gitignored clone of `microsoft/playwright`) and builds the driver from it +* roll the driver and update generated sources: `./scripts/roll_driver.sh [main|release-1.|]`. It rolls to the tip of upstream `main` (the default), to the tip of an upstream release branch, or to an exact commit of `microsoft/playwright`. It writes the commit to `scripts/DRIVER_VERSION`, checks it out in `.upstream/` (a gitignored clone of `microsoft/playwright`) and builds the driver from it * list the upstream commits to port: `git -C .upstream log --oneline --reverse $(git show HEAD:scripts/DRIVER_VERSION)..$(cat scripts/DRIVER_VERSION)` * fix any errors * commit & send PR with the roll diff --git a/scripts/build_driver.sh b/scripts/build_driver.sh index f989d8e52..b2b54f2a4 100755 --- a/scripts/build_driver.sh +++ b/scripts/build_driver.sh @@ -8,15 +8,17 @@ cd "$(dirname $0)" if [[ ($1 == '-h') || ($1 == '--help') ]]; then echo "" - echo "This script builds the Playwright driver from source and assembles it for all platforms." - echo "It clones microsoft/playwright into '.upstream/' (gitignored), checks out the commit" - echo "pinned in scripts/DRIVER_VERSION and builds the 'playwright-core' npm package from it." - echo "The platform-independent package is assembled once into the driver module" - echo "('driver/src/main/resources/driver/package'), and the Node.js binary from" - echo "https://nodejs.org (version pinned in scripts/NODE_VERSION) for each platform goes" - echo "into the driver-bundle module ('driver-bundle/src/main/resources/driver/')." + echo "This script builds the Playwright driver from source for all platforms." echo "" - echo "Requires git and Node.js with npm." + echo "1. It clones microsoft/playwright into '.upstream/' (gitignored)." + echo "2. It checks out the commit in scripts/DRIVER_VERSION." + echo "3. It builds the 'playwright-core' package and puts it into the driver module" + echo " ('driver/src/main/resources/driver/package'). All platforms use this package." + echo "4. It downloads the Node.js binary of each platform from https://nodejs.org and puts" + echo " it into the driver-bundle module ('driver-bundle/src/main/resources/driver/')." + echo " scripts/NODE_VERSION holds the Node.js version." + echo "" + echo "The script needs git and Node.js with npm." echo "" echo "Usage: scripts/build_driver.sh [option]" echo "" @@ -43,21 +45,21 @@ ROOT="$(cd .. && pwd)" UPSTREAM_URL="https://github.com/microsoft/playwright.git" UPSTREAM_DIR="$ROOT/.upstream" -# scripts/DRIVER_VERSION pins the microsoft/playwright commit. scripts/roll_driver.sh updates it. +# scripts/DRIVER_VERSION holds the microsoft/playwright commit. scripts/roll_driver.sh updates it. DRIVER_VERSION=$(head -1 ./DRIVER_VERSION) if [[ ! "$DRIVER_VERSION" =~ ^[0-9a-f]{40}$ ]]; then echo "scripts/DRIVER_VERSION must hold one microsoft/playwright commit (40 hex digits), got '$DRIVER_VERSION'" exit 1 fi -# scripts/NODE_VERSION pins the exact Node.js version. scripts/roll_node.sh updates it. +# scripts/NODE_VERSION holds the exact Node.js version. scripts/roll_node.sh updates it. NODE_VERSION=$(head -1 ./NODE_VERSION) echo "Driver commit: $DRIVER_VERSION" echo "Node.js version: $NODE_VERSION" -# npm uses the registry and the credentials of a root-level .npmrc when there is one (e.g. -# the one the release pipeline writes to point at the internal Azure Artifacts feed). -# Locally, NPM_CONFIG_REGISTRY= can be used to the same effect. +# Runs npm in a directory. If the repository root has an .npmrc file, npm uses its registry +# and its credentials. The release pipeline writes this file to use the internal Azure +# Artifacts feed. On your computer, set NPM_CONFIG_REGISTRY= to use a different registry. npm_in() { local dir=$1 shift @@ -76,11 +78,12 @@ upstream_has_local_changes() { TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT -# 1. .upstream/ at the commit in scripts/DRIVER_VERSION. +# 1. Check out the commit of scripts/DRIVER_VERSION in .upstream/. CLONED="" if [[ ! -e "$UPSTREAM_DIR/.git" ]]; then echo "Cloning $UPSTREAM_URL into $UPSTREAM_DIR" - # The whole history, for listing the changes of a roll; file contents are fetched on demand. + # The clone has the full history, which a roll uses to list the upstream changes. + # Git downloads the file contents only when it needs them. git clone --quiet --filter=blob:none --no-checkout "$UPSTREAM_URL" "$UPSTREAM_DIR" CLONED=1 fi @@ -91,7 +94,7 @@ if [[ -n "$CLONED" || "$(git -C "$UPSTREAM_DIR" rev-parse HEAD)" != "$DRIVER_VER fi if ! git -C "$UPSTREAM_DIR" cat-file -e "$DRIVER_VERSION^{commit}" 2> /dev/null; then git -C "$UPSTREAM_DIR" fetch --quiet --tags origin - # A commit that no branch or tag reaches any more, for example on a deleted branch. + # If the commit is not on a branch or a tag, fetch it by its hash. git -C "$UPSTREAM_DIR" cat-file -e "$DRIVER_VERSION^{commit}" 2> /dev/null \ || git -C "$UPSTREAM_DIR" fetch --quiet origin "$DRIVER_VERSION" fi @@ -99,13 +102,13 @@ if [[ -n "$CLONED" || "$(git -C "$UPSTREAM_DIR" rev-parse HEAD)" != "$DRIVER_VER fi echo "$UPSTREAM_DIR is at $DRIVER_VERSION" -# 2. Build it, once per commit. +# 2. Build .upstream/. Do this only one time for each commit. if upstream_has_local_changes; then - echo "$UPSTREAM_DIR has local changes. The driver is pinned to a commit, so build it from a clean checkout." + echo "$UPSTREAM_DIR has local changes. Discard them: the driver must come from the commit in scripts/DRIVER_VERSION." exit 1 fi UPSTREAM_CORE_DIR="$UPSTREAM_DIR/packages/playwright-core" -# npm ci removes node_modules, and the stamp with it. +# The stamp file holds the commit of the last build. `npm ci` deletes node_modules and the stamp. STAMP="$UPSTREAM_DIR/node_modules/.playwright-java-build" if [[ "$(cat "$STAMP" 2> /dev/null)" != "$DRIVER_VERSION" || ! -d "$UPSTREAM_CORE_DIR/lib" ]]; then npm_in "$UPSTREAM_DIR" ci --no-audit --no-fund @@ -113,24 +116,24 @@ if [[ "$(cat "$STAMP" 2> /dev/null)" != "$DRIVER_VERSION" || ! -d "$UPSTREAM_COR echo "$DRIVER_VERSION" > "$STAMP" fi -# The platform-independent driver code (playwright-core) is assembled once into the driver module; -# the Node.js binary for each platform is assembled into the driver-bundle module. See issue #1196. +# The playwright-core package is the same on all platforms. It goes into the driver module. +# The Node.js binary of each platform goes into the driver-bundle module. See issue #1196. CORE_DEST="$ROOT/driver/src/main/resources/driver" NODE_DEST="$ROOT/driver-bundle/src/main/resources/driver" -# 3. playwright-core package -> driver module (once, shared by every platform). +# 3. Put the playwright-core package into the driver module. echo "Assembling playwright-core package to $CORE_DEST/package" npm_in "$UPSTREAM_CORE_DIR" pack --pack-destination "$TMP_DIR" --silent > /dev/null CORE_TGZ=$(ls "$TMP_DIR"/playwright-core-*.tgz) rm -rf "$CORE_DEST/package" mkdir -p "$CORE_DEST" -# The npm tarball has a top-level package/ directory, so this creates $CORE_DEST/package. +# The npm tarball has a top-level package/ directory. This command creates $CORE_DEST/package. tar -xzf "$CORE_TGZ" -C "$CORE_DEST" rm -f "$CORE_TGZ" -# Upstream copies these into the package before it publishes it (LICENCE_FILES in utils/workspace.js). +# The upstream release copies these files into the package (LICENCE_FILES in utils/workspace.js). cp "$UPSTREAM_DIR/NOTICE" "$UPSTREAM_DIR/LICENSE" "$CORE_DEST/package/" -# 4. Node.js binary for each platform -> driver-bundle module. +# 4. Put the Node.js binary of each platform into the driver-bundle module. # :: for ENTRY in \ "mac:darwin-x64:tar.gz" \ @@ -145,7 +148,7 @@ do rm -rf "$DEST" mkdir -p "$DEST" - # Node.js binary and its license from the official Node.js distribution. + # Download the Node.js binary and its license from the official Node.js distribution. NODE_DIR="node-v$NODE_VERSION-$NODE_SUFFIX" NODE_ARCHIVE="$TMP_DIR/$NODE_DIR.$ARCHIVE" download "https://nodejs.org/dist/v$NODE_VERSION/$NODE_DIR.$ARCHIVE" "$NODE_ARCHIVE" @@ -161,5 +164,5 @@ done UPSTREAM_VERSION=$(cd "$UPSTREAM_CORE_DIR" && node -p "require('./package.json').version") echo "" -echo "The driver has been built from microsoft/playwright $DRIVER_VERSION; it reports version $UPSTREAM_VERSION." +echo "Built the driver from microsoft/playwright $DRIVER_VERSION. The driver reports version $UPSTREAM_VERSION." echo "" diff --git a/scripts/generate_api.sh b/scripts/generate_api.sh index 44ff6ca8b..a0f938348 100755 --- a/scripts/generate_api.sh +++ b/scripts/generate_api.sh @@ -8,10 +8,11 @@ cd "$(dirname "$0")/.." DRIVER_VERSION=$(head -1 ./scripts/DRIVER_VERSION) -# api.json is generated from .upstream/, the microsoft/playwright checkout at the commit in -# scripts/DRIVER_VERSION that the driver is built from (scripts/build_driver.sh). PW_SRC_DIR -# generates it from another checkout, to try a change to the docs or to the generator. The -# committed files must come from .upstream/: CI generates them again and fails when they differ. +# The script generates api.json from .upstream/. This is the microsoft/playwright checkout +# at the commit in scripts/DRIVER_VERSION. scripts/build_driver.sh makes it. +# To try a change to the upstream docs or to the generator, set PW_SRC_DIR to a different +# checkout. Do not commit files that come from PW_SRC_DIR: CI generates the files again +# from .upstream/ and fails if they are different. if [[ -n "$PW_SRC_DIR" ]]; then UPSTREAM_DIR="$PW_SRC_DIR" echo "Generating from $UPSTREAM_DIR (PW_SRC_DIR), not from .upstream/" diff --git a/scripts/roll_driver.sh b/scripts/roll_driver.sh index 8d4e404e1..23022b61f 100755 --- a/scripts/roll_driver.sh +++ b/scripts/roll_driver.sh @@ -6,60 +6,54 @@ set +x trap "cd $(pwd -P)" EXIT cd "$(dirname $0)" -if [[ "$#" -gt 1 || ($1 == '-h') || ($1 == '--help') ]]; then +usage() { + echo "" + echo "Rolls the driver to a commit of microsoft/playwright." + echo "" + echo "Usage: scripts/roll_driver.sh [main|release-1.|]" echo "" - echo "Rolls the driver to a microsoft/playwright branch (main, release-1.66), tag (v1.66.0)" - echo "or commit: pins its commit in scripts/DRIVER_VERSION, rolls Node.js, builds the driver" - echo "from source and regenerates the API. The default is the tip of main." + echo " main the tip of the main branch (default)" + echo " release-1. the tip of a release branch, for example release-1.66" + echo " a full commit hash (40 hex digits)" echo "" - echo "Usage: scripts/roll_driver.sh []" + echo "The script writes the commit to scripts/DRIVER_VERSION, rolls Node.js, builds the" + echo "driver from source and generates the API." echo "" +} + +if [[ "$#" -gt 1 || ($1 == '-h') || ($1 == '--help') ]]; then + usage exit 1 fi UPSTREAM_URL="https://github.com/microsoft/playwright.git" REF=${1:-main} if [[ "$REF" =~ ^[0-9a-f]{40}$ ]]; then - NEW_VERSION=$REF -else - # "^{}" is the commit that an annotated tag points to. - REFS=$(git ls-remote "$UPSTREAM_URL" "refs/tags/$REF^{}" "refs/tags/$REF" "refs/heads/$REF") - NEW_VERSION="" - for NAME in "refs/tags/$REF^{}" "refs/tags/$REF" "refs/heads/$REF"; do - NEW_VERSION=$(echo "$REFS" | awk -v name="$NAME" '$2 == name { print $1 }') - if [[ -n "$NEW_VERSION" ]]; then - break - fi - done - if [[ -z "$NEW_VERSION" ]]; then - echo "$REF is not a branch, a tag or a full commit of $UPSTREAM_URL" + NEW_COMMIT=$REF +elif [[ "$REF" == "main" || "$REF" =~ ^release-1\.[0-9]+$ ]]; then + NEW_COMMIT=$(git ls-remote "$UPSTREAM_URL" "refs/heads/$REF" | cut -f1) + if [[ -z "$NEW_COMMIT" ]]; then + echo "$UPSTREAM_URL has no branch $REF" exit 1 fi +else + echo "Unknown ref: $REF" + usage + exit 1 fi -CURRENT_VERSION=$(head -1 ./DRIVER_VERSION) -echo "Rolling driver from $CURRENT_VERSION to $NEW_VERSION" +OLD_COMMIT=$(head -1 ./DRIVER_VERSION) +echo "Rolling the driver from $OLD_COMMIT to $NEW_COMMIT" -echo $NEW_VERSION > ./DRIVER_VERSION -# Each roll also moves the driver to the latest Node.js release of the pinned major version. +echo $NEW_COMMIT > ./DRIVER_VERSION +# Each roll also moves Node.js to the latest release of the pinned major version. ./roll_node.sh ./build_driver.sh ./generate_api.sh ./update_readme.sh -# The version that the driver reports: 1.66.0 on a release tag, 1.67.0-next on main. -PACKAGE_VERSION=$(node -p "require('../.upstream/packages/playwright-core/package.json').version") -node -e "$(cat < parseInt(part, 10)); - const exampleVersion = majorVersion + '.' + minorVersion + '.0'; - fs.writeFileSync('../examples/pom.xml', fs.readFileSync('../examples/pom.xml', 'utf8') - .replace(/.*<\/playwright\.version>/, '' + exampleVersion + '') - ); -EOF2 -)" $PACKAGE_VERSION - echo "" -echo "Rolled to microsoft/playwright $NEW_VERSION; the driver reports version $PACKAGE_VERSION." -echo "The upstream commits since the previous pin:" -echo " git -C .upstream log --oneline --reverse $CURRENT_VERSION..$NEW_VERSION" +echo "Rolled the driver from $OLD_COMMIT to $NEW_COMMIT." +echo "To list the upstream commits of the roll, run:" +echo " git -C .upstream log --oneline --reverse $OLD_COMMIT..$NEW_COMMIT" echo "" diff --git a/utils/docker/build.sh b/utils/docker/build.sh index b00b5d603..ca8a0f809 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -10,7 +10,7 @@ if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then echo "" echo " docker run --rm -it playwright:localbuild-noble /bin/bash" echo "" - echo "NOTE: this requires git, a JDK, Maven and Node.js with npm on the host: the driver and the client are built here" + echo "NOTE: the host must have git, a JDK, Maven and Node.js with npm: the script builds the driver and the client here" echo "and the image only runs it to install the browsers." echo "" exit 0