name: Build Release

on:
  push:
    tags:
    - "*"

jobs:
  release:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    environment: default
    strategy:
      matrix:
        name: [ windows-x64, windows-arm, macos-x64, macos-arm, linux-x64, linux-arm ]

        include:
        - name: windows-x64
          os: windows-latest
          artifact_name: target/release/kumono.exe
          asset_name: target/release/kumono-windows-x64.exe
        - name: windows-arm
          os: windows-11-arm
          artifact_name: target/release/kumono.exe
          asset_name: target/release/kumono-windows-arm64.exe
        - name: macos-x64
          os: macos-15-intel
          artifact_name: target/release/kumono
          asset_name: target/release/kumono-macos-x64
        - name: macos-arm
          os: macos-latest
          artifact_name: target/release/kumono
          asset_name: target/release/kumono-macos-arm64
        - name: linux-x64
          os: ubuntu-latest
          artifact_name: target/release/kumono
          asset_name: target/release/kumono-linux-x64
        - name: linux-arm
          os: ubuntu-24.04-arm
          artifact_name: target/release/kumono
          asset_name: target/release/kumono-linux-arm64

    steps:
    - uses: actions/checkout@v2

    - uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable

    - name: Build
      run: |
        cargo build --release
        mv ${{ matrix.artifact_name }} ${{ matrix.asset_name }}

    - name: Make Release
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: ${{ matrix.asset_name }}
        fail_on_unmatched_files: true
        draft: false

  publish:
    name: Publish crate
    runs-on: ubuntu-latest
    environment: default
    needs: release

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Install Rust toolchain
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable

    - name: Publish crate
      run: |
        cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }}
        cargo publish --no-verify
