name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  upload-assets:
    name: Upload assets (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            os: ubuntu-24.04
          - target: aarch64-unknown-linux-musl
            os: ubuntu-24.04
          - target: x86_64-apple-darwin
            os: macos-15
          - target: aarch64-apple-darwin
            os: macos-15
          - target: x86_64-pc-windows-msvc
            os: windows-2022
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
        with:
          target: ${{ matrix.target }}

      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@20dbac418ca692fd1a9377acf2cec38161169a39 # v1.39.1
        with:
          target: ${{ matrix.target }}
          runner: none
        if: startsWith(matrix.os, 'ubuntu')

      - name: Upload binary to GitHub Release
        uses: taiki-e/upload-rust-binary-action@0e34102c043ded9f2ca39f7af5cd99a540c61aff # v1.29.1
        with:
          bin: clh
          target: ${{ matrix.target }}
          archive: clh-$tag-$target
          token: ${{ secrets.GITHUB_TOKEN }}

