Skip to content

Instantly share code, notes, and snippets.

@khromov
Last active November 15, 2023 17:17
Show Gist options
  • Save khromov/3a012118b8dff4f17883031d09866224 to your computer and use it in GitHub Desktop.
Save khromov/3a012118b8dff4f17883031d09866224 to your computer and use it in GitHub Desktop.
GitHub Actions Bundle size comparison
name: 'Bundle Size Comparison'
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout master branch
uses: actions/checkout@v2
with:
ref: master
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies
run: npm i
- name: Build the code
run: npm run build
- name: Get master branch bundle sizes
id: master_sizes
run: |
echo "client_size=$(du -sk ./build/client/_app/immutable | cut -f1)" >> $GITHUB_ENV
echo "server_size=$(du -sk ./build/server | cut -f1)" >> $GITHUB_ENV
- name: Clean up
run: rm -Rf node_modules/ build/
- name: Checkout PR branch
uses: actions/checkout@v2
- name: Install dependencies
run: npm i
- name: Build the code
run: npm run build
- name: Get PR branch bundle sizes
id: pr_sizes
run: |
echo "pr_client_size=$(du -sk ./build/client/_app/immutable | cut -f1)" >> $GITHUB_ENV
echo "pr_server_size=$(du -sk ./build/server | cut -f1)" >> $GITHUB_ENV
- name: Compute size differences
id: size_diffs
run: |
echo "client_diff=$((${{ env.pr_client_size }} - ${{ env.client_size }}))" >> $GITHUB_ENV
echo "server_diff=$((${{ env.pr_server_size }} - ${{ env.server_size }}))" >> $GITHUB_ENV
- name: Comment PR
uses: mshick/add-pr-comment@v2
with:
message-id: 'bundle-size-comparison'
message: |
📦 Master Branch Client Size: ${{ env.client_size }} KB
🚀 PR Branch Client Size: ${{ env.pr_client_size }} KB
Δ Client Size Difference: ${{ env.client_diff }} KB
🖥️ Master Branch Server Size: ${{ env.server_size }} KB
🚀 PR Branch Server Size: ${{ env.pr_server_size }} KB
Δ Server Size Difference: ${{ env.server_diff }} KB
repo-token: '${{ github.token }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment