Fix lighthouse_comment workflow to handle workflow_run event context#315
Fix lighthouse_comment workflow to handle workflow_run event context#315
Conversation
Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
…dundant token Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
…ents Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the lighthouse_comment.yml workflow to correctly handle workflow_run event contexts. The workflow previously failed because it tried to access github.event.pull_request.number, which doesn't exist when triggered by a workflow_run event.
Changes:
- Added execution control to only run on successful workflow runs
- Configured artifact download to fetch from the triggering workflow run using
run-id - Implemented PR number extraction from
workflow_run.pull_requests[0].numberwith proper validation - Updated comment posting to use the dynamically extracted PR number
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @copilot-swe-agent 👋 — thanks so much for contributing to the project, really appreciate it! Your PR looks great and has been marked for merging. Here's a quick note from the reviewer:
We'll get this merged in soon. Keep the great work coming! 🚀 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Download Lighthouse comment artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: lighthouse-comment | ||
| path: . | ||
| run-id: ${{ github.event.workflow_run.id }} |
There was a problem hiding this comment.
actions/download-artifact@v4 with run-id calls the Actions Artifacts API; with the workflow-level permissions: block present, the default GITHUB_TOKEN no longer has implicit actions: read. This will typically fail with Resource not accessible by integration. Add actions: read (or remove the explicit permissions block and set least-privilege explicitly including actions: read) so the artifact download can succeed.
| run: | | ||
| PR_NUMBER=$(jq -r '.workflow_run.pull_requests[0].number' <<< '${{ toJSON(github.event) }}') | ||
| if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then | ||
| echo "❌ Error: Could not extract PR number from workflow run event" |
There was a problem hiding this comment.
The failure message for missing PR number is descriptive but doesn’t suggest a next step. Consider expanding it to include likely causes (e.g., the triggering run wasn’t associated with a PR, or workflow_run.pull_requests was empty) and what to check (triggering workflow event type / repository settings) to speed up triage.
| echo "❌ Error: Could not extract PR number from workflow run event" | |
| echo "❌ Error: Could not extract a PR number from the workflow_run event. This usually means the triggering workflow run was not associated with a pull request or workflow_run.pull_requests was empty. Next, check that the upstream \"Lighthouse – Run\" workflow was triggered by a pull_request-related event and confirm the repository/workflow settings allow PR context to be included in workflow_run payloads." |
The
lighthouse_comment.ymlworkflow fails to post PR comments because it accessesgithub.event.pull_request.number, which doesn't exist inworkflow_runtrigger contexts.Changes
Artifact download
run-id: ${{ github.event.workflow_run.id }}to download artifacts from the triggering workflow runPR number extraction
github.event.workflow_run.pull_requests[0].numberwith null/empty validationExecution control
if: github.event.workflow_run.conclusion == 'success'to skip commenting on failed runsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.