name: Size limit

# ROADMAP TODO #6 — enforces bundle-size budgets defined in
# .size-limit.cjs on every push to main and every PR. Failures block
# merge so that bundle bloat is a visible, deliberate decision.

on:
  push:
    branches: [main]
    paths:
      - 'packages/**'
      - 'pnpm-lock.yaml'
      - 'pnpm-workspace.yaml'
      - 'package.json'
      - '.size-limit.cjs'
      - '.gitea/workflows/size-limit.yml'
  pull_request:
    branches: [main]
    paths:
      - 'packages/**'
      - 'pnpm-lock.yaml'
      - 'pnpm-workspace.yaml'
      - 'package.json'
      - '.size-limit.cjs'

concurrency:
  group: size-limit-${{ github.ref }}
  cancel-in-progress: true

jobs:
  size:
    name: size-limit
    runs-on: [ubuntu-latest, bytelyst, hostinger]
    container:
      image: node:20-bookworm
    timeout-minutes: 10
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          github-server-url: https://gitea.bytelyst.com

      - name: Install pinned pnpm
        run: |
          npm install -g pnpm@10.6.5
          pnpm --version

      - name: Install dependencies
        run: HUSKY=0 pnpm install --frozen-lockfile

      - name: Build measured packages
        # size-limit measures dist/ — ensure every entry in
        # .size-limit.cjs has a fresh build before running.
        run: |
          pnpm --filter @bytelyst/api-client \
               --filter @bytelyst/auth-client \
               --filter @bytelyst/celebrations \
               --filter @bytelyst/quick-actions \
               --filter @bytelyst/react-auth \
               --filter @bytelyst/dashboard-shell \
               --filter @bytelyst/ai-ui \
               --filter @bytelyst/command-palette \
               run build

      - name: Enforce size budgets
        run: pnpm size

      - name: Upload size report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: size-limit-${{ github.run_id }}
          path: |
            .size-limit/
          retention-days: 14
        continue-on-error: true
