From 53bd319b43e0e97b9c7f24bfd4acb9a6fe5eb4f8 Mon Sep 17 00:00:00 2001 From: EdamAmex <121654029+EdamAme-x@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:44:48 +0900 Subject: [PATCH] ci: compare bundle size (#3661) * ci: compare bundle size * chore: change name of task * for SDGs * Revert "for SDGs" This reverts commit 7861d1a5fe712149a6a5825499756af697efe3d1. * add gitignore * update * fix --- .github/workflows/ci.yml | 43 +++++++++++++++++++ perf-measures/bundle-check/.gitignore | 2 + perf-measures/bundle-check/generated/.gitkeep | 0 .../bundle-check/scripts/process-results.ts | 14 ++++++ 4 files changed, 59 insertions(+) create mode 100644 perf-measures/bundle-check/.gitignore create mode 100644 perf-measures/bundle-check/generated/.gitkeep create mode 100644 perf-measures/bundle-check/scripts/process-results.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4daa0ea1..3a6b109e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -182,6 +182,7 @@ jobs: path: coverage/ perf-measures-type-check-on-pr: + name: 'Type Check on PR' runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: @@ -209,6 +210,7 @@ jobs: name: display comparison perf-measures-type-check-on-main: + name: 'Type Check on Main' runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: @@ -223,3 +225,44 @@ jobs: with: path: perf-measures/type-check/previous-result.txt key: type-check-perf-previous-result-${{ github.sha }} + + perf-measures-bundle-check-on-pr: + name: 'Bundle Check on PR' + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install + - run: bun run build + - run: bunx esbuild --minify --bundle dist/index.js --format=esm --outfile=perf-measures/bundle-check/generated/after.js + - uses: actions/cache/restore@v4 + with: + path: perf-measures/bundle-check/generated/before.js + restore-keys: | + perf-measures-bundle-check-previous-file- + key: perf-measures-bundle-check-previous-file- + - run: | + { + echo 'COMPARISON<> "$GITHUB_ENV" + working-directory: perf-measures/bundle-check + - run: echo "$COMPARISON" + name: display comparison + + perf-measures-bundle-check-on-main: + name: 'Bundle Check on Main' + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install + - run: bun run build + - run: bunx esbuild --minify --bundle dist/index.js --format=esm --outfile=perf-measures/bundle-check/generated/before.js + - uses: actions/cache/save@v4 + with: + path: perf-measures/bundle-check/generated/before.js + key: perf-measures-bundle-check-previous-file-${{ github.sha }} \ No newline at end of file diff --git a/perf-measures/bundle-check/.gitignore b/perf-measures/bundle-check/.gitignore new file mode 100644 index 00000000..49795c58 --- /dev/null +++ b/perf-measures/bundle-check/.gitignore @@ -0,0 +1,2 @@ +generated +!generated/.gitkeep diff --git a/perf-measures/bundle-check/generated/.gitkeep b/perf-measures/bundle-check/generated/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/perf-measures/bundle-check/scripts/process-results.ts b/perf-measures/bundle-check/scripts/process-results.ts new file mode 100644 index 00000000..e570a188 --- /dev/null +++ b/perf-measures/bundle-check/scripts/process-results.ts @@ -0,0 +1,14 @@ +import * as fs from 'node:fs/promises' + +async function main() { + const currentResult = (await fs.readFile('./generated/after.js')).byteLength + let previousResult: number | null = null + try { + previousResult = (await fs.readFile('./generated/before.js')).byteLength + } catch (e) {} + const table = ['| | Current | Previous |', '| --- | --- | --- |'] + table.push(`| Bundle Size | ${currentResult} | ${previousResult || 'N/A'} |`) + console.log(table.join('\n')) +} + +main()