-
Notifications
You must be signed in to change notification settings - Fork 12
129 lines (119 loc) · 4.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Lighthouse
permissions:
pull-requests: write
on:
pull_request_target:
branches: [main]
jobs:
authorize:
environment:
${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true
lighthouse:
needs: authorize
runs-on: ubuntu-latest
env:
PUBLIC_FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
PUBLIC_FIREBASE_SERVICE_ACCOUNT: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
PUBLIC_FIREBASE_STORAGE_BUCKET: ${{secrets.FIREBASE_STORAGE_BUCKET}}
strategy:
matrix:
node-version: ['20.x']
steps:
- uses: actions/github-script@v7
id: pr
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
...context.repo,
pull_number: context.payload.pull_request.number,
});
return pullRequest
- uses: actions/checkout@v4
with:
ref: ${{fromJSON(steps.pr.outputs.result).merge_commit_sha}}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install --no-frozen-lockfile
- run: pnpm run build
- run: pnpm run preview & npx wait-on http://localhost:4321
- name: Run Lighthouse Mobile
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v11
with:
urls: |
http://localhost:4321
configPath: ./.github/workflows/lighthouse/lighthouserc.json
uploadArtifacts: true
temporaryPublicStorage: true
runs: 5
- name: Format Lighthouse Mobile score
uses: actions/github-script@v7
id: format_lighthouse_score
with:
script: |
const lighthouseCommentMaker = require('./.github/workflows/lighthouse/lighthouseCommentMaker.cjs');
const lighthouseOutputs = {
manifest: ${{ steps.lighthouse_audit.outputs.manifest }},
links: ${{ steps.lighthouse_audit.outputs.links }},
assertionResults: ${{ steps.lighthouse_audit.outputs.assertionResults }}
};
const prComment = lighthouseCommentMaker({ lighthouseOutputs });
core.setOutput("pr_comment", prComment);
- name: Run Lighthouse Desktop
id: lighthouse_desktop_audit
uses: treosh/lighthouse-ci-action@v11
with:
urls: |
http://localhost:4321
configPath: ./.github/workflows/lighthouse/lighthouserc-desktop.json
uploadArtifacts: true
temporaryPublicStorage: true
runs: 5
artifactName: lighthouse-desktop-results
- name: Format Lighthouse Desktop score
uses: actions/github-script@v7
id: format_lighthouse_desktop_score
with:
script: |
const lighthouseCommentMaker = require('./.github/workflows/lighthouse/lighthouseCommentMaker.cjs');
const lighthouseOutputs = {
manifest: ${{ steps.lighthouse_desktop_audit.outputs.manifest }},
links: ${{ steps.lighthouse_desktop_audit.outputs.links }},
assertionResults: ${{ steps.lighthouse_desktop_audit.outputs.assertionResults }}
};
const prComment = lighthouseCommentMaker({ lighthouseOutputs });
core.setOutput("pr_comment", prComment);
- uses: jwalton/gh-find-current-pr@v1
id: pr_number_finder
- name: Add Lighthouse stats as comment
uses: marocchino/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: lighthouse
number: ${{ github.event.number || steps.pr_number_finder.outputs.pr }}
message: |
## Mobile score
${{ steps.format_lighthouse_score.outputs.pr_comment }}
## Desktop score
${{ steps.format_lighthouse_desktop_score.outputs.pr_comment }}