Skip to content

Ruchi/lighthouse performance metrics #13

Ruchi/lighthouse performance metrics

Ruchi/lighthouse performance metrics #13

name: Performance Testing
on:
pull_request:
branches:
- main
env:
NODE_OPTIONS: '--max-old-space-size=6144 --dns-result-order=ipv4first'
LATEST_VERSION: '2.17.0'
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Setup Yarn
run: |
npm uninstall -g yarn
npm i -g [email protected]
- name: Run bootstrap
run: yarn osd bootstrap
- name: Download OpenSearch
uses: suisei-cn/[email protected]
with:
url: https://artifacts.opensearch.org/releases/bundle/opensearch/${{ env.LATEST_VERSION }}/opensearch-${{ env.LATEST_VERSION }}-linux-x64.tar.gz
- name: Extract OpenSearch
run: |
tar -xzf opensearch-*.tar.gz
rm -f opensearch-*.tar.gz
shell: bash
- name: Remove security plugin
run: |
/bin/bash -c "yes | ./opensearch-${{ env.LATEST_VERSION }}/bin/opensearch-plugin remove opensearch-security"
shell: bash
- name: Run OpenSearch
run: |
/bin/bash -c "./opensearch-${{ env.LATEST_VERSION }}/opensearch-tar-install.sh &"
sleep 30
shell: bash
- name: Install Lighthouse CI
run: yarn add --dev @lhci/cli
- name: Run bootstrap
run: yarn osd bootstrap
- name: Build plugins
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 12
- name: Wait for OpenSearch to be ready
run: |
until curl -s http://localhost:9200 >/dev/null; do
echo "Waiting for OpenSearch..."
sleep 10
done
echo "OpenSearch is up!"
- name: Start OpenSearch Dashboards
run: |
yarn start --no-base-path &
until curl -s http://localhost:5601 >/dev/null; do
echo "Waiting for OpenSearch Dashboards..."
sleep 10
done
echo "OpenSearch Dashboards is up!"
- name: Mock data
run: |
curl 'http://localhost:5601/api/sample_data/ecommerce' -X 'POST' -H 'osd-version: 3.0.0' -H 'osd-xsrf: osd-fetch'
- name: Run Lighthouse CI
run: yarn lhci autorun || echo "Lighthouse assertion failed, check results"
- name: Run Lighthouse CI
run: |
yarn lhci autorun --json | tee lhci_output.json || true
# Validate JSON output
if [ ! -s lhci_output.json ]; then
echo "❌ Lighthouse output is empty or invalid."
cat lhci_output.json # Print for debugging
exit 1
fi
# Extract failed assertions safely
FAILURES=$(jq -r 'if .assertionResults then [.assertionResults[] | select(.status=="fail") | {metric: .auditId, reason: .explanation}] else [] end' lhci_output.json)
if [[ "$FAILURES" == "[]" ]]; then
echo "✅ All Lighthouse metrics passed!" > comment.txt
else
echo "❌ **Failed Lighthouse Metrics:**" > comment.txt
echo '```json' >> comment.txt
echo "$FAILURES" >> comment.txt
echo '```' >> comment.txt
fi
# Upload and extract report URL
yarn lhci upload --target=temporary-public-storage | tee lhci_output.txt
REPORT_URL=$(grep -Eo 'https://storage.googleapis.com/lighthouse-infrastructure-[^\s]+' lhci_output.txt | head -n 1)
if [[ -n "$REPORT_URL" ]]; then
echo "🔗 [View Full Lighthouse Report]($REPORT_URL)" >> comment.txt
else
echo "⚠️ Lighthouse report link not found. Check workflow logs." >> comment.txt
fi
gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment.txt)"