# kilocode_change - new file
name: prepare-jetbrains-release

on:
  workflow_dispatch:
    inputs:
      kind:
        description: "Release kind"
        required: true
        type: choice
        options:
          - rc
          - stable
      version:
        description: "Version, e.g. 7.3.13-rc.1 or 7.3.13"
        required: true
        type: string
      from_tag:
        description: "Optional previous tag for changelog range"
        required: false
        type: string

permissions:
  contents: write
  pull-requests: write

concurrency:
  group: prepare-jetbrains-release-${{ inputs.version }}
  cancel-in-progress: false

jobs:
  prepare:
    if: github.repository == 'Kilo-Org/kilocode'
    runs-on: blacksmith-4vcpu-ubuntu-2404
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Setup Bun
        uses: ./.github/actions/setup-bun

      - name: Setup Git Committer
        id: committer
        uses: ./.github/actions/setup-git-committer
        with:
          kilo-maintainer-app-id: ${{ secrets.KILO_MAINTAINER_APP_ID }}
          kilo-maintainer-app-secret: ${{ secrets.KILO_MAINTAINER_APP_SECRET }}

      - name: Create release tag and PR
        run: |
          args=(--kind "$KIND" --version "$VERSION")
          if [[ -n "$FROM_TAG" ]]; then
            args+=(--from-tag "$FROM_TAG")
          fi
          bun script/jetbrains-release-pr.ts "${args[@]}"
        env:
          GH_TOKEN: ${{ steps.committer.outputs.token }}
          GH_REPO: ${{ github.repository }}
          KIND: ${{ inputs.kind }}
          VERSION: ${{ inputs.version }}
          FROM_TAG: ${{ inputs.from_tag }}
