diff --git a/.github/workflows/lighthouse-production.yml b/.github/workflows/lighthouse-production.yml new file mode 100644 index 00000000000..a7dc0861698 --- /dev/null +++ b/.github/workflows/lighthouse-production.yml @@ -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 }} diff --git a/dev/ci/generate-lighthouse-slack-report.sh b/dev/ci/generate-lighthouse-slack-report.sh new file mode 100755 index 00000000000..4c41a0730c5 --- /dev/null +++ b/dev/ci/generate-lighthouse-slack-report.sh @@ -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"