From d4d59356dae35a907dc7c1d44ae74e28e556e386 Mon Sep 17 00:00:00 2001 From: Lukas Trombach Date: Thu, 2 Jan 2025 18:47:06 +0100 Subject: [PATCH] refactor lighthouse check workflows --- .github/workflows/{pr-checks.yml => ci.yml} | 17 +++++++++- .github/workflows/lhci.yml | 37 +++++++++++++++++++++ .github/workflows/lighthouse.yml | 25 +++----------- README.md | 4 +-- 4 files changed, 60 insertions(+), 23 deletions(-) rename .github/workflows/{pr-checks.yml => ci.yml} (56%) create mode 100644 .github/workflows/lhci.yml diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/ci.yml similarity index 56% rename from .github/workflows/pr-checks.yml rename to .github/workflows/ci.yml index eab663a9..6d501c53 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Check +name: CI on: pull_request: @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/lhci.yml b/.github/workflows/lhci.yml new file mode 100644 index 00000000..79e92813 --- /dev/null +++ b/.github/workflows/lhci.yml @@ -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 }}"}' diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index d639e831..0c1755db 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -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 diff --git a/README.md b/README.md index a2193bb0..8f135bd6 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@
-[![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)