Skip to content

Patchright Release Workflow #3146

Patchright Release Workflow

Patchright Release Workflow #3146

name: Patchright Release Workflow
on:
# enabling manual trigger
workflow_dispatch:
inputs:
version:
description: 'Playwright Version (e.g. v1.58.0 or 1.58.0)'
default: ''
patchright_release:
description: 'Patchright Release Version (e.g. v1.58.0 or 1.58.0) on pypi'
default: ''
# running every hour
schedule:
- cron: '0 * * * *'
env:
REPO: ${{ github.repository }}
patchright_release: ${{ github.event.inputs.patchright_release || '' }}
jobs:
check-release-version:
name: Check Release Version
runs-on: ubuntu-latest
outputs:
proceed: ${{ steps.version_check.outputs.proceed }}
playwright_version: ${{ steps.version_check.outputs.playwright_version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Check Release Version
id: version_check
run: |
PLAYWRIGHT_VERSION=""
if [ -n "${{ github.event.inputs.version }}" ]; then
raw_version="${{ github.event.inputs.version }}"
PLAYWRIGHT_VERSION="v${raw_version#v}"
echo "proceed=true" >>$GITHUB_OUTPUT
echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
if [ -n "${{ github.event.inputs.patchright_release }}" ]; then
raw_patchright_release="${{ github.event.inputs.patchright_release }}"
echo "patchright_release=${raw_patchright_release#v}" >> $GITHUB_ENV
fi
elif [ -n "${{ github.event.inputs.patchright_release }}" ]; then
raw_patchright_release="${{ github.event.inputs.patchright_release }}"
echo "patchright_release=${raw_patchright_release#v}" >> $GITHUB_ENV
response=$(curl --silent "https://api.github.com/repos/microsoft/playwright-python/releases/latest")
PLAYWRIGHT_VERSION=$(echo "$response" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
echo "proceed=true" >>$GITHUB_OUTPUT
echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
else
chmod +x utils/release_version_check.sh
utils/release_version_check.sh
PLAYWRIGHT_VERSION=$(grep '^playwright_version=' "$GITHUB_ENV" | tail -n1 | cut -d= -f2-)
fi
if [ -n "$PLAYWRIGHT_VERSION" ]; then
echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT
fi
run-patchright-tests:
name: Run Patchright Tests
needs: check-release-version
if: needs.check-release-version.outputs.proceed == 'true'
uses: ./.github/workflows/patchright_tests.yml
with:
playwright_version: ${{ needs.check-release-version.outputs.playwright_version }}
patchright-release-workflow:
name: "Patchright-Python Workflow: Install, Patch, Build and Publish Patchright Python Package"
needs: [check-release-version, run-patchright-tests]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/patchright
permissions:
contents: write
id-token: write # For trusted Publishing
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Set up Python
run: uv python install
- name: Install Playwright-Python Package
env:
playwright_version: ${{ needs.check-release-version.outputs.playwright_version }}
run: |
uv sync --all-groups
PLAYWRIGHT_MINOR=${playwright_version#v}
PLAYWRIGHT_MINOR=${PLAYWRIGHT_MINOR%.*}
PATCHRIGHT_DRIVER_VERSION=$(curl -fsSL "https://api.github.com/repos/Kaliiiiiiiiii-Vinyzu/patchright/releases?per_page=100" | jq -r --arg minor "$PLAYWRIGHT_MINOR" '[.[].tag_name | ltrimstr("v") | select(startswith($minor + ".")) | select((try (split(".") | map(tonumber) | length) catch 0) == 3)] | sort_by(split(".") | map(tonumber)) | last')
test -n "$PATCHRIGHT_DRIVER_VERSION" -a "$PATCHRIGHT_DRIVER_VERSION" != "null"
echo "patchright_driver_version=$PATCHRIGHT_DRIVER_VERSION" >> $GITHUB_ENV
if [ -n "$patchright_release" ]; then
PATCHRIGHT_RELEASE="${patchright_release#v}"
else
PATCHRIGHT_RELEASE="$PATCHRIGHT_DRIVER_VERSION"
fi
echo "patchright_release=$PATCHRIGHT_RELEASE" >> $GITHUB_ENV
git clone https://github.com/microsoft/playwright-python --branch "$playwright_version"
uv add -r playwright-python/local-requirements.txt --dev
- name: Patch Playwright-Python Package
run: |
uv run patch_python_package.py
uvx ruff format playwright-python
- name: Build Patchright-Python Package
run: |
cd playwright-python
uv pip install -e .
for wheel in $(uv run setup.py --list-wheels); do
PLAYWRIGHT_TARGET_WHEEL=$wheel uv build --wheel
done
- name: Create Empty Versioning Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.check-release-version.outputs.playwright_version }}
release_name: ${{ needs.check-release-version.outputs.playwright_version }}
body: |
This is an automatic deployment in response to a new release of [microsoft/playwright-python](https://github.com/microsoft/playwright-python).
This Release is only used for Versioning.
draft: false
prerelease: false
- name: Publish Patchright-Python Package
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: playwright-python/dist/
verbose: true