name: Release

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
  create-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    outputs:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true

  build-release:
    name: Build and Upload Binaries
    needs: create-release
    strategy:
      matrix:
        include:
          # Standard Linux (Ubuntu/Debian)
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          # ARM64 Linux (AWS Graviton, ARM CI runners)
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          # Statically linked Linux (Alpine containers - CRITICAL for CI)
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
          # macOS Intel
          - target: x86_64-apple-darwin
            os: macos-latest
          # macOS Apple Silicon (M1/M2/M3)
          - target: aarch64-apple-darwin
            os: macos-latest
          # Windows x86_64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          # Windows ARM64
          - target: aarch64-pc-windows-msvc
            os: windows-latest
    runs-on: ${{ matrix.os }}
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build and Upload Binary
        uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: safe-migrate
          target: ${{ matrix.target }}
          token: ${{ secrets.GITHUB_TOKEN }}
