Skip to content

feat: report bundle size #1

feat: report bundle size

feat: report bundle size #1

Workflow file for this run

name: Bundle Size
on:
pull_request:
types: [opened, synchronize]
branches: [canary]
permissions:
contents: read
pull-requests: write
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_CACHE_SIGNATURE_KEY: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
BIGCOMMERCE_STORE_HASH: ${{ vars.BIGCOMMERCE_STORE_HASH }}
BIGCOMMERCE_CHANNEL_ID: ${{ vars.BIGCOMMERCE_CHANNEL_ID }}
BIGCOMMERCE_CLIENT_ID: ${{ secrets.BIGCOMMERCE_CLIENT_ID }}
BIGCOMMERCE_CLIENT_SECRET: ${{ secrets.BIGCOMMERCE_CLIENT_SECRET }}
BIGCOMMERCE_STOREFRONT_TOKEN: ${{ secrets.BIGCOMMERCE_STOREFRONT_TOKEN }}
BIGCOMMERCE_ACCESS_TOKEN: ${{ secrets.BIGCOMMERCE_ACCESS_TOKEN }}
jobs:
bundle-size:
name: Bundle Size Report
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: pnpm/action-setup@v3
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build catalyst
run: pnpm build
- name: Analyze bundle size
run: node scripts/analyze-bundle-size.mjs --build-dir core/.next --output /tmp/bundle-current.json
- name: Compare with baseline
id: compare
run: |
if [ -f bundle-baseline.json ]; then
node scripts/compare-bundle-size.mjs --baseline bundle-baseline.json --current /tmp/bundle-current.json --output /tmp/bundle-report.md
else
node scripts/compare-bundle-size.mjs --no-baseline --current /tmp/bundle-current.json --output /tmp/bundle-report.md
fi
- name: Post or update PR comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const marker = '<!-- bundle-size-report -->';
const report = fs.readFileSync('/tmp/bundle-report.md', 'utf-8');
const body = `${marker}\n${report}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Check for warnings
run: |
if [ -f /tmp/bundle-report.md.warnings ]; then
echo "::warning::Bundle size increased significantly. Review the bundle size report in the PR comment."
fi