Skip to content

Commit 9fd28ad

Browse files
authored
chore: dist file size chekcing with github actions (#2063)
* chore: dist file size chekcing with github actions * fix: size checking scripts * fix: add size reporting scripts * fix: add github action workflows * fix: tweak workflow name * fix: add test for size reporting with workflow dispatch
1 parent 8dc19e0 commit 9fd28ad

File tree

13 files changed

+445
-12
lines changed

13 files changed

+445
-12
lines changed

.github/workflows/nightly-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: nightly release
1+
name: Nightly release
22
on:
33
push:
44
branches:

.github/workflows/size-data.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Size data
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
upload:
16+
if: github.repository == 'intlify/vue-i18n'
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout codes
21+
uses: actions/checkout@v4
22+
23+
- name: Install pnpm
24+
uses: pnpm/[email protected]
25+
26+
- name: Setup node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 23
30+
cache: pnpm
31+
32+
- name: Install dependencies
33+
run: pnpm install --frozen-lockfile
34+
35+
- name: Check size
36+
run: pnpm size
37+
38+
- name: Save PR number & base branch
39+
if: ${{github.event_name == 'pull_request'}}
40+
run: |
41+
echo ${{ github.event.number }} > ./temp/size/number.txt
42+
echo ${{ github.base_ref }} > ./temp/size/base.txt
43+
44+
- name: Upload Size Data
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: size-data
48+
path: temp/size

.github/workflows/size-report.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Size report
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Size data']
6+
types:
7+
- completed
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
issues: write
14+
15+
jobs:
16+
size-report:
17+
runs-on: ubuntu-latest
18+
if: >
19+
github.repository == 'intlify/vue-i18n' &&
20+
github.event.workflow_run.event == 'pull_request' &&
21+
github.event.workflow_run.conclusion == 'success'
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install pnpm
26+
uses: pnpm/[email protected]
27+
28+
- name: Install Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 23
32+
cache: pnpm
33+
34+
- name: Install dependencies
35+
run: pnpm install --frozen-lockfile
36+
37+
- name: Download Size Data
38+
uses: dawidd6/action-download-artifact@v6
39+
with:
40+
name: size-data
41+
run_id: ${{ github.event.workflow_run.id }}
42+
path: temp/size
43+
44+
- name: Read PR Number
45+
id: pr-number
46+
uses: juliangruber/read-file-action@v1
47+
with:
48+
path: temp/size/number.txt
49+
50+
- name: Read base branch
51+
id: pr-base
52+
uses: juliangruber/read-file-action@v1
53+
with:
54+
path: temp/size/base.txt
55+
56+
- name: Download Previous Size Data
57+
uses: dawidd6/action-download-artifact@v6
58+
with:
59+
branch: ${{ steps.pr-base.outputs.content }}
60+
workflow: size-data.yml
61+
event: push
62+
name: size-data
63+
path: temp/size-prev
64+
if_no_artifact_found: warn
65+
66+
- name: Prepare report
67+
run: npx tsx scripts/size-report.ts > size-report.md
68+
69+
- name: Read Size Report
70+
id: size-report
71+
uses: juliangruber/read-file-action@v1
72+
with:
73+
path: ./size-report.md
74+
75+
- name: Create Comment
76+
uses: actions-cool/maintain-one-comment@v3
77+
with:
78+
token: ${{ secrets.GITHUB_TOKEN }}
79+
number: ${{ steps.pr-number.outputs.content }}
80+
body: |
81+
${{ steps.size-report.outputs.content }}
82+
<!-- INTLIFY_VUE_I18N_SIZE -->
83+
body-include: '<!-- INTLIFY_VUE_I18N_SIZE -->'

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"build:sourcemap": "pnpm build --sourcemap",
3232
"build:type": "./scripts/build.sh",
3333
"build:typed": "pnpm build core-base vue-i18n-core --withTypes",
34-
"check-install": "tsx ./scripts/playwright.ts",
34+
"size": "tsx ./scripts/build.ts --size && tsx ./scripts/size.ts",
35+
"size:report": "tsx ./scripts/report-size.ts",
3536
"clean": "run-p clean:*",
3637
"clean:coverage": "rm -rf ./coverage",
3738
"clean:dist": "rm -rf ./dist ./packages/**/dist ./docs/.vitepress/dist",
3839
"clean:docs": "trash './docs/api/!(injection).md'",
3940
"clean:type": "rm -rf ./temp",
40-
"coverage": "opener coverage/index.html",
4141
"dev": "tsx ./scripts/dev.ts",
4242
"dev:e2e": "cross-env TZ=UTC vitest -c ./vitest.e2e.config.ts",
4343
"dev:eslint": "npx @eslint/config-inspector",
@@ -73,6 +73,8 @@
7373
"preview:size-petite-vue-i18n": "pnpm --filter @intlify/size-check-petite-vue-i18n preview",
7474
"preview:size-vue-i18n": "pnpm --filter @intlify/size-check-vue-i18n preview",
7575
"release": "bumpp package.json packages/**/package.json --commit \"release: v\" --push --tag",
76+
"check-install": "tsx ./scripts/playwright.ts",
77+
"coverage": "opener coverage/index.html",
7678
"test": "run-s lint test:cover check-install test:e2e",
7779
"test:cover": "pnpm test:unit --coverage",
7880
"test:e2e": "cross-env TZ=UTC vitest run -c ./vitest.e2e.config.ts",
@@ -112,6 +114,7 @@
112114
"jsdom": "^24.0.0",
113115
"lint-staged": "^15.2.2",
114116
"listhen": "^1.7.2",
117+
"markdown-table": "^3.0.4",
115118
"mitata": "^1.0.20",
116119
"npm-run-all2": "^7.0.0",
117120
"opener": "^1.5.2",
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { brotliCompressSync, gzipSync } from 'node:zlib'
2+
import { build } from 'vite'
3+
4+
const generated = await build({
5+
logLevel: 'silent',
6+
build: {
7+
minify: true
8+
}
9+
})
10+
const bundled = generated.output[0].code
11+
12+
const size = bundled.length
13+
const gzip = gzipSync(bundled).length
14+
const brotli = brotliCompressSync(bundled).length
15+
16+
const report = {
17+
name: '@intlify/core',
18+
size,
19+
gzip,
20+
brotli
21+
}
22+
console.log(JSON.stringify(report))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { brotliCompressSync, gzipSync } from 'node:zlib'
2+
import { build } from 'vite'
3+
4+
const generated = await build({
5+
logLevel: 'silent',
6+
build: {
7+
minify: true
8+
}
9+
})
10+
const bundled = generated.output[0].code
11+
12+
const size = bundled.length
13+
const gzip = gzipSync(bundled).length
14+
const brotli = brotliCompressSync(bundled).length
15+
16+
const report = {
17+
name: 'petite-vue-i18n',
18+
size,
19+
gzip,
20+
brotli
21+
}
22+
console.log(JSON.stringify(report))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { brotliCompressSync, gzipSync } from 'node:zlib'
2+
import { build } from 'vite'
3+
4+
const generated = await build({
5+
logLevel: 'silent',
6+
build: {
7+
minify: true
8+
}
9+
})
10+
const bundled = generated.output[0].code
11+
12+
const size = bundled.length
13+
const gzip = gzipSync(bundled).length
14+
const brotli = brotliCompressSync(bundled).length
15+
16+
const report = {
17+
name: 'vue-i18n',
18+
size,
19+
gzip,
20+
brotli
21+
}
22+
console.log(JSON.stringify(report))

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -e
44

5-
pnpm build --withTypes --size
5+
pnpm build --withTypes
66

77
tsx ./scripts/postprocess.ts

scripts/build.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import pc from 'picocolors'
2727
import {
2828
targets as allTargets,
2929
checkSizeDistFiles,
30+
displaySize,
3031
fuzzyMatchTarget,
3132
readJson
3233
} from './utils'
@@ -84,20 +85,27 @@ const {
8485
} = values
8586

8687
const formats = rawFormats?.split(',')
88+
const sizeDir = path.resolve(__dirname, '../temp/size')
8789

8890
async function main() {
8991
await run()
9092

9193
async function run() {
94+
if (size) {
95+
await fs.mkdir(sizeDir, { recursive: true })
96+
}
97+
9298
const rtsCachePath = path.resolve(__dirname, './node_modules/.rts2_cache')
9399
if (isRelease && existsSync(rtsCachePath)) {
94100
// remove build cache for release builds to avoid outdated enum values
95101
await fs.rm(rtsCachePath, { recursive: true })
96102
}
103+
97104
const resolvedTargets = targets.length
98105
? await fuzzyMatchTarget(targets, buildAllMatching)
99106
: await allTargets()
100107
await buildAll(resolvedTargets)
108+
101109
if (size) {
102110
await checkAllSizes(resolvedTargets)
103111
}
@@ -273,17 +281,33 @@ async function main() {
273281
return
274282
}
275283
const file = await fs.readFile(filePath)
276-
const minSize = (file.length / 1024).toFixed(2) + 'kb'
284+
const filename = path.basename(filePath)
285+
277286
const gzipped = gzipSync(file)
278-
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
279-
const compressed = brotliCompressSync(file)
280-
const compressedSize =
281-
compressed != null ? (compressed.length / 1024).toFixed(2) + 'kb' : 'N/A'
287+
const brotli = brotliCompressSync(file)
282288
console.log(
283-
`📦 ${pc.gray(
289+
`📦 ${pc.green(
284290
pc.bold(path.basename(filePath))
285-
)} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
291+
)} - min: ${displaySize(file.length)} / gzip: ${displaySize(gzipped.length)} / brotli: ${displaySize(brotli.length)}`
286292
)
293+
294+
if (size) {
295+
const sizeContents = JSON.stringify(
296+
{
297+
file: filename,
298+
size: file.length,
299+
gzip: gzipped.length,
300+
brotli: brotli.length
301+
},
302+
null,
303+
2
304+
)
305+
await fs.writeFile(
306+
path.resolve(sizeDir, `${filename}.json`),
307+
sizeContents,
308+
'utf-8'
309+
)
310+
}
287311
}
288312
}
289313

0 commit comments

Comments
 (0)