Skip to content

Commit 9202c36

Browse files
authored
meta: skip lighthouse CI when no vercel preview detected (#7266)
Update lighthouse.yml Signed-off-by: Aviv Keller <redyetidev@gmail.com>
1 parent fbd443d commit 9202c36

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

.github/workflows/lighthouse.yml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,39 @@ permissions:
2727
pull-requests: write
2828

2929
jobs:
30-
lighthouse-ci:
30+
get-vercel-preview:
3131
# We want to skip our lighthouse analysis on Dependabot PRs
3232
if: |
3333
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false &&
3434
github.event.label.name == 'github_actions:pull-request'
35+
name: Get Vercel Preview
36+
runs-on: ubuntu-latest
37+
outputs:
38+
deployment_found: ${{ steps.check_deployment.outputs.deployment_found }}
39+
url: ${{ steps.check_deployment.outputs.url }}
40+
steps:
41+
- name: Capture Vercel Preview
42+
id: check_deployment
43+
uses: patrickedqvist/wait-for-vercel-preview@06c79330064b0e6ef7a2574603b62d3c98789125 # v1.3.2
44+
with:
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
max_timeout: 300 # timeout after 5 minutes
47+
check_interval: 10 # check every 10 seconds
48+
continue-on-error: true
49+
- name: Set Outputs
50+
if: always()
51+
id: set_outputs
52+
run: |
53+
if [[ -z "${{ steps.check_deployment.outputs.url }}" ]]; then
54+
echo "deployment_found=false" >> $GITHUB_OUTPUT
55+
else
56+
echo "deployment_found=true" >> $GITHUB_OUTPUT
57+
echo "url=${{ steps.check_deployment.outputs.url }}" >> $GITHUB_OUTPUT
58+
fi
3559
60+
lighthouse-ci:
61+
needs: get-vercel-preview
62+
if: needs.get-vercel-preview.outputs.deployment_found == 'true'
3663
name: Lighthouse Report
3764
runs-on: ubuntu-latest
3865

@@ -57,16 +84,6 @@ jobs:
5784
# Used later to edit the existing comment
5885
comment-tag: 'lighthouse_audit'
5986

60-
- name: Capture Vercel Preview
61-
uses: patrickedqvist/wait-for-vercel-preview@06c79330064b0e6ef7a2574603b62d3c98789125 # v1.3.2
62-
id: vercel_preview_url
63-
with:
64-
token: ${{ secrets.GITHUB_TOKEN }}
65-
# timeout after 5 minutes
66-
max_timeout: 300
67-
# check every 10 seconds
68-
check_interval: 10
69-
7087
- name: Audit Preview URL with Lighthouse
7188
# Conduct the lighthouse audit
7289
id: lighthouse_audit
@@ -76,11 +93,11 @@ jobs:
7693
configPath: './.lighthouserc.json'
7794
# These URLS capture critical pages / site functionality.
7895
urls: |
79-
${{ steps.vercel_preview_url.outputs.url }}/en
80-
${{ steps.vercel_preview_url.outputs.url }}/en/about
81-
${{ steps.vercel_preview_url.outputs.url }}/en/about/previous-releases
82-
${{ steps.vercel_preview_url.outputs.url }}/en/download
83-
${{ steps.vercel_preview_url.outputs.url }}/en/blog
96+
${{ needs.get-vercel-preview.outputs.url }}/en
97+
${{ needs.get-vercel-preview.outputs.url }}/en/about
98+
${{ needs.get-vercel-preview.outputs.url }}/en/about/previous-releases
99+
${{ needs.get-vercel-preview.outputs.url }}/en/download
100+
${{ needs.get-vercel-preview.outputs.url }}/en/blog
84101
uploadArtifacts: true # save results as a action artifacts
85102
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
86103

@@ -93,7 +110,7 @@ jobs:
93110
# see https://github.com/actions/github-script#use-env-as-input
94111
LIGHTHOUSE_RESULT: ${{ steps.lighthouse_audit.outputs.manifest }}
95112
LIGHTHOUSE_LINKS: ${{ steps.lighthouse_audit.outputs.links }}
96-
VERCEL_PREVIEW_URL: ${{ steps.vercel_preview_url.outputs.url }}
113+
VERCEL_PREVIEW_URL: ${{ needs.get-vercel-preview.outputs.url }}
97114
with:
98115
# Run as a separate file so we do not have to inline all of our formatting logic.
99116
# See https://github.com/actions/github-script#run-a-separate-file for more info.

0 commit comments

Comments
 (0)