name: Build and Release

on:
  push:
    branches: [main, next, beta, develop]
    paths-ignore:
      - 'docs/**'

permissions:
  contents: write

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  release:
    name: Build
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v4

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: '1.3.1'

      - name: Cache Bun dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.bun
            node_modules
          key: ${{ runner.os }}-bun-cache-${{ hashFiles('**/bun.lock') }}
          restore-keys: |
            ${{ runner.os }}-bun-cache-

      - name: Install deps
        run: bun install --frozen-lockfile

      - name: Build
        run: bun run build

      - name: Release
        id: release
        run: bun run release
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
