From c78643dec2aa66c225901623c0fda85491e55073 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 6 Jan 2025 10:07:30 +0000 Subject: [PATCH 1/2] ci: add bundle size comparison job --- .github/workflows/size.yml | 70 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + build.config.ts | 2 ++ package.json | 1 + pnpm-lock.yaml | 3 ++ 5 files changed, 77 insertions(+) create mode 100644 .github/workflows/size.yml diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml new file mode 100644 index 000000000..9698f2006 --- /dev/null +++ b/.github/workflows/size.yml @@ -0,0 +1,70 @@ +on: + # this action will error unless run in a pr context + pull_request: + pull_request_target: + +jobs: + # Build current and upload stats.json + # You may replace this with your own build method. All that + # is required is that the stats.json be an artifact + build-head: + name: 'Build head' + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "pnpm" + - run: pnpm install + - run: pnpm build + - name: Upload stats.json + uses: actions/upload-artifact@v3 + with: + name: head-stats + path: ./stats.json + + # Build base for comparison and upload stats.json + # You may replace this with your own build method. All that + # is required is that the stats.json be an artifact + build-base: + name: 'Build base' + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + ref: ${{ github.base_ref }} + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "pnpm" + - run: pnpm install + - run: pnpm build + - name: Upload stats.json + uses: actions/upload-artifact@v3 + with: + name: base-stats + path: ./stats.json + + # run the action against the stats.json files + compare: + name: 'Compare base & head bundle sizes' + runs-on: ubuntu-latest + needs: [build-base, build-head] + permissions: + pull-requests: write + steps: + - uses: actions/download-artifact@v3 + - uses: twk3/rollup-size-compare-action@v1.0.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + current-stats-json-path: ./head-stats/stats.json + base-stats-json-path: ./base-stats/stats.json diff --git a/.gitignore b/.gitignore index 9c591c11b..2aeecfa8d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist nuxt-app .pnpm-store coverage +stats.json diff --git a/build.config.ts b/build.config.ts index f05e034fa..b88bed1db 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,6 +1,7 @@ import { defineBuildConfig } from 'unbuild' import type { InputPluginOption } from 'rollup' import { purgePolyfills } from 'unplugin-purge-polyfills' +import { visualizer } from 'rollup-plugin-visualizer' export default defineBuildConfig({ declaration: true, @@ -10,6 +11,7 @@ export default defineBuildConfig({ plugins.push(purgePolyfills.rollup({ logLevel: 'verbose', })) + plugins.push(visualizer({ template: 'raw-data' })) }, }, rollup: { diff --git a/package.json b/package.json index aa506d55a..8b874c308 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "pkg-pr-new": "^0.0.39", "pkg-types": "^1.3.0", "rollup": "^4.30.0", + "rollup-plugin-visualizer": "^5.13.1", "scule": "^1.3.0", "semver": "^7.6.3", "std-env": "^3.8.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 414f3d375..6f7e4de2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -118,6 +118,9 @@ importers: rollup: specifier: ^4.30.0 version: 4.30.0 + rollup-plugin-visualizer: + specifier: ^5.13.1 + version: 5.13.1(rollup@4.30.0) scule: specifier: ^1.3.0 version: 1.3.0 From 187d5fe95600bbef6d3ccb26245a89f9d7659b17 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 6 Jan 2025 10:11:49 +0000 Subject: [PATCH 2/2] ci: update names for workflows --- .github/workflows/size.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml index 9698f2006..bb1e153d8 100644 --- a/.github/workflows/size.yml +++ b/.github/workflows/size.yml @@ -1,3 +1,4 @@ +name: size on: # this action will error unless run in a pr context pull_request: @@ -8,7 +9,6 @@ jobs: # You may replace this with your own build method. All that # is required is that the stats.json be an artifact build-head: - name: 'Build head' runs-on: ubuntu-latest permissions: contents: read @@ -33,7 +33,6 @@ jobs: # You may replace this with your own build method. All that # is required is that the stats.json be an artifact build-base: - name: 'Build base' runs-on: ubuntu-latest permissions: contents: read @@ -56,7 +55,6 @@ jobs: # run the action against the stats.json files compare: - name: 'Compare base & head bundle sizes' runs-on: ubuntu-latest needs: [build-base, build-head] permissions: