Skip to content

Commit 4106a90

Browse files
ci: skip Lighthouse audit when Netlify preview is not live (#2048)
1 parent ae6197f commit 4106a90

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

.github/workflows/lighthouse.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,26 @@ jobs:
2929
run: |
3030
PREVIEW_URL="https://deploy-preview-${{ github.event.pull_request.number }}--expressjscom-preview.netlify.app"
3131
echo "PREVIEW_URL=$PREVIEW_URL" >> "$GITHUB_ENV"
32-
for i in {1..4}; do
33-
if curl -s --head "$PREVIEW_URL" | grep "200 OK" > /dev/null; then
34-
echo "Preview is live!"
35-
break
32+
MAX_RETRIES=12
33+
DELAY=10
34+
35+
echo "Checking Netlify preview: $PREVIEW_URL"
36+
for i in $(seq 1 $MAX_RETRIES); do
37+
if curl -s --head --max-time 5 "$PREVIEW_URL" | grep "200 OK" > /dev/null; then
38+
echo "✅ Preview is live!"
39+
echo "skip_lighthouse=false" >> "$GITHUB_ENV"
40+
exit 0
3641
fi
37-
echo "Waiting for Netlify to deploy... ($i/4)"
38-
sleep 10
42+
echo "Waiting for Netlify to deploy... ($i/$MAX_RETRIES)"
43+
sleep $DELAY
3944
done
4045
46+
echo "❌ Preview not live after $((MAX_RETRIES*DELAY)) seconds."
47+
echo "skip_lighthouse=true" >> "$GITHUB_ENV"
48+
exit 0
49+
4150
- name: Run Lighthouse audits
51+
if: env.skip_lighthouse == 'false'
4252
run: |
4353
URLS=(
4454
"$PREVIEW_URL"
@@ -88,17 +98,20 @@ jobs:
8898
done
8999
90100
- name: Log Lighthouse report
101+
if: env.skip_lighthouse == 'false'
91102
run: |
92103
cat lighthouse-report.md
93104
94105
- name: Upload Lighthouse reports as artifacts
106+
if: env.skip_lighthouse == 'false'
95107
uses: actions/upload-artifact@v4
96108
with:
97109
name: lighthouse-reports
98110
path: |
99111
lighthouse-report.md
100112
101113
- name: Comment on PR with Lighthouse results
114+
if: env.skip_lighthouse == 'false'
102115
uses: actions/github-script@v7
103116
with:
104117
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)