name: GitHub Release

on:
  workflow_dispatch:

permissions:
  contents: write

env:
  CURRENT_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
  create-github-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v5
        with:
          ref: ${{ env.CURRENT_BRANCH_NAME }}
          fetch-depth: 0

      - name: Extract version from branch
        id: extract
        run: .github/scripts/extract_version.sh "${{ env.CURRENT_BRANCH_NAME }}"

      - name: Validate version format
        id: validate
        run: .github/scripts/validate_semver.sh "${{ steps.extract.outputs.version }}"

      - name: Extract release notes
        id: release-notes
        run: .github/scripts/extract_release_notes.sh "${{ steps.extract.outputs.version }}"

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ steps.extract.outputs.version }}
          name: Release ${{ steps.extract.outputs.version }}
          body_path: release_notes.md
          prerelease: ${{ steps.validate.outputs.is_prerelease }}
          draft: false
