Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: post mock-LLM E2E PR comments for fork PRs via workflow_run (#1154)

Rohit Malhotra2c6ff4bc8496
diff --git a/.github/workflows/mock-llm-e2e-comment.yml b/.github/workflows/mock-llm-e2e-comment.yml
new file mode 100644
index 0000000000..fe3e945eaa
--- /dev/null
+++ b/.github/workflows/mock-llm-e2e-comment.yml
@@ -0,0 +1,52 @@
+# Post Mock-LLM E2E test report as a PR comment.
+#
+# Triggered by `workflow_run` so it executes in the context of the base
+# repository with write permissions β€” necessary for fork PRs where the
+# `pull_request` token is read-only.
+#
+# Same-repo PRs already get an inline comment from the test workflow
+# itself; this workflow covers the fork-PR gap. It is safe because it
+# never checks out or executes PR code β€” it only downloads the rendered
+# report artifact and posts it.
+
+name: "Mock-LLM E2E: Post PR Comment"
+
+on:
+ workflow_run:
+ workflows: ["Mock-LLM E2E Tests"]
+ types: [completed]
+
+permissions:
+ pull-requests: write
+
+jobs:
+ post-comment:
+ name: Post PR comment
+ runs-on: ubuntu-24.04
+ # Only run for fork PRs β€” same-repo PRs are handled inline.
+ if: >-
+ github.event.workflow_run.event == 'pull_request' &&
+ github.event.workflow_run.head_repository.full_name != github.repository
+ steps:
+ - name: Download PR comment payload
+ uses: actions/download-artifact@v4
+ id: download
+ with:
+ name: mock-llm-pr-comment-payload
+ run-id: ${{ github.event.workflow_run.id }}
+ github-token: ${{ github.token }}
+ continue-on-error: true
+
+ - name: Post comment
+ if: steps.download.outcome == 'success'
+ continue-on-error: true
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ run: |
+ PR_NUMBER=$(cat pr_number.txt)
+ if [ -z "$PR_NUMBER" ]; then
+ echo "::warning::Could not determine PR number; skipping comment."
+ exit 0
+ fi
+ gh pr comment "$PR_NUMBER" --body-file mock-llm-report.md
diff --git a/.github/workflows/mock-llm-e2e.yml b/.github/workflows/mock-llm-e2e.yml
index 5890777ce6..d4bba03a84 100644
--- a/.github/workflows/mock-llm-e2e.yml
+++ b/.github/workflows/mock-llm-e2e.yml
@@ -199,8 +199,26 @@ jobs:
--artifact-url "${{ steps.upload_artifacts.outputs.artifact-url || '' }}"
cat "$MOCK_LLM_REPORT_PATH" >> "$GITHUB_STEP_SUMMARY"
- - name: Post PR comment
+ - name: Save PR number for comment workflow
if: always() && github.event.pull_request.number
+ run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
+
+ - name: Upload PR comment payload
+ if: always() && github.event.pull_request.number
+ uses: actions/upload-artifact@v7
+ with:
+ name: mock-llm-pr-comment-payload
+ retention-days: 3
+ path: |
+ ${{ env.MOCK_LLM_REPORT_PATH }}
+ pr_number.txt
+
+ - name: Post PR comment (same-repo PRs only)
+ if: >-
+ always() &&
+ github.event.pull_request.number &&
+ github.event.pull_request.head.repo.full_name == github.repository
+ continue-on-error: true
env:
GITHUB_TOKEN: ${{ github.token }}
run: |