name: size report
on:
  workflow_dispatch:
  pull_request:
    types: [opened, reopened, synchronize, ready_for_review]

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  size-report:
    name: size report
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions: write-all

    steps:
      - name: Clone repository
        uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 18

      - name: Set up Bun
        uses: oven-sh/setup-bun@v2
        with:
          scope: "@silencelaboratories"
          registry-url: "https://registry.npmjs.org"
          bun-version: "latest"

      - name: Install dependencies
        shell: bash
        run: bun install --frozen-lockfile
        env:
          VITE_SILENCE_LABS_NPM_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
          BUN_AUTH_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
  
      - name: Build
        shell: bash
        run: bun run build
        env:
          VITE_SILENCE_LABS_NPM_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
          BUN_AUTH_TOKEN: ${{ secrets.VITE_SILENCE_LABS_NPM_TOKEN }}
  
      - name: Report bundle size
        uses: andresz1/size-limit-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          package_manager: bun
