#! /usr/bin/make -f

export DEB_BUILD_OPTIONS=nocheck
export PYBUILD_NAME=playwright
PW_VERSION=1.42.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.42.1

%:
	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
	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://playwright.azureedge.net/builds/driver/playwright-${PW_DRIVER_VERSION}-linux.zip"
	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 {} \;
