Repository navigation
85 lines (79 loc) · 2.88 KB
/
Copy pathlighthouse.yml
File metadata and controls
85 lines (79 loc) · 2.88 KB
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
name: Lighthouse
on:
workflow_dispatch:
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Generate URLs
id: urls
uses: actions/github-script@v6
env:
COMMUNITIES_URL: ${{ secrets.COMMUNITIES_URL }}
with:
script: |
const { COMMUNITIES_URL } = process.env
const response = await fetch(COMMUNITIES_URL);
const data = await response.json();
const urls = data.join('\n');
core.setOutput('urls', urls);
- name: Run Lighthouse on urls and upload data to private lhci server
id: LHCIAction
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ steps.urls.outputs.urls }}
serverBaseUrl: ${{ secrets.LHCI_SERVER_URL }}
serverToken: ${{ secrets.LHCI_SERVER_TOKEN }}
basicAuthUsername: ${{ secrets.LHCI_SERVER_BASIC_AUTH_USERNAME }}
basicAuthPassword: ${{ secrets.LHCI_SERVER_BASIC_AUTH_PASSWORD }}
- name: Parse output
id: parsedOutput
uses: actions/github-script@v6
with:
script: |
const manifest = ${{ steps.LHCIAction.outputs.manifest }}
function median(numbers) {
return numbers.slice().sort((a, b) => a - b)[Math.floor(numbers.length / 2)];
}
function avg(numbers) {
return numbers.slice().reduce((p, c) => p + c, 0) / numbers.length;
}
function build(manifest, attr) {
let data = manifest.reduce(
(p, c) => {
if (c.summary[attr] >= p.best_score) {
p.best_score = c.summary[attr];
p.best_site = c.url;
}
if (c.summary[attr] <= p.worst_score) {
p.worst_score = c.summary[attr];
p.worst_site = c.url;
}
p.scores.push(c.summary[attr]);
return p;
},
{
best_site: undefined,
best_score: 0,
worst_site: undefined,
worst_score: 1,
scores: [],
}
);
data.median = median(data.scores);
data.avg = avg(data.scores);
delete data.scores
return data;
}
const stats = build(manifest, 'performance');
core.setOutput('manifest', JSON.stringify(stats,null,2));
- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v1.23.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL }}
slack-message: "Lighthouse results: ${{ steps.parsedOutput.outputs.manifest }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}