ci: fix multiple comments in Lighthouse workflow (#2030)

* ci: fix multiple comments in Lighthouse workflow

Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>

* fix comment

---------

Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
Co-authored-by: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com>
This commit is contained in:
Sebastian Beltran
2025-08-03 22:46:56 -05:00
committed by GitHub
parent 69c03457e9
commit 5df99fe254

View File

@@ -29,12 +29,12 @@ jobs:
run: |
PREVIEW_URL="https://deploy-preview-${{ github.event.pull_request.number }}--expressjscom-preview.netlify.app"
echo "PREVIEW_URL=$PREVIEW_URL" >> "$GITHUB_ENV"
for i in {1..2}; do
for i in {1..4}; do
if curl -s --head "$PREVIEW_URL" | grep "200 OK" > /dev/null; then
echo "Preview is live!"
break
fi
echo "Waiting for Netlify to deploy... ($i/2)"
echo "Waiting for Netlify to deploy... ($i/4)"
sleep 10
done
@@ -60,6 +60,7 @@ jobs:
npx lighthouse "$url" \
$lighthouse_args \
--only-categories=performance,accessibility,best-practices \
--output json \
--output-path="lighthouse-report-${device}.json" \
--chrome-flags="--headless"
@@ -104,31 +105,32 @@ jobs:
script: |
const fs = require('fs');
const report = fs.readFileSync('lighthouse-report.md', 'utf8');
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚦Lighthouse Results')
comment.user.type === "Bot" &&
comment.body.includes("🚦 Lighthouse Results")
);
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
body: report,
});
console.log("Updated existing Lighthouse comment.");
} else {
await github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
body: report,
});
console.log("Created new Lighthouse comment.");
}