From 0e9fddff8b87c2d7156c30ab997b6a666348606f Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Tue, 14 Jan 2025 16:58:16 +0700 Subject: [PATCH 1/4] init --- .github/workflows/bundle-stats.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 .github/workflows/bundle-stats.yml diff --git a/.github/workflows/bundle-stats.yml b/.github/workflows/bundle-stats.yml new file mode 100644 index 00000000..4a1ea209 --- /dev/null +++ b/.github/workflows/bundle-stats.yml @@ -0,0 +1,57 @@ +name: Bundle Stats +on: + workflow_call: + inputs: + mode: + required: true + type: string + description: "'store' or 'compare'" + branch: + required: true + type: string + outputs: + stats: + description: "Bundle stats comparison" + value: ${{ jobs.bundle-stats.outputs.stats }} + +jobs: + bundle-stats: + runs-on: ubuntu-latest + outputs: + stats: ${{ steps.compare.outputs.stats }} + steps: + - uses: actions/github-script@v6 + id: gist-ops + with: + script: | + const gistId = '${{ secrets.BUNDLE_STATS_GIST_ID }}'; + + async function getGistContent() { + const { data } = await github.rest.gists.get({ gist_id: gistId }); + return JSON.parse(data.files['bundle-stats.json'].content || '{}'); + } + + async function updateGistContent(content) { + await github.rest.gists.update({ + gist_id: gistId, + files: { + 'bundle-stats.json': { + content: JSON.stringify(content, null, 2) + } + } + }); + } + + if ('${{ inputs.mode }}' === 'store') { + const stats = require('/tmp/bundle-stats.json'); + const content = await getGistContent(); + content['${{ inputs.branch }}'] = stats; + await updateGistContent(content); + } else { + const content = await getGistContent(); + const baseStats = content['${{ inputs.branch }}']; + const newStats = require('/tmp/bundle-stats.json'); + + const comparison = `${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; + core.setOutput('stats', comparison); + } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2208e460..72047302 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,3 +40,53 @@ jobs: # if: ${{ github.event.pull_request.base.ref == 'release' }} # env: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Parse Bundle Stats + run: | + SIZE=$(du -sh dist 2>/dev/null | cut -f1) + GZIP_SIZE=$(du -sh dist/**/*.gz 2>/dev/null | cut -f1) + echo "{\"total\": \"$SIZE\", \"gzipped\": \"$GZIP_SIZE\"}" > /tmp/bundle-stats.json + + - name: Compare Bundle Stats + id: compare + uses: ./.github/workflows/bundle-stats + with: + mode: compare + branch: ${{ github.event.pull_request.base.ref }} + + - name: Store Bundle Stats + if: github.event.pull_request.base.ref == github.event.pull_request.head.ref + uses: ./.github/workflows/bundle-stats + with: + mode: store + branch: ${{ github.event.pull_request.base.ref }} + + - name: Update PR Description + uses: actions/github-script@v6 + with: + script: | + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + let body = pr.body || ''; + const statsMarker = '### Bundle Size'; + const comparison = '${{ steps.compare.outputs.stats }}'; + + if (body.includes(statsMarker)) { + body = body.replace( + new RegExp(`${statsMarker}[^\n]*\n[^\n]*`), + `${statsMarker}\n${comparison}` + ); + } else { + body += `\n\n${statsMarker}\n${comparison}`; + } + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + body + }); From 1b98c925bf44b1292a653bc3c43107398ae06197 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 29 Mar 2025 10:12:58 +0300 Subject: [PATCH 2/4] should be final --- .github/workflows/bundle-stats.yml | 2 +- .github/workflows/ci.yml | 17 +++++++++++++---- rsbuild.config.ts | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bundle-stats.yml b/.github/workflows/bundle-stats.yml index 4a1ea209..a451811d 100644 --- a/.github/workflows/bundle-stats.yml +++ b/.github/workflows/bundle-stats.yml @@ -52,6 +52,6 @@ jobs: const baseStats = content['${{ inputs.branch }}']; const newStats = require('/tmp/bundle-stats.json'); - const comparison = `${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; + const comparison = `minecraft.html (normal build gzip)\n${baseStats.total}MB (${baseStats.gzipped}MB compressed) -> ${newStats.total}MB (${newStats.gzipped}MB compressed)`; core.setOutput('stats', comparison); } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c386e95..79f5788f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,13 @@ jobs: uses: pnpm/action-setup@v4 - run: pnpm install - run: pnpm check-build + - name: Create zip package for size comparison + run: | + mkdir -p package + cp -r dist package/ + cd package + zip -r ../self-host.zip . + - run: pnpm build-single-file - run: pnpm build-playground - run: pnpm build-storybook - run: pnpm test-unit @@ -43,9 +50,11 @@ jobs: - name: Parse Bundle Stats run: | - SIZE=$(du -sh dist 2>/dev/null | cut -f1) - GZIP_SIZE=$(du -sh dist/**/*.gz 2>/dev/null | cut -f1) - echo "{\"total\": \"$SIZE\", \"gzipped\": \"$GZIP_SIZE\"}" > /tmp/bundle-stats.json + SIZE_BYTES=$(du -s dist/single/minecraft.html 2>/dev/null | cut -f1) + GZIP_BYTES=$(du -s self-host.zip 2>/dev/null | cut -f1) + SIZE=$(echo "scale=2; $SIZE_BYTES/1024/1024" | bc) + GZIP_SIZE=$(echo "scale=2; $GZIP_BYTES/1024/1024" | bc) + echo "{\"total\": \"${SIZE}MB\", \"gzipped\": \"${GZIP_SIZE}MB\"}" > /tmp/bundle-stats.json - name: Compare Bundle Stats id: compare @@ -55,7 +64,7 @@ jobs: branch: ${{ github.event.pull_request.base.ref }} - name: Store Bundle Stats - if: github.event.pull_request.base.ref == github.event.pull_request.head.ref + if: github.event.pull_request.base.ref == 'next' uses: ./.github/workflows/bundle-stats with: mode: store diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 1701fc5c..36ccb9b0 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -203,6 +203,12 @@ const appConfig = defineConfig({ }) build.onAfterBuild(async () => { if (SINGLE_FILE_BUILD) { + // check that only index.html is in the dist/single folder + const singleBuildFiles = fs.readdirSync('./dist/single') + if (singleBuildFiles.length !== 1 || singleBuildFiles[0] !== 'index.html') { + throw new Error('Single file build must only have index.html in the dist/single folder. Ensure workers are imported & built correctly.') + } + // process index.html const singleBuildHtml = './dist/single/index.html' let html = fs.readFileSync(singleBuildHtml, 'utf8') From 258bda6506f0ff4bdf0a6d0016473e507fa43a9e Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 29 Mar 2025 10:13:58 +0300 Subject: [PATCH 3/4] mbmb --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79f5788f..46a2de6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: GZIP_BYTES=$(du -s self-host.zip 2>/dev/null | cut -f1) SIZE=$(echo "scale=2; $SIZE_BYTES/1024/1024" | bc) GZIP_SIZE=$(echo "scale=2; $GZIP_BYTES/1024/1024" | bc) - echo "{\"total\": \"${SIZE}MB\", \"gzipped\": \"${GZIP_SIZE}MB\"}" > /tmp/bundle-stats.json + echo "{\"total\": ${SIZE}, \"gzipped\": ${GZIP_SIZE}}" > /tmp/bundle-stats.json - name: Compare Bundle Stats id: compare From fa793e3459f6ac01a4726fc7d083b6313f83783a Mon Sep 17 00:00:00 2001 From: Vitaly Date: Sat, 29 Mar 2025 10:41:11 +0300 Subject: [PATCH 4/4] Update .github/workflows/bundle-stats.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/bundle-stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bundle-stats.yml b/.github/workflows/bundle-stats.yml index a451811d..a9dcb0e5 100644 --- a/.github/workflows/bundle-stats.yml +++ b/.github/workflows/bundle-stats.yml @@ -18,7 +18,7 @@ jobs: bundle-stats: runs-on: ubuntu-latest outputs: - stats: ${{ steps.compare.outputs.stats }} + stats: ${{ steps.gist-ops.outputs.stats }} steps: - uses: actions/github-script@v6 id: gist-ops