mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-21 19:41:33 +00:00
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:
committed by
GitHub
parent
69c03457e9
commit
5df99fe254
22
.github/workflows/lighthouse.yml
vendored
22
.github/workflows/lighthouse.yml
vendored
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user