From 180e95b1c3e69af8896d8ffd15b08ee54f549144 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:47:17 +0000 Subject: [PATCH 1/7] Initial plan From 9337f2003693f8a36c6c253be0e54a065bbdfb28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:50:18 +0000 Subject: [PATCH 2/7] Fix lighthouse_comment.yml to properly handle workflow_run event Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/workflows/lighthouse_comment.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lighthouse_comment.yml b/.github/workflows/lighthouse_comment.yml index 403ac4e7..821b614c 100644 --- a/.github/workflows/lighthouse_comment.yml +++ b/.github/workflows/lighthouse_comment.yml @@ -13,20 +13,28 @@ permissions: jobs: comment: runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' steps: - name: Download Lighthouse comment artifact uses: actions/download-artifact@v4 with: name: lighthouse-comment - path: . + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} - 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) }}') + 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 From 2289cc15717ba0a7336a0d83481c0f0b0263e326 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:51:13 +0000 Subject: [PATCH 3/7] Add documentation for Lighthouse workflow fix Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/LIGHTHOUSE_FIX.md | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/LIGHTHOUSE_FIX.md diff --git a/.github/LIGHTHOUSE_FIX.md b/.github/LIGHTHOUSE_FIX.md new file mode 100644 index 00000000..3ba40ca8 --- /dev/null +++ b/.github/LIGHTHOUSE_FIX.md @@ -0,0 +1,80 @@ +# Lighthouse Workflow Fix Documentation + +## Problem +The Lighthouse GitHub Actions had two workflows: +1. **lighthouse_runner.yml** - Runs Lighthouse audits +2. **lighthouse_comment.yml** - Posts results as PR comments + +The comment workflow was working, but there were issues with how it accessed the PR context. + +## Root Cause +The `lighthouse_comment.yml` workflow is triggered by the `workflow_run` event (when "Lighthouse – Run" completes). However, it was trying to access `${{ github.event.pull_request.number }}`, which is **not available** in a `workflow_run` context. + +In a `workflow_run` event: +- `github.event.pull_request` is NOT available +- PR information must be extracted from `github.event.workflow_run.pull_requests` + +## Changes Made + +### 1. Fixed Artifact Download +```yaml +- name: Download Lighthouse comment artifact + uses: actions/download-artifact@v4 + with: + name: lighthouse-comment + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} # Added: Download from triggering workflow +``` + +### 2. Added PR Number Extraction +```yaml +- name: Extract PR number + id: pr + run: | + PR_NUMBER=$(jq -r '.workflow_run.pull_requests[0].number' <<< '${{ toJSON(github.event) }}') + echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT +``` + +### 3. Updated Comment Step +```yaml +- name: Post Lighthouse comment + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ steps.pr.outputs.number }} # Changed: Use extracted PR number + body-path: lighthouse-comment.md + edit-mode: replace +``` + +### 4. Added Success Check +```yaml +jobs: + comment: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' # Only run if lighthouse succeeded +``` + +## How It Works Now + +1. When a PR is opened/updated, `lighthouse_runner.yml` runs: + - Builds and starts PR branch on port 3001 + - Builds and starts main branch on port 3000 + - Runs Lighthouse audits on both + - Generates comparison report + - Uploads report as artifact + +2. When the runner completes, `lighthouse_comment.yml` triggers: + - Downloads artifact from the completed workflow run (using `run-id`) + - Extracts PR number from the workflow run event + - Posts the Lighthouse comparison as a PR comment + +## Additional Notes + +### "action_required" Status +If you see "action_required" status on workflow runs from forked repositories, this is normal GitHub behavior. The workflow requires manual approval from a maintainer before it can run. This is a security feature to prevent malicious code execution from forks. + +### Permissions +The workflows use minimal permissions: +- `lighthouse_runner.yml`: `contents: read` +- `lighthouse_comment.yml`: `issues: write`, `pull-requests: write` + +This follows the principle of least privilege for security. From cc8488158443f446b07149810631677f7c097224 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:52:10 +0000 Subject: [PATCH 4/7] Address code review feedback - add PR number validation and remove redundant token Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/workflows/lighthouse_comment.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse_comment.yml b/.github/workflows/lighthouse_comment.yml index 821b614c..447e9617 100644 --- a/.github/workflows/lighthouse_comment.yml +++ b/.github/workflows/lighthouse_comment.yml @@ -20,7 +20,6 @@ jobs: uses: actions/download-artifact@v4 with: name: lighthouse-comment - github-token: ${{ secrets.GITHUB_TOKEN }} run-id: ${{ github.event.workflow_run.id }} - name: Ensure comment file exists @@ -30,6 +29,10 @@ jobs: 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 From a51097747f32ec12cf2b649f8661e37b1aac4b0f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:53:17 +0000 Subject: [PATCH 5/7] Update documentation to match implementation and add explanatory comments Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/LIGHTHOUSE_FIX.md | 13 ++++++++++--- .github/workflows/lighthouse_comment.yml | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/LIGHTHOUSE_FIX.md b/.github/LIGHTHOUSE_FIX.md index 3ba40ca8..5e793f77 100644 --- a/.github/LIGHTHOUSE_FIX.md +++ b/.github/LIGHTHOUSE_FIX.md @@ -22,19 +22,26 @@ In a `workflow_run` event: uses: actions/download-artifact@v4 with: name: lighthouse-comment - github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} # Added: Download from triggering workflow + run-id: ${{ github.event.workflow_run.id }} # Download from triggering workflow ``` -### 2. Added PR Number Extraction +The `run-id` parameter is crucial - it specifies which workflow run's artifacts to download. Without it, the action would try to download from the current workflow (which has no artifacts). + +### 2. Added PR Number Extraction with Validation ```yaml - 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 ``` +This step extracts the PR number from the workflow run event and validates that it exists. If the extraction fails, the workflow will fail with a clear error message. + ### 3. Updated Comment Step ```yaml - name: Post Lighthouse comment diff --git a/.github/workflows/lighthouse_comment.yml b/.github/workflows/lighthouse_comment.yml index 447e9617..0c9080ae 100644 --- a/.github/workflows/lighthouse_comment.yml +++ b/.github/workflows/lighthouse_comment.yml @@ -16,6 +16,9 @@ jobs: 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) - name: Download Lighthouse comment artifact uses: actions/download-artifact@v4 with: From 4a4ef7de9629ba5e21d60da6d3aa58cea9a324c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:54:33 +0000 Subject: [PATCH 6/7] Add clarification about github-token not being needed Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/workflows/lighthouse_comment.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lighthouse_comment.yml b/.github/workflows/lighthouse_comment.yml index 0c9080ae..04cb4802 100644 --- a/.github/workflows/lighthouse_comment.yml +++ b/.github/workflows/lighthouse_comment.yml @@ -19,6 +19,8 @@ jobs: # 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: From 5202ddf9ac65f585b752e26012c3155458cef92b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 16:02:18 +0000 Subject: [PATCH 7/7] Remove .github/LIGHTHOUSE_FIX.md documentation file Co-authored-by: Achanandhi-M <110651321+Achanandhi-M@users.noreply.github.com> --- .github/LIGHTHOUSE_FIX.md | 87 --------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 .github/LIGHTHOUSE_FIX.md diff --git a/.github/LIGHTHOUSE_FIX.md b/.github/LIGHTHOUSE_FIX.md deleted file mode 100644 index 5e793f77..00000000 --- a/.github/LIGHTHOUSE_FIX.md +++ /dev/null @@ -1,87 +0,0 @@ -# Lighthouse Workflow Fix Documentation - -## Problem -The Lighthouse GitHub Actions had two workflows: -1. **lighthouse_runner.yml** - Runs Lighthouse audits -2. **lighthouse_comment.yml** - Posts results as PR comments - -The comment workflow was working, but there were issues with how it accessed the PR context. - -## Root Cause -The `lighthouse_comment.yml` workflow is triggered by the `workflow_run` event (when "Lighthouse – Run" completes). However, it was trying to access `${{ github.event.pull_request.number }}`, which is **not available** in a `workflow_run` context. - -In a `workflow_run` event: -- `github.event.pull_request` is NOT available -- PR information must be extracted from `github.event.workflow_run.pull_requests` - -## Changes Made - -### 1. Fixed Artifact Download -```yaml -- name: Download Lighthouse comment artifact - uses: actions/download-artifact@v4 - with: - name: lighthouse-comment - run-id: ${{ github.event.workflow_run.id }} # Download from triggering workflow -``` - -The `run-id` parameter is crucial - it specifies which workflow run's artifacts to download. Without it, the action would try to download from the current workflow (which has no artifacts). - -### 2. Added PR Number Extraction with Validation -```yaml -- 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 -``` - -This step extracts the PR number from the workflow run event and validates that it exists. If the extraction fails, the workflow will fail with a clear error message. - -### 3. Updated Comment Step -```yaml -- name: Post Lighthouse comment - uses: peter-evans/create-or-update-comment@v4 - with: - issue-number: ${{ steps.pr.outputs.number }} # Changed: Use extracted PR number - body-path: lighthouse-comment.md - edit-mode: replace -``` - -### 4. Added Success Check -```yaml -jobs: - comment: - runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion == 'success' # Only run if lighthouse succeeded -``` - -## How It Works Now - -1. When a PR is opened/updated, `lighthouse_runner.yml` runs: - - Builds and starts PR branch on port 3001 - - Builds and starts main branch on port 3000 - - Runs Lighthouse audits on both - - Generates comparison report - - Uploads report as artifact - -2. When the runner completes, `lighthouse_comment.yml` triggers: - - Downloads artifact from the completed workflow run (using `run-id`) - - Extracts PR number from the workflow run event - - Posts the Lighthouse comparison as a PR comment - -## Additional Notes - -### "action_required" Status -If you see "action_required" status on workflow runs from forked repositories, this is normal GitHub behavior. The workflow requires manual approval from a maintainer before it can run. This is a security feature to prevent malicious code execution from forks. - -### Permissions -The workflows use minimal permissions: -- `lighthouse_runner.yml`: `contents: read` -- `lighthouse_comment.yml`: `issues: write`, `pull-requests: write` - -This follows the principle of least privilege for security.