Skip to content

Commit 06f87a5

Browse files
committed
refactor(lighthouse-ci): drop PR-commenting logic from report script
Rename post-comment.mjs to report.mjs and remove all PR-commenting code paths (octokit, listComments + find-and-update, GITHUB_TOKEN handling, fork-403 fallback, IS_PR / PR_NUMBER env vars). The Lighthouse workflow no longer runs on pull_request triggers (see the previous commit), so this code was dead. The script now does one thing: read .lighthouseci/ artifacts, build the markdown report, and write it to $GITHUB_STEP_SUMMARY via core.summary. That panel renders at the top of the workflow run page and is the workflow's only public output. Also drop the @actions/github dependency from dev-packages/lighthouse-tests/package.json — it was only used by the deleted octokit calls. yarn.lock retains an orphaned "@actions/github@^5.0.0" entry that the existing 9.x usage in other gh-action packages doesn't touch; left for natural cleanup on the next clean install.
1 parent 7c24cff commit 06f87a5

2 files changed

Lines changed: 4 additions & 63 deletions

File tree

dev-packages/lighthouse-tests/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
},
1212
"dependencies": {
1313
"@actions/core": "1.10.1",
14-
"@actions/github": "^5.0.0",
1514
"markdown-table": "3.0.3"
1615
}
1716
}

dev-packages/lighthouse-tests/report.mjs

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { promises as fs } from 'node:fs';
22
import path from 'node:path';
33
import * as core from '@actions/core';
4-
import { context, getOctokit } from '@actions/github';
54
import { markdownTable } from 'markdown-table';
65

76
const HEADING = '## 🔦 Lighthouse Report';
87
const MODES = ['no-sentry', 'init-only', 'tracing-replay'];
98

10-
/**
11-
* Apps and their human-readable SDK labels, matching lighthouse-matrix.mjs.
12-
* Order here determines row order in each table.
13-
*/
149
// Must mirror the APPS array in lighthouse-matrix.mjs. Only apps whose Sentry init
1510
// code actually branches on SENTRY_LIGHTHOUSE_MODE are listed here — listing
1611
// uninstrumented apps would dilute the 50%-fill safety check below and produce
@@ -108,8 +103,6 @@ function buildSectionTable(rows, metric, unit) {
108103

109104
async function run() {
110105
const resultsDir = process.env.LIGHTHOUSE_RESULTS_DIR || 'lighthouse-results';
111-
const isPR = process.env.IS_PR === 'true';
112-
const prNumber = process.env.PR_NUMBER ? Number(process.env.PR_NUMBER) : undefined;
113106

114107
const rows = [];
115108
let totalCells = 0;
@@ -126,7 +119,7 @@ async function run() {
126119
}
127120

128121
if (totalCells > 0 && filledCells / totalCells < 0.5) {
129-
core.warning(`Only ${filledCells}/${totalCells} Lighthouse cells have results (< 50%). Skipping comment.`);
122+
core.warning(`Only ${filledCells}/${totalCells} Lighthouse cells have results (< 50%). Skipping report.`);
130123
return;
131124
}
132125

@@ -144,62 +137,11 @@ async function run() {
144137

145138
const body = `${HEADING}\n\n${tables}${footer}`;
146139

147-
// Always render the report as a GitHub Actions Job Summary so it's visible on the
148-
// workflow run page for every trigger (PR, nightly, dispatch). For PR runs we also
149-
// post/update a sticky comment on the PR below.
140+
// Render the report as a GitHub Actions Job Summary so it's visible on the workflow
141+
// run page. This is the workflow's only public output — there is intentionally no
142+
// PR comment (the workflow doesn't run on PRs; see lighthouse.yml).
150143
await core.summary.addRaw(body).write();
151144
core.info('Wrote Lighthouse report to Job Summary.');
152-
153-
if (!isPR || !prNumber) {
154-
// Nightly / non-PR: Job Summary above is the only output. Nothing to post.
155-
return;
156-
}
157-
158-
const token = process.env.GITHUB_TOKEN;
159-
if (!token) {
160-
core.warning('GITHUB_TOKEN not set — cannot post PR comment.');
161-
return;
162-
}
163-
164-
const octokit = getOctokit(token);
165-
const repo = context.repo;
166-
167-
// Find existing Lighthouse comment to update (mirror size-limit-gh-action pattern)
168-
const { data: comments } = await octokit.rest.issues.listComments({
169-
...repo,
170-
issue_number: prNumber,
171-
});
172-
const existing = comments.find(c => c.body?.startsWith(HEADING));
173-
174-
try {
175-
if (existing) {
176-
await octokit.rest.issues.updateComment({
177-
...repo,
178-
comment_id: existing.id,
179-
body,
180-
});
181-
core.info('Updated existing Lighthouse comment.');
182-
} else {
183-
await octokit.rest.issues.createComment({
184-
...repo,
185-
issue_number: prNumber,
186-
body,
187-
});
188-
core.info('Created Lighthouse PR comment.');
189-
}
190-
} catch (err) {
191-
if (err.status === 403) {
192-
// Fork PRs: GITHUB_TOKEN is read-only. Log the table to the workflow log so the
193-
// data is still discoverable, and exit 0 so the job doesn't fail.
194-
core.warning(
195-
'Could not post PR comment (403 Forbidden). This is expected for fork PRs where GITHUB_TOKEN is read-only.',
196-
);
197-
// eslint-disable-next-line no-console
198-
console.log(`\n${body}`);
199-
return;
200-
}
201-
throw err;
202-
}
203145
}
204146

205147
run().catch(err => {

0 commit comments

Comments
 (0)