Skip to content

Fix lighthouse_comment workflow to handle workflow_run event context#315

Open
Copilot wants to merge 7 commits intomainfrom
copilot/fix-lighthouse-github-action-run
Open

Fix lighthouse_comment workflow to handle workflow_run event context#315
Copilot wants to merge 7 commits intomainfrom
copilot/fix-lighthouse-github-action-run

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 3, 2026

The lighthouse_comment.yml workflow fails to post PR comments because it accesses github.event.pull_request.number, which doesn't exist in workflow_run trigger contexts.

Changes

Artifact download

  • Added run-id: ${{ github.event.workflow_run.id }} to download artifacts from the triggering workflow run

PR number extraction

  • Extract from github.event.workflow_run.pull_requests[0].number with null/empty validation
  • Fail early with descriptive error if extraction fails

Execution control

  • Added if: github.event.workflow_run.conclusion == 'success' to skip commenting on failed runs
- name: Extract PR number
  id: pr
  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"
      exit 1
    fi
    echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT

- name: Post Lighthouse comment
  uses: peter-evans/create-or-update-comment@v4
  with:
    issue-number: ${{ steps.pr.outputs.number }}
    body-path: lighthouse-comment.md
Original prompt

Hey copilot, currently there is a problem in the lighthouse github actions, there are two actions are there run and comment, the comment is working but the run is not working, please help me to fix the issues


💡 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.

Copilot AI and others added 5 commits February 3, 2026 15:50
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>
Copilot AI changed the title [WIP] Fix run action issue in lighthouse GitHub Actions Fix lighthouse_comment workflow to use workflow_run event context Feb 3, 2026
Copilot AI requested a review from Achanandhi-M February 3, 2026 15:57
Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com>
Copilot AI changed the title Fix lighthouse_comment workflow to use workflow_run event context Fix lighthouse_comment workflow to handle workflow_run event context Feb 3, 2026
@Achanandhi-M Achanandhi-M marked this pull request as ready for review February 3, 2026 16:04
Copilot AI review requested due to automatic review settings February 3, 2026 16:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].number with 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.

@dhananjay6561 dhananjay6561 requested review from Copilot and removed request for Achanandhi-M April 6, 2026 12:05
@dhananjay6561
Copy link
Copy Markdown
Member

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:

Correctly extracts PR number from workflow_run event context.

We'll get this merged in soon. Keep the great work coming! 🚀

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 24 to +28
- name: Download Lighthouse comment artifact
uses: actions/download-artifact@v4
with:
name: lighthouse-comment
path: .
run-id: ${{ github.event.workflow_run.id }}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants