-
Notifications
You must be signed in to change notification settings - Fork 1.2k
devops: Build driver from source #3092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Skn0tt
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Skn0tt:skn0tt/build-driver-from-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 87bb9ddbd78f329df18c2b24847bc9409240cd07 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) Microsoft Corporation. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Build the Playwright driver bundles from upstream source. | ||
| # | ||
| # This script checks out microsoft/playwright at the commit pinned in the | ||
| # DRIVER_SHA file (repo root) and runs upstream's | ||
| # utils/build/build-playwright-driver.sh. That script cross-builds the | ||
| # per-platform bundles, which this script stages into driver/ as | ||
| # playwright-<sha>-<suffix>.zip for setup.py to embed into the platform wheels. | ||
| # | ||
| # The pin is an immutable commit SHA (tags can be moved upstream) and lives in | ||
| # the neutral DRIVER_SHA file so setup.py and CI can read it without parsing | ||
| # this script. The SHA is baked into the staged bundle filenames, so the | ||
| # filename doubles as the build cache key: a roll changes DRIVER_SHA, which | ||
| # changes the filenames and invalidates the cache. | ||
| # | ||
| # A single host builds all platform bundles at once: the upstream script | ||
| # downloads the matching Node.js binary for each target, so the host platform | ||
| # does not constrain which bundles can be produced. | ||
| # | ||
| # This is intentionally a shell script (rather than language-specific code) so | ||
| # the same build step can be shared across the Playwright language forks. | ||
| # | ||
| # Usage: scripts/build_driver.sh (reads the pin from DRIVER_SHA; no arguments) | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| DRIVER_DIR="$REPO_ROOT/driver" | ||
| SOURCE_DIR="$DRIVER_DIR/playwright-src" | ||
| PLAYWRIGHT_REPO="https://github.com/microsoft/playwright" | ||
|
|
||
| # The driver pin: an immutable commit in microsoft/playwright. | ||
| # microsoft/playwright @ v1.60.0 | ||
| EXPECTED_SHA="$(tr -d '[:space:]' < "$REPO_ROOT/DRIVER_SHA")" | ||
| if [[ -z "$EXPECTED_SHA" ]]; then | ||
| echo "DRIVER_SHA is empty or missing at $REPO_ROOT/DRIVER_SHA" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| # Bundle suffixes produced by utils/build/build-playwright-driver.sh. Keep in | ||
| # sync with the "zip_name" values in setup.py. | ||
| SUFFIXES=(mac mac-arm64 linux linux-arm64 win32_x64 win32_arm64) | ||
|
|
||
| bundles_present() { | ||
| local suffix | ||
| for suffix in "${SUFFIXES[@]}"; do | ||
| [[ -f "$DRIVER_DIR/playwright-$EXPECTED_SHA-$suffix.zip" ]] || return 1 | ||
| done | ||
| return 0 | ||
| } | ||
|
|
||
| require_tools() { | ||
| local missing=() | ||
| local tool | ||
| for tool in git node npm bash; do | ||
| if ! command -v "$tool" >/dev/null 2>&1; then | ||
| missing+=("$tool") | ||
| fi | ||
| done | ||
| if [[ ${#missing[@]} -gt 0 ]]; then | ||
| echo "Building the Playwright driver from source requires the following tools," >&2 | ||
| echo "which were not found on PATH: ${missing[*]}." >&2 | ||
| echo "Install Node.js (with npm), git and bash, then retry. On Windows, run the" >&2 | ||
| echo "build from a bash shell (e.g. Git Bash)." >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| checked_out_sha() { | ||
| if [[ -d "$SOURCE_DIR/.git" ]]; then | ||
| git -C "$SOURCE_DIR" rev-parse HEAD 2>/dev/null || true | ||
| fi | ||
| } | ||
|
|
||
| clone_source() { | ||
| # Reuse an existing checkout only if it already points at exactly the pinned | ||
| # commit; otherwise wipe it so a stale ref can never leak into the bundles. | ||
| if [[ -d "$SOURCE_DIR" ]]; then | ||
| [[ "$(checked_out_sha)" == "$EXPECTED_SHA" ]] || rm -rf "$SOURCE_DIR" | ||
| fi | ||
| if [[ ! -d "$SOURCE_DIR" ]]; then | ||
| mkdir -p "$SOURCE_DIR" | ||
| echo "Fetching $PLAYWRIGHT_REPO at $EXPECTED_SHA" | ||
| # Shallow-fetch a single commit. GitHub allows fetching an arbitrary commit | ||
| # by SHA, so a full clone is unnecessary. | ||
| git -C "$SOURCE_DIR" init -q | ||
| git -C "$SOURCE_DIR" remote add origin "$PLAYWRIGHT_REPO" | ||
| git -C "$SOURCE_DIR" fetch --depth 1 origin "$EXPECTED_SHA" | ||
| git -C "$SOURCE_DIR" checkout -q FETCH_HEAD | ||
| fi | ||
| # Make sure we landed on exactly the pinned commit. | ||
| if [[ "$(checked_out_sha)" != "$EXPECTED_SHA" ]]; then | ||
| echo "Checked out commit '$(checked_out_sha)' but '$EXPECTED_SHA' was requested." >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| build_source() { | ||
| echo "Installing Playwright dependencies (npm ci)" | ||
| (cd "$SOURCE_DIR" && npm ci) | ||
| echo "Building Playwright (npm run build)" | ||
| (cd "$SOURCE_DIR" && npm run build) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend |
||
| echo "Building driver bundles" | ||
| (cd "$SOURCE_DIR" && bash utils/build/build-playwright-driver.sh) | ||
| } | ||
|
|
||
| copy_bundles() { | ||
| local output_dir="$SOURCE_DIR/utils/build/output" | ||
| # The output dir also holds build intermediates (downloaded Node.js binaries, | ||
| # tgz archives, extracted package dirs), so copy only the bundles. Upstream | ||
| # names them playwright-<version>-<suffix>.zip; restage each one with the pin | ||
| # SHA in the name so the filename doubles as the build cache key. | ||
| local suffix matches | ||
| for suffix in "${SUFFIXES[@]}"; do | ||
| matches=("$output_dir"/playwright-*-"$suffix".zip) | ||
| if [[ ! -f "${matches[0]}" ]]; then | ||
| echo "Expected driver bundle for '$suffix' was not produced in $output_dir" >&2 | ||
| exit 1 | ||
| fi | ||
| cp "${matches[0]}" "$DRIVER_DIR/playwright-$EXPECTED_SHA-$suffix.zip" | ||
| done | ||
| } | ||
|
|
||
| # Fast path: the bundles for this exact pin are already staged, so there is | ||
| # nothing to (re)build. This keeps repeat invocations cheap and lets consumers | ||
| # that only downloaded the prebuilt bundles skip the build entirely (no Node). | ||
| if bundles_present; then | ||
| echo "Driver bundles for $EXPECTED_SHA already present in $DRIVER_DIR; skipping build." | ||
| exit 0 | ||
| fi | ||
|
|
||
| require_tools | ||
| clone_source | ||
| build_source | ||
| copy_bundles | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure why wipe the repo, instead of fetch/checkout the desired commit?