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