Skip to content

πŸ™Œ OpenHands: AI-Driven Development

ci(snapshot-tests): support pull_request events from forks (#633)

Robert Brennanb26e85ecba70
diff --git a/.github/workflows/snapshot-tests.yml b/.github/workflows/snapshot-tests.yml
index f561467857..b3cc280b9e 100644
--- a/.github/workflows/snapshot-tests.yml
+++ b/.github/workflows/snapshot-tests.yml
@@ -35,7 +35,16 @@ jobs:
- name: Check out repository
uses: actions/checkout@v6
with:
- ref: ${{ github.head_ref || github.ref_name }}
+ # On `pull_request` events `github.head_ref` is the head branch
+ # name β€” but it lives on the PR head repo, which is a fork for
+ # cross-repo PRs. Without `repository` set, actions/checkout
+ # defaults to `github.repository` (the upstream repo) and fails
+ # to find the branch. Resolve both the head repo and head SHA
+ # from the PR event payload so fork PRs check out cleanly.
+ # Falls back to the workflow's own ref for `push` /
+ # `workflow_dispatch` events where there's no PR payload.
+ repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
+ ref: ${{ github.event.pull_request.head.sha || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
diff --git a/tests/e2e/snapshots/scripts/post-snapshot-comment.mjs b/tests/e2e/snapshots/scripts/post-snapshot-comment.mjs
index 87372f3fb5..70427536f1 100644
--- a/tests/e2e/snapshots/scripts/post-snapshot-comment.mjs
+++ b/tests/e2e/snapshots/scripts/post-snapshot-comment.mjs
@@ -475,7 +475,20 @@ async function main() {
}
const body = buildComment(changed, newSnapshots, unchanged, commitSha);
- await postFreshComment(body);
+ // Commenting requires `pull-requests: write`. GitHub silently downgrades
+ // that to `read` for `pull_request` runs triggered from a fork, so the
+ // POST below 403s on cross-repo PRs. Treat the failure the same way
+ // publishImages already treats its push failure: log it and keep going
+ // so the workflow can still write `has_changes` and let the
+ // "Fail if differences" step do its job.
+ try {
+ await postFreshComment(body);
+ } catch (err) {
+ console.error(
+ "Warning: failed to post PR comment (expected on fork PRs):",
+ err.message,
+ );
+ }
// Tell the workflow whether there are actual pixel-diff failures so the
// "Fail if differences" step can distinguish changed snapshots (should