name: Release

on:
  push:
    branches:
      - main
      - dev
  workflow_dispatch:

permissions:
  contents: write
  issues: write
  pull-requests: write
  id-token: write

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

jobs:
  release:
    name: Semantic release
    runs-on: ubuntu-latest
    if: github.repository == 'nextlevelbuilder/ui-ux-pro-max-skill'

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: npm
          cache-dependency-path: cli/package-lock.json

      - name: Install CLI dependencies
        working-directory: cli
        run: npm ci

      - name: Build CLI
        working-directory: cli
        run: bun run build

      - name: Run semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          npx --yes \
            -p semantic-release \
            -p @semantic-release/commit-analyzer \
            -p @semantic-release/release-notes-generator \
            -p @semantic-release/github \
            -p conventional-changelog-conventionalcommits \
            semantic-release
