Skip to content

Commit

Permalink
Merge pull request #1 from nocodeventure-nl/259
Browse files Browse the repository at this point in the history
259
  • Loading branch information
melmathari authored Nov 22, 2024
2 parents ee014bc + 6439f94 commit 15a2f36
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/bundle-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Size

on:
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- main

permissions:
pull-requests: write
jobs:
size:
name: Report bundle size
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies (base)
run: bun install

- name: Build (base)
run: bun run build

- name: Get base bundle size breakdown
id: base-size
run: |
echo "total=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT
echo "breakdown<<EOF" >> $GITHUB_OUTPUT
find dist -type f -name "*.js" -o -name "*.css" | while read file; do
echo "$(du -sh $file | cut -f1) - $(basename $file)"
done >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Checkout PR branch
uses: actions/checkout@v3

- name: Install dependencies (PR)
run: bun install

- name: Build (PR)
run: bun run build

- name: Get PR bundle size breakdown
id: pr-size
run: |
echo "total=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT
echo "breakdown<<EOF" >> $GITHUB_OUTPUT
find dist -type f -name "*.js" -o -name "*.css" | while read file; do
echo "$(du -sh $file | cut -f1) - $(basename $file)"
done >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Calculate size difference
id: size-diff
run: |
base_size=$(echo ${{ steps.base-size.outputs.total }} | sed 's/[^0-9.]*//g')
pr_size=$(echo ${{ steps.pr-size.outputs.total }} | sed 's/[^0-9.]*//g')
diff=$(echo "$pr_size - $base_size" | bc)
if (( $(echo "$diff > 0" | bc -l) )); then
echo "total=+$diff" >> $GITHUB_OUTPUT
else
echo "total=$diff" >> $GITHUB_OUTPUT
fi
- name: Update comment
uses: marocchino/sticky-pull-request-comment@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
header: Bundle Size Report
message: |
## Bundle Size Report
### Total Size
- Base branch: ${{ steps.base-size.outputs.total }}
- PR branch: ${{ steps.pr-size.outputs.total }}
- Difference: ${{ steps.size-diff.outputs.total }}MB
### Base Branch Breakdown
```
${{ steps.base-size.outputs.breakdown }}
```
### PR Branch Breakdown
```
${{ steps.pr-size.outputs.breakdown }}
```

0 comments on commit 15a2f36

Please sign in to comment.