name: Scripts

on:
  workflow_dispatch:
  pull_request:
    branches:
      - "main"
    paths:
      - "packages/astro/src/runtime/client/**/*"
      - "!packages/astro/src/runtime/client/dev-toolbar/**/*"

permissions: {}

# Automatically cancel in-progress actions on the same branch
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
  cancel-in-progress: true

defaults:
  run:
    shell: bash

jobs:
  bundle:
    name: Bundle Size
    runs-on: ubuntu-latest
    permissions:
      contents: read # Checkout only
      pull-requests: write # Post bundle size comparison comment
    steps:
      - name: Checkout Repo
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Checkout Main into tmp
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          ref: main
          path: main

      - name: Setup PNPM
        uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8

      - name: Setup Node
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: 24.15.0
          cache: "pnpm"

      - name: Install dependencies
        run: pnpm install

      - name: Check Bundle Size
        uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
        with:
          script: |
            const { default: script } = await import('${{ github.workspace }}/.github/scripts/bundle-size.mjs')
            await script({ github, context })
