Skip to content

Commit

Permalink
ci: compare bundle size (#3661)
Browse files Browse the repository at this point in the history
* ci: compare bundle size

* chore: change name of task

* for SDGs

* Revert "for SDGs"

This reverts commit 7861d1a.

* add gitignore

* update

* fix
  • Loading branch information
EdamAme-x authored Nov 15, 2024
1 parent a15bec3 commit 53bd319
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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<<EOF'
bun scripts/process-results.ts | column -s '|' -t
echo 'EOF'
} >> "$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 }}
2 changes: 2 additions & 0 deletions perf-measures/bundle-check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated
!generated/.gitkeep
Empty file.
14 changes: 14 additions & 0 deletions perf-measures/bundle-check/scripts/process-results.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 53bd319

Please sign in to comment.