Skip to content

feat: report bundle size delta #8

feat: report bundle size delta

feat: report bundle size delta #8

Workflow file for this run

name: Bundle Size
# Reports the bundle size impact of a PR by comparing the current build against
# a live build of the base branch (canary or integrations/makeswift).
#
# Both branches are checked out side-by-side and built in the same job.
# The base branch is determined at runtime from core/package.json in the PR checkout.
#
# Results are posted as a PR comment and written to the job summary.
on:
pull_request:
types: [opened, synchronize]
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
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
path: pr
- name: Detect baseline branch
id: baseline
run: |
PKG_NAME=$(node -p "require('./pr/core/package.json').name")
if [ "$PKG_NAME" = "@bigcommerce/catalyst-makeswift" ]; then
echo "branch=integrations/makeswift" >> $GITHUB_OUTPUT
else
echo "branch=canary" >> $GITHUB_OUTPUT
fi
- name: Checkout baseline branch
uses: actions/checkout@v4
with:
ref: ${{ steps.baseline.outputs.branch }}
path: baseline
- uses: pnpm/action-setup@v4
with:
package_json_file: pr/package.json
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: pr/.nvmrc
cache: pnpm
cache-dependency-path: pr/pnpm-lock.yaml
- name: Install PR dependencies
run: pnpm install --frozen-lockfile
working-directory: pr
- name: Build PR branch
run: pnpm build
working-directory: pr
- name: Generate PR bundle size
run: node .github/scripts/bundle-size.mjs generate --output /tmp/bundle-current.json --sha ${{ github.sha }}
working-directory: pr
- name: Install baseline dependencies
run: pnpm install --frozen-lockfile
working-directory: baseline
- name: Build baseline
run: pnpm build
working-directory: baseline
- name: Generate baseline bundle size
run: |
SHA=$(git rev-parse --short HEAD)
node .github/scripts/bundle-size.mjs generate --output /tmp/bundle-baseline.json --sha $SHA
working-directory: baseline
- name: Compare against baseline
run: node .github/scripts/bundle-size.mjs compare --baseline /tmp/bundle-baseline.json --current /tmp/bundle-current.json > /tmp/bundle-report.md
working-directory: pr
- name: Write to job summary
run: cat /tmp/bundle-report.md >> "$GITHUB_STEP_SUMMARY"
- name: Post or update PR comment
uses: actions/github-script@v7
with:
script: |
const postComment = require('./pr/.github/scripts/post-bundle-comment.js')
await postComment({ github, context })