Skip to content

tooling/lighthouse

tooling/lighthouse #21

Workflow file for this run

name: Lighthouse CI
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Install Lighthouse CI
run: npm install -g @lhci/cli
- name: Start HTTP Server
run: npx http-server ./dist -p 4173 &
shell: bash
- name: Wait for HTTP Server to start
run: sleep 10
- name: Run Lighthouse CI
id: lhci
run: lhci autorun --config=.lighthouserc.cjs --output=json --output-path=./lighthouse-results.json
continue-on-error: true
- name: List directory contents
run: ls -la
- name: Extract Scores and Determine Outcome
id: check_scores
run: |
SCORE=$(node -pe "const results = JSON.parse(require('fs').readFileSync('./lighthouse-results.json').toString()); const score = results.categories.accessibility.score * 100; console.log(score); score;")
echo "::set-output name=accessibility_score::${SCORE}"
if [[ $(echo "$SCORE < 100" | bc) -eq 1 ]]; then
echo "::set-output name=status::failed"
else
echo "::set-output name=status::passed"
fi