Skip to content

feat: add Lighthouse CI workflow #6

feat: add Lighthouse CI workflow

feat: add Lighthouse CI workflow #6

Workflow file for this run

name: Lighthouse Performance Test
on:
push:
branches:
- feat/lighthouse
pull_request:
branches:
- feat/lighthouse
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: yarn install
- name: Build Next.js application
run: yarn build
- name: Start production server
run: |
yarn start &
sleep 15 # Give the server time to start
- name: Install Lighthouse
run: yarn global add lighthouse
- name: Run Lighthouse on production build (HTML)
run: lighthouse http://localhost:3000 --output html --output-path ./lighthouse-production.html --chrome-flags="--headless --no-sandbox --disable-gpu"
- name: Upload Lighthouse results
uses: actions/upload-artifact@v2
with:
name: lighthouse-results
path: |
lighthouse-production.html
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
- name: Deploy report to GitHub Pages
run: |
git clone --branch gh-pages https://github.com/${{ github.repository }} gh-pages
cp lighthouse-production.html gh-pages/
cd gh-pages
git add lighthouse-production.html
git commit -m "Deploy Lighthouse report"
git push origin gh-pages
- name: Comment with report link
uses: actions/github-script@v6
with:
script: |
const { context } = require('@actions/github');
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/lighthouse-production.html`;
const issueComment = `Lighthouse performance report is available here: [View Report](${reportUrl})`;
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: issueComment,
});