diff --git a/.claude/skills/playwright-triage/SKILL.md b/.claude/skills/playwright-triage/SKILL.md index 9b1010f39..f86826c6a 100644 --- a/.claude/skills/playwright-triage/SKILL.md +++ b/.claude/skills/playwright-triage/SKILL.md @@ -1,39 +1,23 @@ --- name: playwright-triage -description: Triage and fix one microsoft/playwright-python issue, or do a maintainer's task, unattended inside the Issue triage GitHub Actions workflow (.github/workflows/triage.yml), which a needs-triage, needs-triage-mac or needs-triage-win label starts, or a maintainer starts by hand with an issue, a task or both. Reproduces the issue on the runner, then leaves a verified fix proposal for the workflow to open as a draft PR, an investigation note for it to post on the issue, or an upstream bug report for a maintainer to file in microsoft/playwright. Only for that workflow. +description: Triage and fix an issue in microsoft/playwright-python. How to use the upstream checkout, how to run a published version, how to tell a bug of the Python client from an upstream one, the upstream bug report, and what not to run from a PR of a third party. --- # Playwright Python Issue Triage -You run unattended in the [Issue triage](../../../.github/workflows/triage.yml) workflow of -`microsoft/playwright-python`. First read the shared guide, `$AGENT_GUIDES_DIR/triage.md`, a copy of -[microsoft/playwright/.github/actions/run-agent/guides/triage.md](https://github.com/microsoft/playwright/blob/main/.github/actions/run-agent/guides/triage.md), -and then [AGENTS.md](../../../AGENTS.md), both in full. The guide says how to triage an issue in any -Playwright repo. AGENTS.md says how to build, test and lint this one, and where a regression test -goes. This file covers what neither has: the checkouts, how to run a published version, and the -outcome that this repo adds, an upstream bug report. - -## The checkouts - -`$REPO_DIR` is the checkout of `microsoft/playwright-python` that the guide describes. Its requirements -are installed (`pip install -r local-requirements.txt`, `pip install -r requirements.txt`, -`pip install -e .`), the wheel is built (`python -m build --wheel`, which builds the driver into -`playwright/driver/`), and Chromium, Firefox and WebKit are installed with -`python -m playwright install --with-deps`. It is the working directory, and the checkout that the -guides refer to. The clone is shallow: run `git fetch --unshallow --tags origin` in it before you -bisect or use `git tag --contains`. - -`$PLAYWRIGHT_DIR` is `$REPO_DIR/.upstream/`, a full clone of `microsoft/playwright` at the commit -in `DRIVER_VERSION`, created by `python scripts/upstream.py checkout`. The driver was built from it. -Read upstream code there. Do not edit, commit or switch branches in it: the wheel build and -`./scripts/lint.sh` stop when it is not at that commit or has local changes. Before you run upstream -tests in it, it needs `npm ci`, `npm run build` and `npx playwright install`. The wheel build -(`scripts/build_driver.py`) ran the first two there; run them again when `node_modules/` is missing. +## Upstream + +`.upstream/` is the clone of `microsoft/playwright` at the commit in `DRIVER_VERSION`, as +[AGENTS.md](../../../AGENTS.md) says. The driver is built from it. Read upstream code there. Do not +edit, commit or switch branches in it: the wheel build and `./scripts/lint.sh` stop when it is not +at that commit or has local changes. Before you run upstream tests in it, it needs `npm ci`, +`npm run build` and `npx playwright install`. The wheel build (`scripts/build_driver.py`) runs the +first two there; run them again when `node_modules/` is missing. ## Published versions -To run a published version, for example to bisect, create `$SCRATCH_DIR/playwright-python-//` -and run there: +To run a published version, for example to bisect, create an empty directory outside the repo for +each version, and run there: ```bash python -m venv env && source env/bin/activate # env\Scripts\activate on Windows @@ -43,29 +27,30 @@ python -m playwright install The fixtures of the repo are not available there. Write the condensed repro as a plain script with `sync_playwright()` or `async_playwright()` in that directory, with `page.set_content()` in place of -the test server, and run it from there. In `$REPO_DIR`, the source tree shadows the installed package. +the test server, and run it from there. In this repo, the source tree shadows the installed +package. The driver of a release is in `DRIVER_VERSION` at its tag: `git show v:DRIVER_VERSION` prints the upstream commit it was built from, or, for releases up to 1.64, the `playwright-core` version of the driver; `npm view playwright-core@ gitHead` prints its commit. Match a -regression in the driver to commits with `git -C $PLAYWRIGHT_DIR log .. -- `. +regression in the driver to commits with `git -C .upstream log .. -- `. ## Upstream bugs -The client talks to the Node driver that is built from `$PLAYWRIGHT_DIR`, and `microsoft/playwright` +The client talks to the Node driver that is built from `.upstream/`, and `microsoft/playwright` and this repo are one team. Reproduce the bug in Python first. Then write the same calls as an -upstream test and run it in `$PLAYWRIGHT_DIR`. The triage skill of `microsoft/playwright`, in -`$PLAYWRIGHT_DIR/.claude/skills/playwright-triage/`, says where such a test goes, which fixtures it -uses and how to run it. The rest of that skill is not for this run. Put the test in a new spec -file, and delete the file when you are done, so that the checkout is clean. +upstream test and run it in `.upstream/`. The triage skill of `microsoft/playwright`, in +`.upstream/.claude/skills/playwright-triage/`, says where such a test goes, which fixtures it uses +and how to run it. Use only those parts of it. Put the test in a new spec file, and delete the file +when you are done, so that the checkout is clean. - The Node test passes: the bug is in the Python client. Fix it here. - The Node test fails too: the root cause is upstream, and the fix lands in `microsoft/playwright`. - Do not work around it in `playwright/_impl/`. Run `git -C $PLAYWRIGHT_DIR fetch origin main`. - When `git -C $PLAYWRIGHT_DIR log HEAD..origin/main -- ` shows a fix that already landed, - the note says that it reaches this repo with the next roll. Otherwise write the report. + Do not work around it in `playwright/_impl/`. Run `git -C .upstream fetch origin main`. When + `git -C .upstream log HEAD..origin/main -- ` shows a fix that already landed, it reaches + this repo with the next roll: say so. Otherwise write the report. - The Python API lacks a member or an option: the generated API has everything that the upstream - docs in `$PLAYWRIGHT_DIR/docs/src/api` give Python (`* langs:` decides; no `langs` means every + docs in `.upstream/docs/src/api` give Python (`* langs:` decides; no `langs` means every language). The gap is in the docs, so it is an upstream change too. Do not edit a generated file, and do not add to `scripts/codegen/python_rules.js` to go around the docs. @@ -73,11 +58,7 @@ The report is for an engineer of `microsoft/playwright` who did not read the Pyt fails, expected versus actual, the versions (the Python package, the commit in `DRIVER_VERSION`, the browser, the platform), the root cause when you found it, and the condensed Node test as the repro. The title has at most 256 characters, for example `route.fulfill() drops the charset of -Content-Type`. - -The bot never files it in `microsoft/playwright`: this run allows no `issue` call (the calls are -in `$AGENT_GUIDES_DIR/calls.d.ts`). Put the report at the end of your comment, for a maintainer to -file, in this form: +Content-Type`. A maintainer files it in `microsoft/playwright`. Give it in this form: `````markdown Upstream bug report, for a maintainer to file in microsoft/playwright: @@ -94,7 +75,7 @@ Upstream bug report, for a maintainer to file in microsoft/playwright: ````` -Write the rest of the comment as the note: the verdict, the evidence, and that the bug is upstream. +With it, give the verdict, the evidence, and that the bug is upstream. ## PRs from third parties diff --git a/.github/actions/setup-triage-runner/action.yml b/.github/actions/setup-triage-runner/action.yml deleted file mode 100644 index 5c81075d4..000000000 --- a/.github/actions/setup-triage-runner/action.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: 'Set up the triage runner' -description: > - Prepares the environment that the triage, revision and roll agents work in: the checkout built as - CI builds it, with the browsers and the Copilot CLI installed, and the upstream checkout in - .upstream/ that the driver is built from. Exports PLAYWRIGHT_DIR, the path of that checkout, and - CI_ENV_EXEC, the wrapper from microsoft/playwright that runs a command under xvfb on Linux and at - normal I/O priority on Windows. With pin, it does steps 1 and 2 of the playwright-roll skill before - the build: it pins that commit, updates NODE_VERSION and generates the API from the new pin. -inputs: - pin: - description: 'microsoft/playwright commit to roll to; empty builds the commit in DRIVER_VERSION' - required: false - default: '' -runs: - using: composite - steps: - - uses: microsoft/playwright/.github/actions/ci-env@d1518e3e3fca90352c4390814943cced496fd7e4 # main - - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: '3.12' - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: '24' - - name: Install the requirements - shell: bash - run: | - python -m pip install --upgrade pip - pip install -r local-requirements.txt - pip install -r requirements.txt - pip install -e . - - name: Pin and generate the API - if: inputs.pin != '' - shell: bash - env: - PIN: ${{ inputs.pin }} - run: | - python scripts/upstream.py pin "$PIN" - python scripts/update_node_version.py - ./scripts/update_api.sh - - name: Check out upstream and build the wheel - shell: bash - run: | - python scripts/upstream.py checkout - python -m build --wheel - echo "PLAYWRIGHT_DIR=${GITHUB_WORKSPACE//\\//}/.upstream" >> "$GITHUB_ENV" - - name: Install the browsers - shell: bash - run: python -m playwright install --with-deps chromium firefox webkit - - name: Install the Copilot CLI - shell: bash - run: npm install -g @github/copilot diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml new file mode 100644 index 000000000..56f9ec912 --- /dev/null +++ b/.github/workflows/review.yml @@ -0,0 +1,33 @@ +# Hands the pull request to the Playwright bot when a maintainer applies agent-review. Nothing +# else of the bot lives in this repo. Apply the label again to start another run. +name: "Agent: review" + +on: + # Runs from the default branch, for PRs from forks too. It never checks out the PR. + pull_request_target: + types: [labeled] + +permissions: {} + +jobs: + pr: + name: Hand the PR to the bot + if: github.repository_owner == 'microsoft' && github.event.label.name == 'agent-review' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: app-token + with: + client-id: ${{ vars.PLAYWRIGHT_APP_CLIENT_ID }} + private-key: ${{ secrets.PLAYWRIGHT_PRIVATE_KEY }} + owner: microsoft + repositories: devops.playwright.dev + permission-actions: write + - name: Start the bot + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + NUMBER: ${{ github.event.pull_request.number }} + run: >- + gh workflow run pr.yml --repo microsoft/devops.playwright.dev --ref main + -f repo="$GITHUB_REPOSITORY" -f pr="$NUMBER" diff --git a/.github/workflows/revision.yml b/.github/workflows/revision.yml deleted file mode 100644 index b99d6761a..000000000 --- a/.github/workflows/revision.yml +++ /dev/null @@ -1,133 +0,0 @@ -# Copilot addresses the maintainers' review comments on a draft PR that the triage workflow opened, -# without write credentials. The agent leaves the calls to make on GitHub in calls.json. A fresh job -# checks them and makes them using the app: it pushes the new commit to the PR's branch, so CI runs -# on it, and replies in the review threads. The steps that are the same for every Playwright repo -# are actions in microsoft/playwright, and the shared guide they carry says how to revise; the -# prompt below has what is specific to this repo. -name: PR revision - -on: - # Apply needs-revision, needs-revision-mac or needs-revision-win; re-apply it to trigger another pass. - # pull_request_target always runs this file from main; the jobs only accept the triage app's own PRs. - pull_request_target: - types: [labeled] - -permissions: {} - -jobs: - prepare: - name: Collect the maintainers' comments - if: >- - github.repository == 'microsoft/playwright-python' && - contains(fromJSON('["needs-revision","needs-revision-mac","needs-revision-win"]'), github.event.label.name) && - github.event.pull_request.state == 'open' && - github.event.pull_request.user.login == 'microsoft-playwright-automation[bot]' && - github.event.pull_request.head.repo.full_name == github.repository - runs-on: ubuntu-latest - permissions: - issues: read - pull-requests: write - env: - PLATFORM: ${{ fromJSON('{"needs-revision":"linux","needs-revision-mac":"mac","needs-revision-win":"windows"}')[github.event.label.name] }} - outputs: - head: ${{ steps.collect.outputs.head }} - base: ${{ steps.collect.outputs.base }} - branch: ${{ steps.collect.outputs.branch }} - platform: ${{ env.PLATFORM }} - steps: - - name: Collect the PR and the maintainers' comments - id: collect - uses: microsoft/playwright/.github/actions/collect-review@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - pull-request: ${{ github.event.pull_request.number }} - - name: Post the run link - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ github.event.pull_request.number }} - PLATFORM_NAME: ${{ fromJSON('{"linux":"Linux","mac":"macOS","windows":"Windows"}')[env.PLATFORM] }} - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: | - body=$(printf "Hi, I'm the Playwright bot. I started to address the review comments on %s: [agent run](%s)\n" "$PLATFORM_NAME" "$RUN_URL") - gh pr comment "$PR" --body "$body" || echo "::warning::Could not post the run link" - - revise: - name: Revise PR ${{ github.event.pull_request.number }} (${{ needs.prepare.outputs.platform }}) - needs: prepare - runs-on: ${{ fromJSON('{"linux":"playwright-x64-ubuntu24-64-core","mac":"macos-15-xlarge","windows":"playwright-x64-server2025-64-core"}')[needs.prepare.outputs.platform] }} - timeout-minutes: 240 - concurrency: - group: revision-${{ github.event.pull_request.number }} - cancel-in-progress: false - defaults: - run: - shell: bash - env: - PR: ${{ github.event.pull_request.number }} - HEAD_SHA: ${{ needs.prepare.outputs.head }} - BASE_SHA: ${{ needs.prepare.outputs.base }} - TRIAGE_PLATFORM: ${{ needs.prepare.outputs.platform }} - permissions: - copilot-requests: write - outputs: - has_revision: ${{ steps.agent.outputs.has-result }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.prepare.outputs.head }} - persist-credentials: false - - name: Fetch the base and record the directories - run: | - git fetch --no-tags --depth=1 origin "$BASE_SHA" - echo "OUTPUT_DIR=${RUNNER_TEMP//\\//}/revision" >> "$GITHUB_ENV" - echo "REVIEW_DIR=${RUNNER_TEMP//\\//}/review" >> "$GITHUB_ENV" - echo "SCRATCH_DIR=${RUNNER_TEMP//\\//}/scratch" >> "$GITHUB_ENV" - echo "REPO_DIR=${GITHUB_WORKSPACE//\\//}" >> "$GITHUB_ENV" - mkdir -p "${RUNNER_TEMP//\\//}/revision" "${RUNNER_TEMP//\\//}/scratch" - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: review - path: ${{ runner.temp }}/review - - name: Set up the runner - uses: ./.github/actions/setup-triage-runner - - name: Revise with Copilot CLI - id: agent - # No GitHub tools and no URL access: the agent reads the PR only from the review the prepare job filtered. - uses: microsoft/playwright/.github/actions/run-agent@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - prompt: | - Follow the shared guide revision.md and this repo's AGENTS.md. Read both in full before starting. $PLAYWRIGHT_DIR is the .upstream/ checkout of microsoft/playwright at the commit in DRIVER_VERSION; do not edit, commit or switch branches in it. - - Pull request: https://github.com/microsoft/playwright-python/pull/${{ github.event.pull_request.number }} - output-dir: ${{ env.OUTPUT_DIR }} - result-file: calls.json - artifact-name: revision - exec: ${{ env.CI_ENV_EXEC }} - - push: - name: Push the revision - needs: [prepare, revise] - # calls.json is written when the revision is done, so it is pushed even if the job failed later. - if: ${{ !cancelled() && needs.revise.outputs.has_revision == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 - id: app-token - with: - app-id: ${{ vars.PLAYWRIGHT_APP_ID }} - private-key: ${{ secrets.PLAYWRIGHT_PRIVATE_KEY }} - permission-contents: write - permission-pull-requests: write - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.prepare.outputs.head }} - token: ${{ steps.app-token.outputs.token }} - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: revision - path: ${{ runner.temp }}/revision - # Never execute code or scripts from the artifact in the app job. The calls are data. - - name: Check and make the calls - uses: microsoft/playwright/.github/actions/publish-calls@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - token: ${{ steps.app-token.outputs.token }} - dir: ${{ runner.temp }}/revision diff --git a/.github/workflows/roll.yml b/.github/workflows/roll.yml index a59536af9..e3fabcc3a 100644 --- a/.github/workflows/roll.yml +++ b/.github/workflows/roll.yml @@ -1,11 +1,7 @@ -# Rolls Playwright to a new microsoft/playwright commit, the tip of main unless told otherwise. -# Copilot CLI ports the upstream changes with the playwright-roll skill, without write credentials. -# A fresh job opens the pull request using the microsoft-playwright-automation app, so CI runs on it; -# a partial roll opens as a draft. As in triage.yml, the steps that are the same for every Playwright -# repo are actions in microsoft/playwright, and .github/actions/setup-triage-runner prepares the -# runner: with pin, it also pins, generates and builds. -# Upstream counterpart: microsoft/playwright.dev .github/workflows/roll-next.yml. -name: Roll to latest Playwright +# Rolls Playwright Python to a new microsoft/playwright commit, the tip of main unless told +# otherwise. Starts the Playwright bot with the task below. The bot does it with the +# playwright-roll skill, and opens the pull request as the app. +name: "Agent: roll Playwright" on: # Mon, Wed and Fri at 9:17 UTC: 2:17 at night Pacific time, 1:17 in winter. Not on the hour, when @@ -17,41 +13,19 @@ on: ref: description: "microsoft/playwright branch, tag or commit to roll to" default: "main" - max_ai_credits: - description: "AI credit limit for the Copilot session" - default: "3000" permissions: {} jobs: - versions: - name: Find the commit + start: + name: Hand the task to the bot if: github.repository == 'microsoft/playwright-python' - runs-on: ubuntu-24.04 + runs-on: ubuntu-latest + timeout-minutes: 5 permissions: - contents: read pull-requests: read - outputs: - old_commit: ${{ steps.versions.outputs.old_commit }} - new_commit: ${{ steps.versions.outputs.new_commit }} - new_short: ${{ steps.versions.outputs.new_short }} - open_roll: ${{ steps.open.outputs.pr }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Read the pinned and the new commit - id: versions - env: - REF: ${{ inputs.ref || 'main' }} - run: | - old_commit="$(cat DRIVER_VERSION)" - new_commit="$(python3 scripts/upstream.py resolve "$REF")" - echo "Pinned ${old_commit}, ${REF} is ${new_commit}" >> "$GITHUB_STEP_SUMMARY" - { - echo "old_commit=${old_commit}" - echo "new_commit=${new_commit}" - echo "new_short=${new_commit:0:10}" - } >> "$GITHUB_OUTPUT" - # A manual run rolls anyway: a maintainer asked for it. + # A manual run rolls anyway: a maintainer asked for it. The skill gives the title of a roll. - name: Look for an open roll pull request id: open if: github.event_name == 'schedule' @@ -59,213 +33,27 @@ jobs: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} run: | - pr=$(gh pr list --state open --author app/microsoft-playwright-automation --json number,headRefName \ - --jq '[.[] | select(.headRefName | startswith("roll/")) | .number] | first // empty') + pr=$(gh pr list --state open --author app/microsoft-playwright-automation --json number,title \ + --jq '[.[] | select(.title | startswith("chore: roll Playwright to")) | .number] | first // empty') if [[ -n "$pr" ]]; then echo "pr=$pr" >> "$GITHUB_OUTPUT" echo "Skipped: roll pull request #$pr is open." >> "$GITHUB_STEP_SUMMARY" fi - - roll: - name: Roll to ${{ needs.versions.outputs.new_short }} - needs: versions - if: >- - needs.versions.outputs.new_commit != needs.versions.outputs.old_commit && - needs.versions.outputs.open_roll == '' - # The runner of CI: the skill runs ./test.sh, both suites on all its cores. - runs-on: playwright-x64-ubuntu24-64-core - timeout-minutes: 240 - concurrency: - group: roll - cancel-in-progress: false - defaults: - run: - shell: bash - permissions: - copilot-requests: write - outputs: - setup: ${{ steps.setup.outcome }} - version: ${{ steps.record.outputs.version }} - complete: ${{ steps.save.outputs.complete }} - has_changes: ${{ steps.save.outputs.has_changes }} - env: - OLD_COMMIT: ${{ needs.versions.outputs.old_commit }} - NEW_COMMIT: ${{ needs.versions.outputs.new_commit }} - steps: - # No credentials in the checkout: the agent must not push. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Record the directories - run: | - echo "OUTPUT_DIR=$RUNNER_TEMP/roll" >> "$GITHUB_ENV" - echo "PATCH_DIR=$RUNNER_TEMP/roll-patch" >> "$GITHUB_ENV" - mkdir -p "$RUNNER_TEMP/roll" "$RUNNER_TEMP/roll-patch" - # Steps 1 to 3 of the playwright-roll skill. - - name: Set up the runner - id: setup - uses: ./.github/actions/setup-triage-runner - with: - pin: ${{ env.NEW_COMMIT }} - # Before the session, from .upstream/ at the new pin. - - name: Record the version and the upstream commits - id: record - run: | - echo "version=$(node -p "require('./.upstream/packages/playwright-core/package.json').version")" >> "$GITHUB_OUTPUT" - python scripts/upstream.py log "$OLD_COMMIT" > "$RUNNER_TEMP/commits.md" - - name: Roll with Copilot CLI - id: agent - # No GitHub tools and no URL access: the agent reads upstream only from .upstream/, so text from - # issues and PRs does not reach it. - uses: microsoft/playwright/.github/actions/run-agent@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - prompt: | - Roll Playwright Python from microsoft/playwright ${{ env.OLD_COMMIT }} to ${{ env.NEW_COMMIT }}. Follow the playwright-roll skill, .claude/skills/playwright-roll/SKILL.md, and AGENTS.md. Read both in full before starting. - - The workflow already did steps 1 (pin), 2 (generate) and 3 (build) of the skill: DRIVER_VERSION is ${{ env.NEW_COMMIT }}, .upstream/ is checked out at it, NODE_VERSION is the current LTS, ./scripts/update_api.sh has generated the files from .upstream/, the driver is built, and Chromium, Firefox and WebKit are installed. The old pin is ${{ env.OLD_COMMIT }} (DRIVER_VERSION at HEAD). Start with mypy playwright and the API comparison of step 2, then step 4. - - Do not commit, push or run gh. A later job of the workflow commits your changes and opens the pull request. - - When you finish, write the pull request description that step 5 of the skill describes to $OUTPUT_DIR/summary.md, without the list of upstream commits: the workflow shows the file in the run summary, sets the title and adds the list. - output-dir: ${{ env.OUTPUT_DIR }} - result-file: summary.md - artifact-name: roll - exec: ${{ env.CI_ENV_EXEC }} - max-ai-credits: ${{ inputs.max_ai_credits || '3000' }} - # The agent runs scripts/lint.sh last (step 5 of the skill); a roll that does - # not pass it again here opens as a draft. - - name: Check the roll - id: check - continue-on-error: true - run: | - test "$(cat DRIVER_VERSION)" = "$NEW_COMMIT" - ./scripts/lint.sh - # After the session, so that a partial roll opens too: the pin and the generated files are a - # start for a maintainer. - - name: Save the pull request - id: save - env: - COMPLETE: ${{ steps.agent.outputs.outcome == 'success' && steps.check.outcome == 'success' }} - COMPARE_URL: https://github.com/microsoft/playwright/compare/${{ needs.versions.outputs.old_commit }}...${{ needs.versions.outputs.new_commit }} - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: | - git add -A - # Against the checked-out commit, in case the agent committed anyway. - git diff --cached --binary "$GITHUB_SHA" > "$PATCH_DIR/roll.patch" - if [[ -s "$PATCH_DIR/roll.patch" ]]; then - echo "has_changes=true" >> "$GITHUB_OUTPUT" - else - echo "has_changes=false" >> "$GITHUB_OUTPUT" - fi - echo "complete=$COMPLETE" >> "$GITHUB_OUTPUT" - python - <<'EOF' - import os - from pathlib import Path - - env = os.environ - def read(path): - return path.read_text(encoding="utf-8").strip() if path.is_file() else "" - - parts = [read(Path(env["OUTPUT_DIR"], "summary.md")) or "The agent wrote no description."] - if env["COMPLETE"] != "true": - parts.append(f"**The roll is not complete:** the agent or the checks failed. See the [roll run]({env['RUN_URL']}).") - # A description has at most 65536 characters: a long range keeps its first commits. - commits = [line for line in read(Path(env["RUNNER_TEMP"], "commits.md")).splitlines() if line] - total = len(commits) - while len("\n".join(commits)) > 50000: - commits = commits[: len(commits) * 9 // 10] - if len(commits) < total: - commits.append(f"- … and {total - len(commits)} more: {env['COMPARE_URL']}") - parts.append(f"
\nUpstream commits ({total})\n\n" + "\n".join(commits) + "\n\n
") - parts.append(f"Upstream changes: {env['COMPARE_URL']}") - # publish-calls adds nothing to the text, so the footer is here. - parts.append(f"Prepared by the [roll workflow]({env['RUN_URL']}).") - Path(env["PATCH_DIR"], "pr-body.md").write_text("\n\n".join(parts) + "\n", encoding="utf-8") - EOF - { - echo '```' - git diff --cached --stat "$GITHUB_SHA" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - - name: Upload the pull request - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: roll-patch - path: ${{ env.PATCH_DIR }} - if-no-files-found: error - - publish: - name: Open the pull request - needs: [versions, roll] - if: ${{ !cancelled() && needs.roll.outputs.has_changes == 'true' }} - runs-on: ubuntu-latest - outputs: - pr: ${{ steps.publish.outputs.pull-request }} - steps: - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + if: steps.open.outputs.pr == '' id: app-token with: client-id: ${{ vars.PLAYWRIGHT_APP_CLIENT_ID }} private-key: ${{ secrets.PLAYWRIGHT_PRIVATE_KEY }} - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - token: ${{ steps.app-token.outputs.token }} - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - with: - name: roll-patch - path: ${{ runner.temp }}/roll - # A roll changes only what a roll changes; publish-calls rejects only .github/. The checks are - # here and not in a script, because the roll could change the script. They apply the patch to - # a separate index, so the checkout stays clean for publish-calls. - - name: Check the changed files - env: - GIT_INDEX_FILE: ${{ runner.temp }}/roll.index - run: | - git read-tree HEAD - git apply --cached "$RUNNER_TEMP/roll/roll.patch" - # --no-renames lists a renamed file under its old name too. - git diff --cached --name-only --no-renames > "$RUNNER_TEMP/changed.txt" - if grep -E '\.ya?ml$' "$RUNNER_TEMP/changed.txt"; then - echo "The roll changes YAML files." >&2 - exit 1 - fi - if grep -E '(^|/)(AGENTS|CLAUDE)\.md$' "$RUNNER_TEMP/changed.txt"; then - echo "The roll changes agent instructions." >&2 - exit 1 - fi - if grep -v -E '^(DRIVER_VERSION|NODE_VERSION|README\.md|scripts/codegen/python_rules\.js)$|^(playwright|tests)/' "$RUNNER_TEMP/changed.txt"; then - echo "The roll changes files outside DRIVER_VERSION, NODE_VERSION, README.md, playwright/, tests/ and python_rules.js." >&2 - exit 1 - fi - # The new mode of each path, also when a file changes its type: 120000 is a symbolic link, - # 160000 a submodule. - if git diff --cached --raw --no-renames | awk '$2 ~ /^1[26]0000$/ { found = 1; print } END { exit !found }'; then - echo "The roll adds a symbolic link or a submodule." >&2 - exit 1 - fi - # This job writes the call, and not the roll job, so that nothing in the artifact can add a call - # or name a patch other than the one that the checks above read. - - name: Write the call - env: - BRANCH: roll/${{ needs.versions.outputs.new_short }}/${{ github.run_id }}-${{ github.run_attempt }} - TITLE: "chore: roll Playwright to ${{ needs.roll.outputs.version }} (${{ needs.versions.outputs.new_short }})" - run: | - jq -n --arg repo "$GITHUB_REPOSITORY" --arg branch "$BRANCH" --arg title "$TITLE" \ - '[{call: "pull-request", repo: $repo, branch: $branch, title: $title, patch: "roll.patch", bodyFile: "pr-body.md"}]' \ - > "$RUNNER_TEMP/roll/calls.json" - # Never execute code or scripts from the roll in the app job. The call is data. - - name: Check and make the call - id: publish - uses: microsoft/playwright/.github/actions/publish-calls@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - token: ${{ steps.app-token.outputs.token }} - dir: ${{ runner.temp }}/roll - scope-kinds: pull-request - # publish-calls opens a draft; a complete roll is ready for review. - - name: Mark the pull request as ready - if: needs.roll.outputs.complete == 'true' + owner: microsoft + repositories: devops.playwright.dev + permission-actions: write + - name: Start the bot + if: steps.open.outputs.pr == '' env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - GH_REPO: ${{ github.repository }} - PR: ${{ steps.publish.outputs.pull-request }} - run: gh pr ready "$PR" + REF: ${{ inputs.ref || 'main' }} + run: | + task="Roll Playwright Python to $REF of microsoft/playwright, as the playwright-roll skill, .claude/skills/playwright-roll/SKILL.md, says. When the roll is not complete, open the pull request anyway: the pin and the generated files are a start for a maintainer. Say in it what is left." + gh workflow run task.yml --repo microsoft/devops.playwright.dev --ref main \ + -f repo="$GITHUB_REPOSITORY" -f task="$task" diff --git a/.github/workflows/task.yml b/.github/workflows/task.yml new file mode 100644 index 000000000..9fa5ac950 --- /dev/null +++ b/.github/workflows/task.yml @@ -0,0 +1,36 @@ +# Starts the Playwright bot with the task that you type. The bot does it with the skills of this +# repo, and opens the pull request as the app. Start it from the Actions tab. +name: "Agent: task" + +on: + workflow_dispatch: + inputs: + task: + description: What the bot should do + type: string + required: true + +permissions: {} + +jobs: + start: + name: Hand the task to the bot + if: github.repository == 'microsoft/playwright-python' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: app-token + with: + client-id: ${{ vars.PLAYWRIGHT_APP_CLIENT_ID }} + private-key: ${{ secrets.PLAYWRIGHT_PRIVATE_KEY }} + owner: microsoft + repositories: devops.playwright.dev + permission-actions: write + - name: Start the bot + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + TASK: ${{ inputs.task }} + run: >- + gh workflow run task.yml --repo microsoft/devops.playwright.dev --ref main + -f repo="$GITHUB_REPOSITORY" -f task="$TASK" diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index f9419c5e9..aa39150dd 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -1,207 +1,38 @@ -# Copilot triages and fixes an issue, or works on a task given by hand, without write credentials. -# The agent leaves the calls to make on GitHub in calls.json. A fresh job posts the run link on the -# issue first. After the agent, a fresh job checks the calls and makes them using the app: it opens -# the fix as a draft PR, so CI runs on it, and comments on the issue. The steps that are the same -# for every Playwright repo are actions in microsoft/playwright. The skill in -# .claude/skills/playwright-triage/ has what is specific to this repo. -name: Issue triage +# Hands the issue to the Playwright bot when a maintainer applies agent-triage, agent-implement or +# agent-task. Nothing else of the bot lives in this repo. Apply the label again to start another +# run. +name: "Agent: triage" on: - # Apply needs-triage, needs-triage-mac or needs-triage-win; re-apply it to trigger another pass. issues: types: [labeled] - workflow_dispatch: - inputs: - issue: - description: "Issue number to triage; leave empty to work on the task alone" - type: string - required: false - default: "" - platform: - description: "Platform to triage on" - type: choice - required: true - default: linux - options: - - linux - - mac - - windows - task: - description: "Task to direct the triage, such as what to focus on; the whole job when there is no issue" - type: string - required: false - default: "" permissions: {} jobs: - start: - name: Post the run link on the issue - # The triage job's condition, for runs that have an issue. + issue: + name: Hand the issue to the bot if: >- - github.repository == 'microsoft/playwright-python' && - ((github.event_name == 'workflow_dispatch' && inputs.issue != '') || - contains(fromJSON('["needs-triage","needs-triage-mac","needs-triage-win"]'), github.event.label.name)) - runs-on: ubuntu-latest - permissions: - issues: write - outputs: - comment: ${{ steps.post.outputs.id }} - env: - ISSUE: ${{ github.event.issue.number || inputs.issue }} - PLATFORM_NAME: ${{ fromJSON('{"linux":"Linux","mac":"macOS","windows":"Windows","needs-triage":"Linux","needs-triage-mac":"macOS","needs-triage-win":"Windows"}')[inputs.platform || github.event.label.name] }} - GH_TOKEN: ${{ github.token }} - GH_REPO: ${{ github.repository }} - WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - steps: - - name: Post the run link - id: post - run: | - [[ "$ISSUE" =~ ^[1-9][0-9]*$ ]] || { echo "issue must be a positive integer" >&2; exit 1; } - body=$(printf "Hi, I'm the Playwright bot. I started to triage this issue on %s: [agent run](%s)\n" "$PLATFORM_NAME" "$WORKFLOW_URL") - id=$(gh api "repos/$GH_REPO/issues/$ISSUE/comments" -f body="$body" --jq .node_id) - echo "id=$id" >> "$GITHUB_OUTPUT" - - triage: - name: Triage ${{ (github.event.issue.number || inputs.issue) && format('issue {0}', github.event.issue.number || inputs.issue) || 'task' }} (${{ inputs.platform || github.event.label.name }}) - if: >- - github.repository == 'microsoft/playwright-python' && - (github.event_name == 'workflow_dispatch' || - contains(fromJSON('["needs-triage","needs-triage-mac","needs-triage-win"]'), github.event.label.name)) - # Falls back to a runner name for unrelated labels, where the job is skipped anyway. - runs-on: ${{ fromJSON('{"linux":"playwright-x64-ubuntu24-64-core","mac":"macos-15-xlarge","windows":"playwright-x64-server2025-64-core"}')[inputs.platform || fromJSON('{"needs-triage":"linux","needs-triage-mac":"mac","needs-triage-win":"windows"}')[github.event.label.name]] || 'ubuntu-latest' }} - timeout-minutes: 240 - concurrency: - group: triage-${{ github.event.issue.number || inputs.issue || github.run_id }} - cancel-in-progress: false - defaults: - run: - shell: bash - env: - ISSUE: ${{ github.event.issue.number || inputs.issue }} - TRIAGE_PLATFORM: ${{ inputs.platform || fromJSON('{"needs-triage":"linux","needs-triage-mac":"mac","needs-triage-win":"windows"}')[github.event.label.name] }} - TASK: ${{ inputs.task }} - permissions: - copilot-requests: write - outputs: - base: ${{ steps.base.outputs.sha }} - setup: ${{ steps.setup.outcome }} - agent: ${{ steps.agent.outputs.outcome }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: main - persist-credentials: false - - name: Record the base and the directories - id: base - run: | - if [[ -n "$ISSUE" ]]; then - [[ "$ISSUE" =~ ^[1-9][0-9]*$ ]] || { echo "issue must be a positive integer" >&2; exit 1; } - elif [[ -z "${TASK//[[:space:]]/}" ]]; then - echo "give an issue, a task or both" >&2; exit 1 - fi - echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - echo "OUTPUT_DIR=${RUNNER_TEMP//\\//}/triage" >> "$GITHUB_ENV" - echo "SCRATCH_DIR=${RUNNER_TEMP//\\//}/scratch" >> "$GITHUB_ENV" - echo "REPO_DIR=${GITHUB_WORKSPACE//\\//}" >> "$GITHUB_ENV" - mkdir -p "${RUNNER_TEMP//\\//}/triage" "${RUNNER_TEMP//\\//}/scratch" - - name: Set up the runner - id: setup - uses: ./.github/actions/setup-triage-runner - - name: Write the prompt - id: prompt - run: | - delimiter="PROMPT_$RANDOM$RANDOM" - { - echo "prompt<<$delimiter" - echo "Follow .claude/skills/playwright-triage/SKILL.md. Read it, the guide and the AGENTS.md" - echo "it points to in full before starting." - if [[ -n "$ISSUE" ]]; then - printf '\nIssue: https://github.com/%s/issues/%s\n' "$GITHUB_REPOSITORY" "$ISSUE" - fi - if [[ -n "$TASK" ]]; then - printf '\nTask: %s\n' "$TASK" - fi - echo "$delimiter" - } >> "$GITHUB_OUTPUT" - - name: Triage with Copilot CLI - id: agent - uses: microsoft/playwright/.github/actions/run-agent@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - prompt: ${{ steps.prompt.outputs.prompt }} - output-dir: ${{ env.OUTPUT_DIR }} - result-file: calls.json - artifact-name: triage - github-tools: true - exec: ${{ env.CI_ENV_EXEC }} - - publish: - name: Publish the results - needs: [start, triage] - # Runs after every triage run, also a failed one: without a comment from the agent, the comment - # says why the bot could not finish. - if: ${{ !cancelled() && needs.triage.result != 'skipped' }} + github.repository_owner == 'microsoft' && ( + github.event.label.name == 'agent-triage' || + github.event.label.name == 'agent-implement' || + github.event.label.name == 'agent-task') runs-on: ubuntu-latest + timeout-minutes: 5 steps: - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 id: app-token with: - app-id: ${{ vars.PLAYWRIGHT_APP_ID }} + client-id: ${{ vars.PLAYWRIGHT_APP_CLIENT_ID }} private-key: ${{ secrets.PLAYWRIGHT_PRIVATE_KEY }} - permission-contents: write - permission-issues: write - permission-pull-requests: write - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.triage.outputs.base }} - token: ${{ steps.app-token.outputs.token }} - - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 - # A failed triage run may not have uploaded anything. - continue-on-error: true - with: - name: triage - path: ${{ runner.temp }}/triage - # Without a comment from the agent on the issue, for example after a failed run, the issue gets - # one that says that the bot could not finish. - - name: Add a comment when the agent left none - if: github.event.issue.number || inputs.issue - env: - CALLS: ${{ runner.temp }}/triage/calls.json - ISSUE: ${{ github.event.issue.number || inputs.issue }} - SETUP: ${{ needs.triage.outputs.setup }} - AGENT: ${{ needs.triage.outputs.agent }} - FOOTER: Triaged on ${{ fromJSON('{"linux":"Linux","mac":"macOS","windows":"Windows","needs-triage":"Linux","needs-triage-mac":"macOS","needs-triage-win":"Windows"}')[inputs.platform || github.event.label.name] }} by the Playwright bot - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: | - mkdir -p "$(dirname "$CALLS")" - if jq -e --argjson issue "$ISSUE" 'any(.[]; .call == "comment" and .issue == $issue)' "$CALLS" > /dev/null 2>&1; then - exit 0 - fi - if [[ "$SETUP" == "failure" ]]; then - reason="setting up the runner failed" - elif [[ "$AGENT" == "failure" ]]; then - reason="the Copilot session failed or ran out of budget" - else - reason="the session ended without a comment" - fi - body=$(printf "Hi, I'm the Playwright bot. I couldn't finish triaging this issue: %s. The agent run has the details.\n\n%s - [agent run](%s)\n" "$reason" "$FOOTER" "$RUN_URL") - comment=$(jq -n --arg repo "$GITHUB_REPOSITORY" --argjson issue "$ISSUE" --arg body "$body" '{call: "comment", repo: $repo, issue: $issue, body: $body}') - # A calls.json that is not an array is replaced: its calls would be rejected anyway. - jq --argjson comment "$comment" '. + [$comment]' "$CALLS" > "$CALLS.tmp" 2> /dev/null \ - || jq -n --argjson comment "$comment" '[$comment]' > "$CALLS.tmp" - mv "$CALLS.tmp" "$CALLS" - # Never execute code or scripts from the artifact in the app job. The calls are data. - - name: Check and make the calls - id: publish - uses: microsoft/playwright/.github/actions/publish-calls@d1518e3e3fca90352c4390814943cced496fd7e4 # main - with: - token: ${{ steps.app-token.outputs.token }} - dir: ${{ runner.temp }}/triage - - name: Hide the comment with the run link - if: ${{ !cancelled() && steps.publish.outputs.comment == 'true' && needs.start.outputs.comment != '' }} + owner: microsoft + repositories: devops.playwright.dev + permission-actions: write + - name: Start the bot env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - ID: ${{ needs.start.outputs.comment }} - run: | - gh api graphql -f query='mutation($id: ID!) { minimizeComment(input: { subjectId: $id, classifier: OUTDATED }) { clientMutationId } }' -f id="$ID" \ - || echo "::warning::Could not hide the comment with the run link" + NUMBER: ${{ github.event.issue.number }} + LABEL: ${{ github.event.label.name }} + run: >- + gh workflow run issue.yml --repo microsoft/devops.playwright.dev --ref main + -f repo="$GITHUB_REPOSITORY" -f issue="$NUMBER" -f label="$LABEL"