diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f858feeb9..eb49e9249 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,7 +4,7 @@ on: types: [published] jobs: deploy: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: microsoft/playwright-github-action@v1 diff --git a/build_driver.py b/build_driver.py index f2e03307c..c5aff886b 100644 --- a/build_driver.py +++ b/build_driver.py @@ -16,6 +16,7 @@ import re import shutil import subprocess +import sys from playwright.path_utils import get_file_dirname @@ -33,7 +34,19 @@ shutil.rmtree(driver_path / "out") subprocess.check_call("npm i", cwd=driver_path, shell=True) -subprocess.check_call("npm run bake", cwd=driver_path, shell=True) + +platform = sys.platform +if platform == "darwin": + subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True) +elif platform == "linux": + subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True) +elif platform == "win32": + # Windows is the only one that can build all drivers (x86 and x64), + # so we publish from it + subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True) + subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True) + subprocess.check_call("npm run bake-win32", cwd=driver_path, shell=True) + subprocess.check_call("npm run bake-win32-amd64", cwd=driver_path, shell=True) # for local development drivers = (driver_path / "out").glob("**/*") diff --git a/build_package.py b/build_package.py index ce02af945..333c113ad 100644 --- a/build_package.py +++ b/build_package.py @@ -16,6 +16,7 @@ import os import shutil import subprocess +import sys import zipfile from playwright.path_utils import get_file_dirname @@ -36,11 +37,18 @@ base_wheel_location = glob.glob("dist/*.whl")[0] without_platform = base_wheel_location[:-7] -pack_wheel_drivers = [ - ("driver-linux", "manylinux1_x86_64.whl"), - ("driver-macos", "macosx_10_13_x86_64.whl"), - ("driver-win.exe", "win_amd64.whl"), -] +pack_wheel_drivers = [] +if sys.platform == "linux": + pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl")) +if sys.platform == "darwin": + pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl")) +if sys.platform == "win32": + # Windows is the only one that can build all drivers (x86 and x64), + # so we publish from it + pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl")) + pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl")) + pack_wheel_drivers.append(("driver-win32.exe", "win32.whl")) + pack_wheel_drivers.append(("driver-win32-amd64.exe", "win_amd64.whl")) for driver, wheel in pack_wheel_drivers: wheel_location = without_platform + wheel diff --git a/driver/package.json b/driver/package.json index 8e8faab20..87e896c36 100644 --- a/driver/package.json +++ b/driver/package.json @@ -5,7 +5,10 @@ "description": "Playwright driver", "bin": "main.js", "scripts": { - "bake": "pkg --public --out-path=out ." + "bake-darwin": "pkg --public --targets node12-macos-x64 --output=out/driver-darwin .", + "bake-win32": "pkg --public --targets node12-win-x86 --output=out/driver-win32.exe .", + "bake-win32-amd64": "pkg --public --targets node12-win-x64 --output=out/driver-win32-amd64.exe .", + "bake-linux": "pkg --public --targets node12-linux-x64 --output=out/driver-linux ." }, "keywords": [], "author": { diff --git a/playwright/main.py b/playwright/main.py index 5a7547e11..1f86fc45e 100644 --- a/playwright/main.py +++ b/playwright/main.py @@ -14,8 +14,11 @@ import asyncio import io +import os +import stat import subprocess import sys +from pathlib import Path from typing import Any from greenlet import greenlet @@ -30,21 +33,23 @@ from playwright.sync_base import dispatcher_fiber, set_dispatcher_fiber -def compute_driver_name() -> str: +def compute_driver_executable() -> Path: + package_path = get_file_dirname() platform = sys.platform if platform == "darwin": - result = "driver-macos" + return package_path / "drivers" / "driver-darwin" elif platform == "linux": - result = "driver-linux" + return package_path / "drivers" / "driver-linux" elif platform == "win32": - result = "driver-win.exe" - return result + result = package_path / "drivers" / "driver-win32-amd64.exe" + if result.exists(): + return result + return package_path / "drivers" / "driver-win32.exe" + return package_path / "drivers" / "driver-linux" async def run_driver_async() -> Connection: - package_path = get_file_dirname() - driver_name = compute_driver_name() - driver_executable = package_path / "drivers" / driver_name + driver_executable = compute_driver_executable() # Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80 def _get_stderr_fileno() -> int: @@ -134,9 +139,12 @@ def main() -> None: if "install" not in sys.argv: print('Run "python -m playwright install" to complete installation') return - package_path = get_file_dirname() - driver_name = compute_driver_name() - driver_executable = package_path / "drivers" / driver_name + driver_executable = compute_driver_executable() + # Fix the executable bit during the installation. + if not sys.platform == "win32": + st = os.stat(driver_executable) + if st.st_mode & stat.S_IEXEC == 0: + os.chmod(driver_executable, st.st_mode | stat.S_IEXEC) print("Installing the browsers...") subprocess.check_call(f"{driver_executable} install", shell=True)