Skip to content

Commit 0408c36

Browse files
committed
ci: add size report
1 parent bd08f05 commit 0408c36

File tree

11 files changed

+811
-52
lines changed

11 files changed

+811
-52
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,3 @@ jobs:
114114

115115
- name: Run type declaration tests
116116
run: pnpm run test-dts
117-
118-
size:
119-
runs-on: ubuntu-latest
120-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
121-
env:
122-
CI_JOB_NUMBER: 1
123-
steps:
124-
- uses: actions/checkout@v3
125-
126-
- name: Install pnpm
127-
uses: pnpm/action-setup@v2
128-
129-
- name: Set node version to 18
130-
uses: actions/setup-node@v3
131-
with:
132-
node-version: 18
133-
cache: 'pnpm'
134-
135-
- run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
136-
- run: pnpm run size

.github/workflows/size-report.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: size report
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
size:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v2
21+
22+
- name: Set node version to LTS
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: lts/*
26+
cache: pnpm
27+
28+
- run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
29+
- run: pnpm run size
30+
31+
- name: Download Previous Size Report
32+
id: download-artifact
33+
uses: dawidd6/action-download-artifact@v2
34+
with:
35+
branch: main
36+
name: size-report
37+
path: temp/size-prev
38+
if_no_artifact_found: warn
39+
40+
- name: Upload Size Report
41+
uses: actions/upload-artifact@v3
42+
with:
43+
name: size-report
44+
path: temp/size
45+
46+
- name: Compare size
47+
run: node scripts/size-report.js > size.md
48+
49+
- name: Read Size Markdown
50+
id: size-markdown
51+
uses: juliangruber/read-file-action@v1
52+
with:
53+
path: ./size.md
54+
55+
- name: Create Comment
56+
uses: actions-cool/maintain-one-comment@v3
57+
with:
58+
body: |
59+
${{steps.size-markdown.outputs.content}}
60+
<!-- VUE_CORE_SIZE -->
61+
body-include: '<!-- VUE_CORE_SIZE -->'

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build": "node scripts/build.js",
99
"build-dts": "tsc -p tsconfig.build.json && rollup -c rollup.dts.config.js",
1010
"size": "run-s size-global size-baseline",
11-
"size-global": "node scripts/build.js vue runtime-dom -f global -p",
12-
"size-baseline": "node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler && cd packages/size-check && vite build && node brotli",
11+
"size-global": "node scripts/build.js vue runtime-dom -f global -p --size",
12+
"size-baseline": "node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler && node scripts/export-size.js && cd packages/size-check && vite build && node size-report",
1313
"check": "tsc --incremental --noEmit",
1414
"lint": "eslint --cache --ext .ts packages/*/{src,__tests__}/**.ts",
1515
"format": "prettier --write --cache \"**/*.[tj]s?(x)\"",
@@ -63,6 +63,7 @@
6363
"@rollup/plugin-node-resolve": "^15.0.1",
6464
"@rollup/plugin-replace": "^5.0.2",
6565
"@rollup/plugin-terser": "^0.4.0",
66+
"@sxzz/export-size": "^0.6.0",
6667
"@types/hash-sum": "^1.0.0",
6768
"@types/node": "^16.4.7",
6869
"@typescript-eslint/parser": "^5.56.0",
@@ -81,10 +82,12 @@
8182
"lint-staged": "^10.2.10",
8283
"lodash": "^4.17.15",
8384
"magic-string": "^0.30.0",
85+
"markdown-table": "^3.0.3",
8486
"marked": "^4.0.10",
8587
"minimist": "^1.2.0",
8688
"npm-run-all": "^4.1.5",
8789
"prettier": "^3.0.1",
90+
"pretty-bytes": "^6.1.1",
8891
"pug": "^3.0.1",
8992
"puppeteer": "~19.6.0",
9093
"rollup": "^3.26.0",

packages/size-check/brotli.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/size-check/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@vue/size-check",
33
"version": "3.3.4",
4+
"type": "module",
45
"private": true,
56
"scripts": {
67
"build": "vite build"

packages/size-check/size-report.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @ts-check
2+
import { brotliCompress, gzip } from 'node:zlib'
3+
import { promisify } from 'node:util'
4+
import { readFile, writeFile } from 'node:fs/promises'
5+
import path from 'node:path'
6+
import prettyBytes from 'pretty-bytes'
7+
8+
run()
9+
10+
async function run() {
11+
const file = await readFile('dist/index.js')
12+
13+
const gzipped = await promisify(gzip)(file)
14+
console.log(`gzip: ${prettyBytes(gzipped.length)}`)
15+
16+
const brotli = await promisify(brotliCompress)(file)
17+
console.log(`brotli: ${prettyBytes(brotli.length)}`)
18+
19+
await writeFile(
20+
path.resolve('../../temp/size/_baseline.json'),
21+
JSON.stringify({
22+
size: file.length,
23+
gzip: gzipped.length,
24+
brotli: brotli.length
25+
})
26+
)
27+
}

packages/size-check/vite.config.js renamed to packages/size-check/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { defineConfig } from 'vite'
2+
3+
export default defineConfig({
24
define: {
35
__VUE_PROD_DEVTOOLS__: false,
46
__VUE_OPTIONS_API__: true
@@ -12,4 +14,4 @@ export default {
1214
},
1315
minify: 'terser'
1416
}
15-
}
17+
})

0 commit comments

Comments
 (0)