PRD - Lighthouse Run for latest main #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ⛵️ Lighthouse | |
run-name: "${{ github.ref_name == 'main' && 'PRD' || 'STG' }} - Lighthouse Run for ${{ github.event_name == 'pull_request' && format('PR #{0}: {1}', github.event.pull_request.number, github.event.pull_request.title) || format('latest {0}', github.ref_name) }}" | |
on: | |
workflow_dispatch: | |
workflow_call: | |
secrets: | |
AWS_S3_BUCKET_REPORTS: | |
required: true | |
AWS_ACCESS_KEY_ID: | |
required: true | |
AWS_SECRET_ACCESS_KEY: | |
required: true | |
AWS_REGION: | |
required: true | |
REPORTS_DISTRIBUTION: | |
required: true | |
GH_WORKFLOW_TOKEN: | |
required: true | |
env: | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
jobs: | |
lighthouse: | |
name: ⛵️ Lighthouse | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.ref_name == 'main' && 'prd' || 'stg' }} | |
steps: | |
- name: 𐂷 Checkout | |
uses: actions/checkout@v3 | |
with: | |
repository: dgrebb/dgrebb.com | |
ref: ${{ github.ref }} | |
token: ${{ github.token }} | |
sparse-checkout: | | |
_ci/_utils | |
_ci/perf | |
- name: ⬢ Setup Node & Cache | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.18.0" | |
- name: ↧ Install & Patch | |
run: | | |
cd _ci/perf && npm ci | |
- name: 🌤️ Warmup CloudFront Cache | |
run: | | |
_ci/_utils/warmup.sh ${{ github.ref_name == 'main' && 'prd' || 'stg' }} | |
- name: 🔦 Lighthouse | |
id: lighthouse | |
continue-on-error: true | |
run: | | |
cd _ci/perf/lighthouse | |
urls="${{ vars.LIGHTHOUSE_URLS }}" | |
while IFS="" read -r url || [ -n "$url" ]; do | |
u="$(echo "$url" | tr -d '\r')" | |
undurl=$(echo "$u" | sed -E 's|https?://([^/]+)(/[^?#]*)?([?#]?.*)?|\2|;s|/+$||;s|/|_|g') | |
automation_url="${u}?roboto" | |
echo "Running Lighthouse on $u and writing report to ./$undurl" | |
npm run lhgh $automation_url -- --output-path ./mobile_"$undurl"report.html --disable-extensions | |
npm run lhgh-d $automation_url -- --output-path ./desktop_"$undurl"report.html --disable-extensions | |
done <<<"$urls" | |
- name: ⚓️ Drop Anchor | |
if: always() | |
run: | | |
ls -la _ci/perf/lighthouse | |
sudo _ci/perf/_utils/landfall.sh _ci/perf/lighthouse | |
echo "# Lighthouse Results" >> $GITHUB_STEP_SUMMARY | |
echo "<a href=\"https://${{ vars.REPORTS_DOMAIN }}/lighthouse\" target=\"_blank\">Lighthouse Reports</a>" >> $GITHUB_STEP_SUMMARY | |
- name: ⬆ Upload Reports | |
if: always() | |
uses: jakejarvis/s3-sync-action@master | |
with: | |
args: --acl public-read --follow-symlinks --delete --exclude '*.js' --cache-control max-age=2853200,public | |
env: | |
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_REPORTS }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
SOURCE_DIR: "_ci/perf/lighthouse" | |
DEST_DIR: "lighthouse" | |
- name: ∅ Invalidate CloudFront | |
uses: chetan/invalidate-cloudfront-action@v2 | |
env: | |
DISTRIBUTION: ${{ secrets.REPORTS_DISTRIBUTION }} | |
PATHS: "/*" | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |