diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7e438310f3..50577f052e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: node-version: 16.x - run: npm ci - name: build stats - run: npm run build -- -s + run: npm run build - name: persist id: b uses: actions/github-script@v6 @@ -36,7 +36,7 @@ jobs: script: | const fs = require('fs'); return JSON.stringify({ - size: JSON.parse(fs.readFileSync('cli_output/build_size.json')) + size: { fabric: { minified: fs.statSync('dist/fabric.min.js').size, bundled: fs.statSync('dist/fabric.js').size } } }); - name: checkout src files run: git checkout origin/master -- src @@ -50,15 +50,15 @@ jobs: script: | const fs = require('fs'); return JSON.stringify({ - size: JSON.parse(fs.readFileSync('cli_output/build_size.json')) + size: { fabric: { minified: fs.statSync('dist/fabric.min.js').size, bundled: fs.statSync('dist/fabric.js').size } } }); - name: process uses: actions/github-script@v6 with: result-encoding: string script: | - const { run } = await import('${{ github.workspace }}/scripts/buildStats.mjs'); - const res = await run({ + const { run_simple } = await import('${{ github.workspace }}/scripts/buildStats.mjs'); + const res = await run_simple({ github, context, core, diff --git a/CHANGELOG.md b/CHANGELOG.md index 6190f92167e..9dfd3220dac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- ci(): Simplify filestats even more [#8449](https://github.com/fabricjs/fabric.js/pull/8449) - chore(TS): migrate filter backends [#8403](https://github.com/fabricjs/fabric.js/pull/8403) - chore(TS): migrate Text classes/mixins [#8408](https://github.com/fabricjs/fabric.js/pull/8408) - chore(TS): migrate Path [#8412](https://github.com/fabricjs/fabric.js/pull/8412) diff --git a/scripts/buildStats.mjs b/scripts/buildStats.mjs index 61ed08bd597..39196278004 100644 --- a/scripts/buildStats.mjs +++ b/scripts/buildStats.mjs @@ -1,5 +1,3 @@ -import _ from 'lodash'; - const REQUESTED_COMMENTS_PER_PAGE = 20; const COMMENT_MARKER = ''; @@ -13,7 +11,7 @@ function printSize(a, b) { )}**)`; } -function printSizeByte(a, b) { +function printSizeKByte(a, b) { return printSize(a / 1024, b / 1024); } @@ -48,7 +46,7 @@ export async function run({ github, context, a, b }) { const table = [ ['file / KB (diff)', 'bundled', 'minified', 'gzipped'], ['---', '---', '---', '---'], - ..._.map(b.size, (_b, file) => { + ...Object.entries(b.size).map(([file, _b]) => { const _a = { bundled: 0, minified: 0, @@ -57,9 +55,58 @@ export async function run({ github, context, a, b }) { }; return [ file, - printSizeByte(_a.bundled, _b.bundled), - printSizeByte(_a.minified, _b.minified), - printSizeByte(_a.gzipped, _b.gzipped), + printSizeKByte(_a.bundled, _b.bundled), + printSizeKByte(_a.minified, _b.minified), + printSizeKByte(_a.gzipped, _b.gzipped), + ]; + }), + ]; + + const body = [ + COMMENT_MARKER, + '**Build Stats**', + '', + ...table.map((row) => ['', ...row, ''].join(' | ')), + '', + ] + .join('\n') + .slice(0, MAX_COMMENT_CHARS); + + const commentId = await findCommentId(github, context); + + await (commentId + ? github.rest.issues.updateComment({ + repo, + owner, + comment_id: commentId, + body, + }) + : github.rest.issues.createComment({ + repo, + owner, + issue_number: context.payload.pull_request.number, + body, + })); +} + +export async function run_simple({ github, context, a, b }) { + const { + repo: { owner, repo }, + } = context; + + const table = [ + ['file / KB (diff)', 'bundled', 'minified'], + ['---', '---', '---'], + ...Object.entries(b.size).map(([file, _b]) => { + const _a = { + bundled: 0, + minified: 0, + ...(a.size[file] || {}), + }; + return [ + file, + printSizeKByte(_a.bundled, _b.bundled), + printSizeKByte(_a.minified, _b.minified), ]; }), ];