-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (67 loc) · 2.8 KB
/
lighthouse.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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: Create Results Directory
run: mkdir -p lighthouse-results
- name: Run Lighthouse CI
run: lhci autorun --config=.lighthouserc.cjs
continue-on-error: true
- name: Collect JSON Results
run: |
lhci collect --config=.lighthouserc.cjs --numberOfRuns=1
lhci report --config=.lighthouserc.cjs --output=json --output-path=./lighthouse-results/results.json
- name: List Output Files
run: ls -la ./lighthouse-results/
- name: Extract Scores and Determine Outcome
run: |
if [ -f "./lighthouse-results/results.json" ]; then
SCORE=$(node -pe "const results = JSON.parse(require('fs').readFileSync('./lighthouse-results/results.json').toString()); const score = results[0].categories.accessibility.score * 100; console.log(score); score;")
if [[ $(echo "$SCORE < 100" | bc) -eq 1 ]]; then
echo "::set-output name=status::failed"
echo "::set-output name=accessibility_score::$SCORE"
else
echo "::set-output name=status::passed"
echo "::set-output name=accessibility_score::$SCORE"
fi
else
echo "Results file does not exist."
exit 1
fi
continue-on-error: true
- name: Post Comment on PR
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ steps.check_scores.outputs.status == 'failed' && '❌ Lighthouse checks failed with an accessibility score of ${{ steps.check_scores.outputs.accessibility_score }}%. Please review the Lighthouse report in the Artifacts.' || '✅ Lighthouse checks passed successfully with an accessibility score of ${{ steps.check_scores.outputs.accessibility_score }}%!' }}
Report URL: [View Lighthouse Report](${{ steps.extract_url.outputs.report_url }})
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fail the Workflow if Lighthouse Failed
if: steps.check_scores.outputs.status == 'failed'
run: exit 1