Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/lighthouse_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@ permissions:
jobs:
comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'

steps:
# Download artifacts from the completed "Lighthouse – Run" workflow
# The run-id parameter is critical - it specifies to download from the
# triggering workflow run, not the current workflow (which has no artifacts)
# Note: github-token is not needed as the default GITHUB_TOKEN has sufficient
# permissions to download artifacts from the same repository
- name: Download Lighthouse comment artifact
uses: actions/download-artifact@v4
with:
name: lighthouse-comment
path: .
run-id: ${{ github.event.workflow_run.id }}
Comment on lines 24 to +28
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.

- name: Ensure comment file exists
run: test -f lighthouse-comment.md

- 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"
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.
exit 1
fi
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT

- name: Post Lighthouse comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
issue-number: ${{ steps.pr.outputs.number }}
body-path: lighthouse-comment.md
edit-mode: replace