name: Build release binaries

on:
  push:
    tags:
      - v*

jobs:
  build-x86_64-apple-darwin:
    runs-on: macos-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup target add x86_64-apple-darwin
      - run: cargo build --target x86_64-apple-darwin --release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.x86_64-apple-darwin
          path: ./target/x86_64-apple-darwin/release/repo
      - run: mv ./target/x86_64-apple-darwin/release/repo repo.${{ github.ref_name }}.x86_64-apple-darwin
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.x86_64-apple-darwin

  build-aarch64-apple-darwin:
    runs-on: macos-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain list
      - run: make build-release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.aarch64-apple-darwin
          path: ./target/release/repo
      - run: mv ./target/release/repo repo.${{ github.ref_name }}.aarch64-apple-darwin
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.aarch64-apple-darwin

  build-x86_64-pc-windows:
    runs-on: windows-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain list
      - run: make build-release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.x86_64-pc-windows
          path: ./target/release/repo.exe
      - run: mv ./target/release/repo.exe repo.${{ github.ref_name }}.x86_64-pc-windows
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.x86_64-pc-windows

  build-aarch64-pc-windows:
    runs-on: windows-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain list
      - run: make build-release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.aarch64-pc-windows
          path: ./target/release/repo.exe
      - run: mv ./target/release/repo.exe repo.${{ github.ref_name }}.aarch64-pc-windows
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.aarch64-pc-windows

  build-x86_64-unknown-linux-gnu:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain list
      - run: make build-release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.x86_64-unknown-linux-gnu
          path: ./target/release/repo
      - run: mv ./target/release/repo repo.${{ github.ref_name }}.x86_64-unknown-linux-gnu
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.x86_64-unknown-linux-gnu

  build-aarch64-unknown-linux-gnu:
    runs-on: ubuntu-24.04-arm
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain list
      - run: make build-release
      - uses: actions/upload-artifact@v4
        with:
          name: repo.aarch64-unknown-linux-gnu
          path: ./target/release/repo
      - run: mv ./target/release/repo repo.${{ github.ref_name }}.aarch64-unknown-linux-gnu
      - uses: softprops/action-gh-release@v2
        with:
          files: repo.${{ github.ref_name }}.aarch64-unknown-linux-gnu
