name: Release

on:
  push:
    tags:
      - 'v*.*.*'

env:
  CARGO_TERM_COLOR: always

jobs:
  create-release:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1

      - name: Build release binaries
        run: |
          cargo build --release --features cli
          mkdir -p artifacts
          cp target/release/realizar artifacts/realizar-linux-x86_64

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          files: artifacts/*
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build-release:
    name: Build Release - ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            artifact_name: realizar
            asset_name: realizar-linux-x86_64
          - os: macos-latest
            artifact_name: realizar
            asset_name: realizar-macos-x86_64
          - os: windows-latest
            artifact_name: realizar.exe
            asset_name: realizar-windows-x86_64.exe

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1

      - name: Build release binary
        run: cargo build --release --features cli

      - name: Upload Release Asset
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.asset_name }}
          path: target/release/${{ matrix.artifact_name }}
