Performance: Run weekly audits against Sourcegraph.com (#26779)

This commit is contained in:
Tom Ross 2021-11-01 10:49:03 +00:00 committed by GitHub
parent 6a2eec86d4
commit 7234a2f931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,30 @@
name: Lighthouse production audit
on:
workflow_dispatch:
schedule:
# Every Monday at 12pm UTC
- cron: '0 12 * * MON'
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# set up correct version of node
- id: nvmrc
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
- uses: actions/setup-node@v2
with: { node-version: '${{ steps.nvmrc.outputs.NODE_VERSION }}' }
- name: Install dependencies
run: yarn --ignore-engines --ignore-scripts
- name: Run Lighthouse
run: |
echo -e "*Weekly audit against Sourcegraph.com*\n" > lighthouse_results.txt
./dev/ci/generate-lighthouse-slack-report.sh ":house: *Homepage*" "https://sourcegraph.com/search" ./lighthouse_results.txt
./dev/ci/generate-lighthouse-slack-report.sh ":mag_right: *Search results*" "https://sourcegraph.com/search?q=repo:sourcegraph/lighthouse-ci-test-repository+file:index.js" ./lighthouse_results.txt
./dev/ci/generate-lighthouse-slack-report.sh ":repository: *Repository page*" "https://sourcegraph.com/github.com/sourcegraph/lighthouse-ci-test-repository" ./lighthouse_results.txt
./dev/ci/generate-lighthouse-slack-report.sh ":code: *File blob*" "https://sourcegraph.com/github.com/sourcegraph/lighthouse-ci-test-repository/-/blob/index.js" ./lighthouse_results.txt
curl -X POST -H 'Content-type: application/json' --data "{'text':'$(cat ./lighthouse_results.txt)'}" ${{ secrets.LIGHTHOUSE_SLACK_WEBHOOK }}

View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# This script will run Lighthouse audits against a specified URL
# and generate a text report suitable for uploading to Slack.
# Friendly name to associate with the Lighthouse audit
NAME=$1
# URL to run Lighthouse against
URL=$2
# File to output results to
OUTPUT_FILE=$3
yarn lhci collect --url="$URL" --no-lighthouserc --settings.preset="desktop" --numberOfRuns=10
# LHCI doesn't an provide a way to easily expose the temporary storage URL, we have to extract it ourselves
REPORT_URL=$(yarn lhci upload --target=temporary-public-storage | grep -o "https:\/\/storage.googleapis.*.html\+")
# Primary result source, we'll use this to extract the raw audit data.
yarn lhci upload --target=filesystem
# Lighthouse runs multiple times and takes the median to account for varying network latency
REPRESENTATIVE_RUN=$(jq -r '.[] | select(.isRepresentativeRun==true)' manifest.json)
# Extract the Lighthouse score for each relevant category
PERFORMANCE=$(jq -r '.summary.performance' <<<"$REPRESENTATIVE_RUN")
ACCESSIBILITY=$(jq -r '.summary.accessibility' <<<"$REPRESENTATIVE_RUN")
BEST_PRACTICES=$(jq -r '.summary."best-practices"' <<<"$REPRESENTATIVE_RUN")
SEO=$(jq -r '.summary.seo' <<<"$REPRESENTATIVE_RUN")
SUMMARY="
$NAME: <$REPORT_URL|Report>
Performance: $PERFORMANCE/1
Accessibility: $ACCESSIBILITY/1
Best practices: $BEST_PRACTICES/1
SEO: $SEO/1\n
"
echo -e "$SUMMARY" >>"$OUTPUT_FILE"