-
-
Notifications
You must be signed in to change notification settings - Fork 387
136 lines (116 loc) · 4.76 KB
/
Copy pathstatoscope.yml
File metadata and controls
136 lines (116 loc) · 4.76 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
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
130
131
132
133
134
135
136
name: Statoscope
# PR-only: compares the PR build against statoscope/reference.json, which is
# regenerated locally by `make newversion` on each release. The bot must not
# push to main.
on:
pull_request:
branches: [ main ]
jobs:
statoscope:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Build with Statoscope
run: make build es=es2021 uglify=true fat=true statoscope=true
# Compare against the committed reference
- name: Generate size report
id: sizes
run: |
if [ ! -f statoscope/reference.json ]; then
echo "has_reference=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "has_reference=true" >> "$GITHUB_OUTPUT"
REF=$(npx @statoscope/cli query \
--input statoscope/reference.json \
--query '$[0].compilations.pick().assets.({name, size: info.size})')
NEXT=$(npx @statoscope/cli query \
--input statoscope/reference.next.json \
--query '$[0].compilations.pick().assets.({name, size: info.size})')
node -e "
const ref = JSON.parse(process.argv[1]);
const next = JSON.parse(process.argv[2]);
const fmt = (b) => (b / 1024).toFixed(2) + ' KB';
const fmtDiff = (d) => {
if (d === 0) return '—';
const kb = (d / 1024).toFixed(2);
return (d > 0 ? '+' : '') + kb + ' KB';
};
let table = '| Asset | Reference | Current | Diff |\n|---|--:|--:|--:|\n';
let totalRef = 0, totalNext = 0;
for (const n of next) {
const r = ref.find(x => x.name === n.name);
const rSize = r ? r.size : 0;
const diff = n.size - rSize;
totalRef += rSize;
totalNext += n.size;
const icon = diff > 0 ? '🔺' : diff < 0 ? '🟢' : '';
table += '| ' + n.name + ' | ' + fmt(rSize) + ' | ' + fmt(n.size) + ' | ' + icon + ' ' + fmtDiff(diff) + ' |\n';
}
const totalDiff = totalNext - totalRef;
const icon = totalDiff > 0 ? '🔺' : totalDiff < 0 ? '🟢' : '';
table += '| **Total** | **' + fmt(totalRef) + '** | **' + fmt(totalNext) + '** | ' + icon + ' **' + fmtDiff(totalDiff) + '** |\n';
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'table<<SIZES_EOF\n' + table + 'SIZES_EOF\n');
" "$REF" "$NEXT"
- name: Validate rules
if: steps.sizes.outputs.has_reference == 'true'
id: validate
run: |
set +e
OUTPUT=$(npx @statoscope/cli validate \
--input statoscope/reference.next.json \
--reference statoscope/reference.json 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
{
echo "result<<STATOSCOPE_EOF"
echo "$OUTPUT"
echo "STATOSCOPE_EOF"
} >> "$GITHUB_OUTPUT"
echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
- name: Generate diff report
if: steps.sizes.outputs.has_reference == 'true'
run: |
npx @statoscope/cli generate \
--input statoscope/reference.next.json \
--reference statoscope/reference.json \
--output build/statoscope-diff.html
- name: Upload diff report
if: steps.sizes.outputs.has_reference == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: statoscope-diff
path: build/statoscope-diff.html
retention-days: 30
- name: Comment PR
if: steps.sizes.outputs.has_reference == 'true'
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v2
with:
header: statoscope
message: |
## 📊 Bundle Size
${{ steps.sizes.outputs.table }}
<details>
<summary>Validation details</summary>
```
${{ steps.validate.outputs.result }}
```
</details>
${{ steps.validate.outputs.exit_code == '0' && '✅ All checks passed' || '⚠️ Some checks failed' }} · [Full diff report →](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) (see Artifacts)
- name: Comment PR (no reference)
if: steps.sizes.outputs.has_reference != 'true'
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v2
with:
header: statoscope
message: |
## 📊 Bundle Size
No reference stats in `main` yet. Comparison will be available after first merge.