#! /usr/bin/make -f

export DEB_BUILD_OPTIONS=nocheck
export DH_VERBOSE=1
export PYBUILD_NAME=playwright
PW_VERSION=1.60.0

# PW_DRIVER_VERSION can be found in the upstream playwright-python `setup.py`
# https://github.com/microsoft/playwright-python/blob/665af8dbe9f188c1dd5d1913d16e4d709a0dd9cc/setup.py#L33
PW_DRIVER_VERSION=1.60.0
# sha256 of playwright-${PW_DRIVER_VERSION}-linux.zip from cdn.playwright.dev.
# Update this whenever PW_DRIVER_VERSION changes.
PW_DRIVER_SHA256=13219f82df3802fee67c6b1351131492cda1b5320c6d658980c2699a613d0410

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_configure:
	git init -q
	git remote add origin https://github.com/microsoft/playwright-python.git
	git fetch --depth 1 origin refs/tags/v$(PW_VERSION):refs/tags/v$(PW_VERSION)
	git switch --detach v$(PW_VERSION)
	patch -p0 < debian/patches/00-dependency-version.patch
	patch -p0 < debian/patches/01-pyproject-toml.patch

	dh_auto_configure

override_dh_auto_build:
	dh_auto_build
	curl -LOC - --retry-connrefused --retry 5 "https://cdn.playwright.dev/builds/driver/playwright-${PW_DRIVER_VERSION}-linux.zip"
	echo "${PW_DRIVER_SHA256}  playwright-${PW_DRIVER_VERSION}-linux.zip" | sha256sum -c -
	mkdir driver
	unzip "playwright-${PW_DRIVER_VERSION}-linux.zip" -d driver/

override_dh_auto_clean:
	find . -mindepth 1 -maxdepth 1 -not -name "debian" -exec rm -rf {} \;
