diff --git a/.azure-pipelines/publish.yml b/.azure-pipelines/publish.yml deleted file mode 100644 index 74c85ea5..00000000 --- a/.azure-pipelines/publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -# don't trigger for Pull Requests -pr: none - -trigger: - tags: - include: - - '*' - -pool: - vmImage: ubuntu-latest - -steps: -- task: UsePythonVersion@0 - inputs: - versionSpec: '3.8' - displayName: 'Use Python' - -- script: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - python setup.py bdist_wheel --all - displayName: 'Install & Build' - -- task: EsrpRelease@4 - inputs: - ConnectedServiceName: 'Playwright-ESRP' - Intent: 'PackageDistribution' - ContentType: 'PyPi' - ContentSource: 'Folder' - FolderLocation: './dist/' - WaitForReleaseCompletion: true - Owners: 'maxschmitt@microsoft.com' - Approvers: 'maxschmitt@microsoft.com' - ServiceEndpointUrl: 'https://api.esrp.microsoft.com' - MainPublisher: 'Playwright' - DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47' - displayName: 'ESRP Release to PIP' diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index f234cf67..00000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# text files must be lf for golden file tests to work -* text=auto eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index c37bf348..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,193 +0,0 @@ -name: CI - -on: - push: - branches: - - main - - release-* - pull_request: - branches: - - main - - release-* - -concurrency: - # For pull requests, cancel all currently-running jobs for this workflow - # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - infra: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Install dependencies & browsers - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - python setup.py bdist_wheel - python -m playwright install --with-deps - - name: Lint - run: pre-commit run --show-diff-on-failure --color=always --all-files - - name: Generate APIs - run: bash scripts/update_api.sh - - name: Verify generated API is up to date - run: git diff --exit-code - - build: - name: Build - timeout-minutes: 45 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: [3.8, 3.9] - browser: [chromium, firefox, webkit] - include: - - os: ubuntu-latest - python-version: '3.10' - browser: chromium - - os: windows-latest - python-version: '3.10' - browser: chromium - - os: macos-latest - python-version: '3.10' - browser: chromium - - os: windows-latest - python-version: '3.11' - browser: chromium - - os: macos-latest - python-version: '3.11' - browser: chromium - - os: ubuntu-latest - python-version: '3.11' - browser: chromium - - os: windows-latest - python-version: '3.12' - browser: chromium - - os: macos-latest - python-version: '3.12' - browser: chromium - - os: ubuntu-latest - python-version: '3.12' - browser: chromium - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies & browsers - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - python setup.py bdist_wheel - python -m playwright install --with-deps ${{ matrix.browser }} - - name: Common Tests - run: pytest tests/common --browser=${{ matrix.browser }} --timeout 90 - - name: Test Reference count - run: pytest tests/test_reference_count_async.py --browser=${{ matrix.browser }} - - name: Test Wheel Installation - run: pytest tests/test_installation.py --browser=${{ matrix.browser }} - - name: Test Sync API - if: matrix.os != 'ubuntu-latest' - run: pytest tests/sync --browser=${{ matrix.browser }} --timeout 90 - - name: Test Sync API - if: matrix.os == 'ubuntu-latest' - run: xvfb-run pytest tests/sync --browser=${{ matrix.browser }} --timeout 90 - - name: Test Async API - if: matrix.os != 'ubuntu-latest' - run: pytest tests/async --browser=${{ matrix.browser }} --timeout 90 - - name: Test Async API - if: matrix.os == 'ubuntu-latest' - run: xvfb-run pytest tests/async --browser=${{ matrix.browser }} --timeout 90 - - test-stable: - name: Stable - timeout-minutes: 45 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - browser-channel: [chrome] - include: - - os: windows-latest - browser-channel: msedge - - os: macos-latest - browser-channel: msedge - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Install dependencies & browsers - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - python setup.py bdist_wheel - python -m playwright install ${{ matrix.browser-channel }} --with-deps - - name: Common Tests - run: pytest tests/common --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90 - - name: Test Sync API - if: matrix.os != 'ubuntu-latest' - run: pytest tests/sync --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90 - - name: Test Sync API - if: matrix.os == 'ubuntu-latest' - run: xvfb-run pytest tests/sync --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90 - - name: Test Async API - if: matrix.os != 'ubuntu-latest' - run: pytest tests/async --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90 - - name: Test Async API - if: matrix.os == 'ubuntu-latest' - run: xvfb-run pytest tests/async --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90 - - build-conda: - name: Conda Build - strategy: - fail-fast: false - matrix: - os: [ubuntu-20.04, macos-12, windows-2019] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Get conda - uses: conda-incubator/setup-miniconda@v2 - with: - python-version: 3.9 - channels: conda-forge - - name: Prepare - run: conda install conda-build conda-verify - - name: Build - run: conda build . - - test_examples: - name: Examples - runs-on: ubuntu-22.04 - defaults: - run: - working-directory: examples/todomvc/ - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Install dependencies & browsers - run: | - pip install -r requirements.txt - python -m playwright install --with-deps chromium - - name: Common Tests - run: pytest diff --git a/.github/workflows/patchright_workflow.yml b/.github/workflows/patchright_workflow.yml new file mode 100644 index 00000000..66283c03 --- /dev/null +++ b/.github/workflows/patchright_workflow.yml @@ -0,0 +1,87 @@ +name: PatchRight Workflow + +on: + # enabling manual trigger + workflow_dispatch: + inputs: + version: + description: 'Playwright Version' + default: '' + # running every hour + schedule: + - cron: '48 * * * *' + + +permissions: + actions: none + attestations: none + checks: none + contents: write + deployments: none + id-token: none + issues: none + discussions: none + packages: none + pages: none + pull-requests: none + repository-projects: none + security-events: none + statuses: none + + +env: + REPO: ${{ github.repository }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + patchright-workflow: + name: "Patchright Workflow: Install, Patch, Build and Publish Patchright Driver" + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Setup Node v18 + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + - name: Install TS-Morph + run: npm install + + - name: Check Release Version + id: version_check + run: | + if [ -n "${{ github.event.inputs.version }}" ]; then + echo "proceed=true" >>$GITHUB_OUTPUT + echo "playwright_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV + else + chmod +x utils/release_version_check.sh + utils/release_version_check.sh + fi + + - name: Install Playwright Driver + if: steps.version_check.outputs.proceed == 'true' + run: | + git clone https://github.com/microsoft/playwright --branch ${{ env.playwright_version }} + cd playwright + npm ci + + - name: Patch Playwright Driver + if: steps.version_check.outputs.proceed == 'true' + run: | + cd playwright + node "../patchright_driver_patch.js" + + - name: Build Patchright Driver + if: steps.version_check.outputs.proceed == 'true' + run: | + cd playwright + npm run build + npx playwright install-deps + chmod +x utils/build/build-playwright-driver.sh + utils/build/build-playwright-driver.sh + + - name: Publish Patchright Driver + if: steps.version_check.outputs.proceed == 'true' + run: | + chmod +x utils/release_driver.sh + utils/release_driver.sh \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index cc729ae1..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Upload Python Package -on: - release: - types: [published] -jobs: - deploy-conda: - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Get conda - uses: conda-incubator/setup-miniconda@v2 - with: - python-version: 3.9 - channels: conda-forge - - name: Prepare - run: conda install anaconda-client conda-build conda-verify - - name: Build and Upload - env: - ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} - run: | - conda config --set anaconda_upload yes - conda build --user microsoft . diff --git a/.github/workflows/publish_canary_docker.yml b/.github/workflows/publish_canary_docker.yml deleted file mode 100644 index e153e606..00000000 --- a/.github/workflows/publish_canary_docker.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "publish canary docker" - -on: - workflow_dispatch: - schedule: - - cron: "10 0 * * *" - -jobs: - publish-canary: - name: "Publish canary Docker" - runs-on: ubuntu-20.04 - if: github.repository == 'microsoft/undetected_playwright-python' - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Install dependencies & browsers - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - - uses: azure/docker-login@v1 - with: - login-server: undetected_playwright.azurecr.io - username: undetected_playwright - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Set up Docker QEMU for arm64 docker builds - uses: docker/setup-qemu-action@v2 - with: - platforms: arm64 - - name: publish docker canary - run: ./utils/docker/publish_docker.sh canary diff --git a/.github/workflows/publish_release_docker.yml b/.github/workflows/publish_release_docker.yml deleted file mode 100644 index a5afbb4d..00000000 --- a/.github/workflows/publish_release_docker.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: "publish release - Docker" - -on: - workflow_dispatch: - inputs: - is_release: - required: false - type: boolean - description: "Is this a release image?" - - release: - types: [published] - -jobs: - publish-docker-release: - name: "publish to DockerHub" - runs-on: ubuntu-20.04 - if: github.repository == 'microsoft/undetected_playwright-python' - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - uses: azure/docker-login@v1 - with: - login-server: undetected_playwright.azurecr.io - username: undetected_playwright - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Set up Docker QEMU for arm64 docker builds - uses: docker/setup-qemu-action@v2 - with: - platforms: arm64 - - name: Install dependencies & browsers - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - - run: ./utils/docker/publish_docker.sh stable - if: (github.event_name != 'workflow_dispatch' && !github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true') - - run: ./utils/docker/publish_docker.sh canary - if: (github.event_name != 'workflow_dispatch' && github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release != 'true') diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml deleted file mode 100644 index f7d616ba..00000000 --- a/.github/workflows/test_docker.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Test Docker -on: - push: - paths: - - '.github/workflows/test_docker.yml' - - 'setup.py' - - '**/Dockerfile.*' - branches: - - main - - release-* - pull_request: - paths: - - '.github/workflows/test_docker.yml' - - 'setup.py' - - '**/Dockerfile.*' - branches: - - main - - release-* -jobs: - build: - timeout-minutes: 120 - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: - docker-image-variant: - - focal - - jammy - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -e . - - name: Build Docker image - run: bash utils/docker/build.sh --amd64 ${{ matrix.docker-image-variant }} undetected_playwright-python:localbuild-${{ matrix.docker-image-variant }} - - name: Test - run: | - CONTAINER_ID="$(docker run --rm -v $(pwd):/root/playwright --name playwright-docker-test --workdir /root/playwright/ -d -t playwright-python:localbuild-${{ matrix.docker-image-variant }} /bin/bash)" - # Fix permissions for Git inside the container - docker exec "${CONTAINER_ID}" chown -R root:root /root/playwright - docker exec "${CONTAINER_ID}" pip install -r local-requirements.txt - docker exec "${CONTAINER_ID}" pip install -e . - docker exec "${CONTAINER_ID}" python setup.py bdist_wheel - docker exec "${CONTAINER_ID}" xvfb-run pytest -vv tests/sync/ - docker exec "${CONTAINER_ID}" xvfb-run pytest -vv tests/async/ diff --git a/.github/workflows/trigger_internal_tests.yml b/.github/workflows/trigger_internal_tests.yml deleted file mode 100644 index b4e6c21d..00000000 --- a/.github/workflows/trigger_internal_tests.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: "Internal Tests" - -on: - push: - branches: - - main - - release-* - -jobs: - trigger: - name: "trigger" - runs-on: ubuntu-20.04 - steps: - - run: | - curl -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${GH_TOKEN}" \ - --data "{\"event_type\": \"playwright_tests_python\", \"client_payload\": {\"ref\": \"${GITHUB_SHA}\"}}" \ - https://api.github.com/repos/microsoft/playwright-browsers/dispatches - env: - GH_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_PERSONAL_ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore index 9a6021e9..01f94a33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,163 @@ -**/__pycache__/ -driver/ -undetected_playwright/driver/ -playwright.egg-info/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ +develop-eggs/ dist/ -venv/ -.idea/ -**/*.pyc -env/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports htmlcov/ -.coverage* -.DS_Store -.vscode/ -.eggs -_repo_version.py +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml coverage.xml -junit/ -htmldocs/ -utils/docker/dist/ +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ +.DS_Store \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index eabece58..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,49 +0,0 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - exclude: tests/assets/har-sha1-main-response.txt - - id: check-yaml - - id: check-toml - - id: requirements-txt-fixer - - id: check-ast - - id: check-builtin-literals - - id: check-executables-have-shebangs - - id: check-merge-conflict - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 - hooks: - - id: mypy - additional_dependencies: [types-pyOpenSSL==23.2.0.2, types-requests==2.31.0.10] - - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: local - hooks: - - id: pyright - name: pyright - entry: pyright - language: node - pass_filenames: false - types: [python] - additional_dependencies: ["pyright@1.1.278"] - - repo: local - hooks: - - id: check-license-header - name: Check License Header - entry: ./utils/linting/check_file_header.py - language: python - types: [python]