Skip to content

Commit

Permalink
refactor lighthouse check workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Trombach committed Jan 2, 2025
1 parent 600d5d8 commit d4d5935
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/pr-checks.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check
name: CI

on:
pull_request:
Expand All @@ -7,9 +7,11 @@ on:
push:
branches:
- main
deployment_status:

jobs:
Typescript:
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -25,6 +27,7 @@ jobs:
run: pnpm ts:check

Biome:
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -38,3 +41,15 @@ jobs:
- run: pnpm install
- name: Run biome checks
run: pnpm biome:ci

Lighthouse:
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
strategy:
fail-fast: false
matrix:
route: ["", "/projects", "/contact"]
uses: ./.github/workflows/lhci.yml
with:
url: ${{ github.event.deployment_status.environment_url }}${{ matrix.route}}
config-path: ./lighthouserc.Preview.json
secrets: inherit
37 changes: 37 additions & 0 deletions .github/workflows/lhci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
workflow_call:
inputs:
url:
required: true
type: string
description: Full URL path to check
config-path:
required: true
type: string
description: Path to lhci config file
secrets:
LHCI_GITHUB_APP_TOKEN:
required: true
VERCEL_AUTOMATION_BYPASS_SECRET:
required: true

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: false
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
- name: Audit URL using Lighthouse
run: |
pnpm add --global @lhci/cli
lhci autorun --config=${{ inputs.config-path }}
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
LHCI_COLLECT__URL: ${{ inputs.url }}
LHCI_COLLECT__SETTINGS__EXTRA_HEADERS: '{"x-vercel-protection-bypass": "${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}"}'
25 changes: 5 additions & 20 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
name: Lighthouse test

on:
deployment_status:
schedule:
- cron: "0 7 * * *"
workflow_dispatch:

jobs:
run:
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
route: ["", "/projects", "/contact"]
steps:
- uses: actions/checkout@v4
with:
lfs: false
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
- name: Audit URL using Lighthouse
run: |
pnpm add --global @lhci/cli
lhci autorun --config=./lighthouserc.${{ github.event.deployment.environment || 'Production' }}.json
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
LHCI_COLLECT__URL: ${{ github.event.deployment_status.environment_url || 'https://www.lukastrombach.dev' }}${{ matrix.route }}
LHCI_COLLECT__SETTINGS__EXTRA_HEADERS: '{"x-vercel-protection-bypass": "${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}"}'
uses: ./.github/workflows/lhci.yml
with:
url: https://www.lukastrombach.dev${{ matrix.route }}
config-path: ./lighthouserc.Production.json
secrets: inherit
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

<div align=center>

[![Checks](https://github.com/Trombach/astro-homepage/actions/workflows/pr-checks.yml/badge.svg)](https://github.com/Trombach/astro-homepage/actions/workflows/pr-checks.yml)
[![CI](https://github.com/Trombach/astro-homepage/actions/workflows/ci.yml/badge.svg)](https://github.com/Trombach/astro-homepage/actions/workflows/ci.yml)
![Staging](https://img.shields.io/github/deployments/Trombach/astro-homepage/Production?logo=vercel&label=Staging)
[![Lighthouse tests](https://github.com/Trombach/astro-homepage/actions/workflows/lighthouse.yml/badge.svg?event=schedule)](https://github.com/Trombach/astro-homepage/actions/workflows/lighthouse.yml)
[![Lighthouse Scores](https://github.com/Trombach/astro-homepage/actions/workflows/lighthouse.yml/badge.svg?event=schedule)](https://github.com/Trombach/astro-homepage/actions/workflows/lighthouse.yml)

</div>

Expand Down

0 comments on commit d4d5935

Please sign in to comment.