44 pull_request :
55 branches :
66 - main
7+
78permissions :
89 contents : read
910 pull-requests : write
@@ -19,10 +20,10 @@ jobs:
1920 runs-on : ubuntu-latest
2021 steps :
2122 - name : Checkout repository
22- uses : actions/checkout@v2
23+ uses : actions/checkout@v4
2324
2425 - name : Setup Node
25- uses : actions/setup-node@v2
26+ uses : actions/setup-node@v4
2627 with :
2728 node-version-file : ' .nvmrc'
2829 registry-url : ' https://registry.npmjs.org'
6061 - name : Install Lighthouse CI
6162 run : yarn add --dev @lhci/cli
6263
63- - name : Run bootstrap
64- run : yarn osd bootstrap
65-
6664 - name : Build plugins
6765 run : node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12
6866
@@ -72,25 +70,21 @@ jobs:
7270 echo "Waiting for OpenSearch..."
7371 sleep 10
7472 done
75- echo "OpenSearch is up!"
7673
7774 - name : Start OpenSearch Dashboards
7875 run : |
79- yarn start --no-base-path &
76+ yarn start --no-base-path --opensearch.ignoreVersionMismatch=true &
8077 until curl -s http://localhost:5601 >/dev/null; do
8178 echo "Waiting for OpenSearch Dashboards..."
8279 sleep 10
8380 done
84- echo "OpenSearch Dashboards is up!"
8581
8682 - name : Mock data
8783 run : |
8884 curl 'http://localhost:5601/api/sample_data/ecommerce' -X 'POST' -H 'osd-version: ${{ env.VERSION }}' -H 'osd-xsrf: osd-fetch'
8985
9086 - name : Run Lighthouse CI
91- run : |
92- export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
93- yarn lhci autorun --verbose
87+ run : yarn lhci autorun --verbose
9488 continue-on-error : true
9589
9690 - name : Ensure Lighthouse Reports Exist
@@ -101,68 +95,42 @@ jobs:
10195 echo "[]" > .lighthouseci/assertion-results.json
10296 fi
10397
98+ - name : List contents of .lighthouseci
99+ run : ls -R .lighthouseci || echo "Directory not found"
100+
104101 - name : Verify Lighthouse Results
102+ id : verify_lighthouse
105103 run : |
106- if [ ! -d ".lighthouseci" ] || [ -z "$(ls -A .lighthouseci)" ]; then
107- echo "❌ Lighthouse CI did not generate reports."
108- exit 1
104+ if [ ! -s ".lighthouseci/assertion-results.json" ]; then
105+ echo "❌ Lighthouse assertion-results.json is empty. Skipping further steps."
106+ echo "should_continue=false" >> $GITHUB_OUTPUT
107+ else
108+ echo "✅ Valid Lighthouse results found."
109+ echo "should_continue=true" >> $GITHUB_OUTPUT
109110 fi
110111
111- - name : Post Lighthouse Results into comment
112+ - name : Save Lighthouse Results as Artifact
113+ if : steps.verify_lighthouse.outputs.should_continue == 'true'
112114 run : |
113- # Validate if empty
114- if [ ! -s .lighthouseci/assertion-results.json ]; then
115- echo "❌ No assertion results found. Skipping PR comment."
116- exit 0 #Prevents failure
117- fi
115+ mkdir -p artifacts
116+ cp .lighthouseci/assertion-results.json artifacts/
117+
118+ - name : Upload Lighthouse Results Artifact
119+ if : steps.verify_lighthouse.outputs.should_continue == 'true'
120+ uses : actions/upload-artifact@v4
121+ with :
122+ name : lighthouse-results
123+ path : artifacts/assertion-results.json
118124
119- # Ensure JSON is properly formatted
120- if ! jq empty .lighthouseci/assertion-results.json; then
121- echo "❌ Invalid JSON format in Lighthouse assertion results."
122- cat .lighthouseci/assertion-results.json # Print for debugging
125+ - name : Fail CI if Lighthouse assertion results indicate failures
126+ if : steps.verify_lighthouse.outputs.should_continue == 'true'
127+ run : |
128+ if jq -e '[.[] | select(.passed==false)] | length > 0' .lighthouseci/assertion-results.json > /dev/null; then
129+ echo "❌ Lighthouse CI detected performance issues. Failing the job."
123130 exit 1
131+ else
132+ echo "✅ All Lighthouse metrics passed."
124133 fi
125134
126- BASELINE=$(cat ./baselines/lighthouse_baseline.json)
127-
128- FAILURES=$(jq --argjson baseline "$BASELINE" -r '[.[] | select(.passed==false) | {metric: .auditId, expected: ($baseline[(.url | sub("^.*?//[^/]+"; ""))][.auditId] // "N/A"), actual: (if .actual then (.actual | floor) else "N/A" end), url: .url}]' .lighthouseci/assertion-results.json)
129-
130- UNIQUE_FAILURE_URLS=$(echo "$FAILURES" | jq '[.[] | .url] | unique')
131-
132- if [ ! -f ".lighthouseci/links.json" ]; then
133- echo "⚠️ No .lighthouseci/links.json file found. Creating an empty JSON object..."
134- echo "{}" > .lighthouseci/links.json
135- fi
136-
137- # Load the URL to report mapping from links.json
138- URL_REPORT_MAP=$(jq -c '.' .lighthouseci/links.json)
139-
140- # Append report URLs to failed assertions
141- FAILURES_WITH_REPORTS=$(jq --argjson url_report_map "$URL_REPORT_MAP" '
142- map(. + {reportUrl: $url_report_map[.url]})
143- ' <<< "$FAILURES")
144-
145- # Check if there are failures before posting a comment
146- if [[ "$FAILURES_WITH_REPORTS" == "[]" ]]; then
147- echo "✅ **All Lighthouse metrics passed!** 🎉"
148- exit 0
149- fi
150-
151- COMMENT="### ⚡ Lighthouse CI Performance Issues ⚡
152-
153- | Metric | Expected Value | Current Value | Page URL | Report |
154- |--------|---------------|--------------|----------|--------|"
155-
156- while IFS= read -r line; do
157- COMMENT+="\n| $(echo "$line" | jq -r '.metric') | $(echo "$line" | jq -r '.expected') | $(echo "$line" | jq -r '.actual') | $(echo "$line" | jq -r '.url') | [Report]($(echo "$line" | jq -r '.reportUrl')) |"
158- done <<< "$(echo "$FAILURES_WITH_REPORTS" | jq -c '.[]')"
159-
160- echo -e "$COMMENT" > comment.txt
161-
162- gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment.txt)"
163- continue-on-error : true
164- env :
165- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
166-
167- - name : Cleanup Lighthouse Reports
168- run : rm -f comment.txt && rm -rf .lighthouseci
135+ - name : Cleanup
136+ run : rm -rf .lighthouseci
0 commit comments