π OpenHands: AI-Driven Development
ci: add .pr/ cleanup-after-merge and fork-aware notice (#17245)
OpenHands Bot373d355bc013
diff --git a/.github/workflows/pr-artifacts.yml b/.github/workflows/pr-artifacts.ymlindex f346b56fbc..c0f28f17e8 100644--- a/.github/workflows/pr-artifacts.yml+++ b/.github/workflows/pr-artifacts.yml@@ -2,16 +2,13 @@ name: PR Artifactson:workflow_dispatch:- pull_request:+ pull_request_target:types: [opened, synchronize, reopened, closed]branches:- mainpull_request_review:types: [submitted]-permissions:- contents: write-jobs:cleanup-on-approval:if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'@@ -153,47 +150,208 @@ jobs:}check-pr-artifacts:- if: github.event_name == 'pull_request'+ if: github.event_name == 'pull_request_target' && github.event.action != 'closed'runs-on: ubuntu-latestpermissions:contents: readissues: writepull-requests: writesteps:- - name: Check out repository- uses: actions/checkout@v7+ - name: Post or update PR artifacts comment+ uses: actions/github-script@v9+ with:+ script: |+ const marker = '<!-- pr-artifacts-notice -->';+ const pullRequest = context.payload.pull_request;+ const headRepository = pullRequest.head.repo;+ let exists = true;++ try {+ await github.rest.repos.getContent({+ owner: headRepository.owner.login,+ repo: headRepository.name,+ path: '.pr',+ ref: pullRequest.head.sha,+ });+ } catch (error) {+ if (error.status === 404) {+ exists = false;+ } else {+ throw error;+ }+ }++ const comments = await github.paginate(+ github.rest.issues.listComments,+ {+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: context.issue.number,+ per_page: 100,+ },+ );+ const existing = comments.find((comment) => comment.body.includes(marker));++ if (!exists) {+ if (existing) {+ await github.rest.issues.updateComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ comment_id: existing.id,+ body: [+ marker,+ '**PR Artifacts Cleaned Up**',+ '',+ 'The `.pr/` directory is no longer present.',+ '',+ ].join('\n'),+ });+ }+ return;+ }++ const isFork = headRepository.full_name !== context.payload.repository.full_name;+ const cleanup = isFork+ ? 'Because this is a fork PR, the workflow will **open or update a cleanup PR against `main` after merge**.'+ : 'The directory will be **automatically removed when the PR is approved**.';+ const body = [+ marker,+ '**PR Artifacts Notice**',+ '',+ 'This PR contains a `.pr/` directory with temporary PR-specific documents. ' + cleanup,+ '',+ ].join('\n');++ core.warning('.pr/ directory contains temporary PR-only artifacts');+ if (existing) {+ await github.rest.issues.updateComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ comment_id: existing.id,+ body,+ });+ } else {+ await github.rest.issues.createComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: context.issue.number,+ body,+ });+ }++ # Fork branches cannot be modified reliably. If artifacts reach the trusted base,+ # remove them through a pull request so branch protections remain enforced.+ cleanup-after-merge:+ concurrency:+ group: pr-artifacts-live-e2e-${{ github.event.pull_request.base.ref }}+ cancel-in-progress: false+ if: >-+ github.event_name == 'pull_request_target' &&+ github.event.action == 'closed' &&+ github.event.pull_request.merged == true+ runs-on: ubuntu-latest+ permissions:+ contents: write+ issues: write+ pull-requests: write+ steps:+ - uses: actions/checkout@v7+ with:+ ref: ${{ github.event.pull_request.base.ref }}+ token: ${{ secrets.OPENHANDS_BOT_GITHUB_PAT_PUBLIC }}- - name: Check for .pr directory- id: check+ - name: Create or update cleanup PR+ id: cleanup+ env:+ BASE_REF: ${{ github.event.pull_request.base.ref }}+ CLEANUP_BRANCH: automation/remove-pr-artifacts+ GH_TOKEN: ${{ secrets.OPENHANDS_BOT_GITHUB_PAT_PUBLIC }}run: |- if [ -d ".pr" ]; then- echo "exists=true" >> "$GITHUB_OUTPUT"- echo "::warning::.pr directory exists and will be automatically removed when the PR is approved. Fork PRs require manual cleanup before merging."- else- echo "exists=false" >> "$GITHUB_OUTPUT"+ set -euo pipefail+ if [ ! -d ".pr" ]; then+ echo "created=false" >> "$GITHUB_OUTPUT"+ echo "::notice::No .pr/ directory to remove from $BASE_REF"+ exit 0fi- - name: Post or update PR artifacts comment- if: steps.check.outputs.exists == 'true'+ git config user.name "allhands-bot"+ git config user.email "[email protected]"+ git fetch origin \+ "+refs/heads/$CLEANUP_BRANCH:refs/remotes/origin/$CLEANUP_BRANCH" || true+ git checkout -B "$CLEANUP_BRANCH"+ git rm -rf --ignore-unmatch .pr/+ if git diff --cached --quiet; then+ echo "created=false" >> "$GITHUB_OUTPUT"+ echo "::notice::No tracked .pr/ files to remove from $BASE_REF"+ exit 0+ fi+ git commit \+ -m "chore: remove merged PR artifacts" \+ -m "Co-authored-by: openhands <[email protected]>"+ git push --force-with-lease origin "HEAD:$CLEANUP_BRANCH"++ cleanup_pr_url=$(gh pr list \+ --base "$BASE_REF" \+ --head "$CLEANUP_BRANCH" \+ --state open \+ --json url \+ --jq '.[0].url')++ if [ -z "$cleanup_pr_url" ]; then+ cleanup_pr_url=$(gh pr create \+ --base "$BASE_REF" \+ --head "$CLEANUP_BRANCH" \+ --title "chore: remove merged PR artifacts" \+ --body-file - <<EOF+ ## Why++ Temporary \`.pr/\` artifacts reached \`$BASE_REF\` through one or more merged PRs.++ ## Summary++ - Remove the temporary \`.pr/\` directory from \`$BASE_REF\`.++ ## How to Test++ - Confirm this PR only deletes files under \`.pr/\`.+ - Let the required checks validate the cleanup commit.++ ---++ _This PR was automatically created by the PR Artifacts workflow._+ EOF+ )+ fi++ echo "created=true" >> "$GITHUB_OUTPUT"+ echo "pr_url=$cleanup_pr_url" >> "$GITHUB_OUTPUT"+ echo "::notice::Cleanup PR ready: $cleanup_pr_url"++ - name: Update source PR comment+ if: steps.cleanup.outputs.created == 'true'uses: actions/github-script@v9+ env:+ CLEANUP_PR_URL: ${{ steps.cleanup.outputs.pr_url }}with:script: |const marker = '<!-- pr-artifacts-notice -->';const body = [marker,- '**PR Artifacts Notice**',- '',- 'This PR contains a `.pr/` directory with PR-specific artifacts. This directory will be **automatically removed** when the PR is approved.',+ '**PR Artifact Cleanup Queued**','',- '> Fork PRs require manual cleanup before merging.',+ 'The `.pr/` directory reached `' + context.payload.pull_request.base.ref + '` after merge. A cleanup PR has been opened or updated: ' + process.env.CLEANUP_PR_URL,'',].join('\n');- const { data: comments } = await github.rest.issues.listComments({- owner: context.repo.owner,- repo: context.repo.repo,- issue_number: context.issue.number,- });+ const comments = await github.paginate(+ github.rest.issues.listComments,+ {+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: context.issue.number,+ per_page: 100,+ },+ );const existing = comments.find((comment) => comment.body.includes(marker));if (existing) {diff --git a/.github/workflows/pr-description-check.yml b/.github/workflows/pr-description-check.ymlindex 1460a32847..c73f8f3eaf 100644--- a/.github/workflows/pr-description-check.yml+++ b/.github/workflows/pr-description-check.yml@@ -19,8 +19,13 @@ jobs:# Run on drafts too so contributors can iterate on a passing description# before requesting review. Bots (dependabot, release-please) write their# own bodies and can't follow the HUMAN/AGENT template, so exempt them- # rather than failing every such PR.- if: github.event.pull_request.user.type != 'Bot'+ # rather than failing every such PR. The artifact-cleanup PR is generated+ # by a trusted workflow without the human-authored template, so exempt it too.+ if: >-+ github.event.pull_request.user.type != 'Bot' &&+ !(github.event.pull_request.head.repo.full_name == github.repository &&+ github.event.pull_request.base.ref == 'main' &&+ github.event.pull_request.head.ref == 'automation/remove-pr-artifacts')runs-on: ubuntu-24.04steps:- name: Checkout trusted workflow scriptsdiff --git a/AGENTS.md b/AGENTS.mdindex ee89afb009..259efc90e2 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -232,7 +232,7 @@ you are running inside of β NOT the automation backend.- Keep live E2E secrets out of job-level `env`. The workflow should check whether credentials exist before checkout, but inject the LLM key only into the trusted step that actually runs the live test.- The live job uploads the Playwright HTML report plus screenshot/video output as a GitHub Actions artifact, and also extracts the primary screenshot/video attachments. It converts the WebM recording to a GIF preview with `ffmpeg` so GitHub PR comments can inline the preview. Keep Playwright trace capture disabled for live tests because the setup flow sends LLM credentials to the Agent Server settings API, and traces can record request bodies. Failure messages around live Agent Server settings must not print response bodies from credential-bearing requests.- Inline PR-comment media is stored as PR-only files under `.pr/live-e2e/<github_run_id>/` on the PR branch, not on a long-lived orphan media branch. The comment uses `raw.githubusercontent.com/<repo>/<artifact_commit>/.pr/live-e2e/...` URLs for the GIF and PNG so GitHub can render them inline. The WebM is linked as the full recording because GitHub comments do not reliably inline WebM.-- `.github/workflows/pr-artifacts.yml` owns cleanup for `.pr/live-e2e/`: it comments when `.pr/` artifacts exist and removes them after PR approval for same-repo PRs (fork PRs require manual cleanup).+- `.github/workflows/pr-artifacts.yml` owns cleanup for `.pr/live-e2e/`: it comments when `.pr/` artifacts exist, removes them after PR approval for same-repo PRs, and opens or updates a cleanup PR against `main` if artifacts reach `main` through a fork PR or a missed approval cleanup.- The live reporting scripts live beside the live tests under `tests/e2e/live/scripts/`: `run-live-e2e.mjs`, `extract-live-e2e-media.mjs`, `render-live-e2e-report.mjs`, and `upsert-pr-comment.mjs`. Keep report/comment/local-runner logic there rather than in top-level `scripts/`, because these scripts are part of the live E2E framework.- When changing any part of this framework β live workflow triggers, artifact publishing, `.pr` cleanup, live Playwright config, live test file layout, helper locations, local runner behavior, or report/comment scripts β update this `AGENTS.md` section in the same PR so future agents have the current operating model.