1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl gnused nix-prefetch common-updater-scripts node2nix jq
3set -euo pipefail
4
5root="$(dirname "$(readlink -f "$0")")"
6driver_file="$root/../../web/playwright/driver.nix"
7playwright_test="$root/../../web/playwright-test"
8
9version=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s https://api.github.com/repos/microsoft/playwright-python/releases/latest | jq -r '.tag_name | sub("^v"; "")')
10
11# Most of the time, this should be the latest stable release of the Node-based
12# Playwright version, but that isn't a guarantee, so this needs to be specified
13# as well:
14setup_py_url="https://github.com/microsoft/playwright-python/raw/v${version}/setup.py"
15driver_version=$(curl -Ls "$setup_py_url" | grep '^driver_version =' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
16
17fetch_driver_arch() {
18 nix-prefetch-url "https://playwright.azureedge.net/builds/driver/playwright-${driver_version}-${1}.zip"
19}
20
21replace_sha() {
22 sed -i "s|$1 = \".\{44,52\}\"|$1 = \"$2\"|" "$driver_file"
23}
24
25# Replace SHAs for the driver downloads
26replace_sha "x86_64-linux" "$(fetch_driver_arch "linux")"
27replace_sha "x86_64-darwin" "$(fetch_driver_arch "mac")"
28replace_sha "aarch64-linux" "$(fetch_driver_arch "linux-arm64")"
29replace_sha "aarch64-darwin" "$(fetch_driver_arch "mac-arm64")"
30
31# Update the version stamps
32sed -i "s/version =\s*\"[^\$]*\"/version = \"$driver_version\"/" "$driver_file"
33sed -i "s/\"@playwright\/test\": \"[^\$]*\"/\"@playwright\/test\": \"$driver_version\"/" "$playwright_test/node-packages.json"
34(cd "$playwright_test"; node2nix -i node-packages.json)
35update-source-version playwright "$version" --rev="v$version"