name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact: traceable-reqs
            asset_suffix: linux-x86_64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact: traceable-reqs.exe
            asset_suffix: windows-x86_64.exe
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact: traceable-reqs
            asset_suffix: macos-arm64
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        working-directory: rust
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: rust
      - run: cargo build --release --target ${{ matrix.target }}
      - name: Stage asset
        shell: bash
        run: |
          mkdir -p ../dist
          cp target/${{ matrix.target }}/release/${{ matrix.artifact }} \
             ../dist/traceable-reqs-${{ github.ref_name }}-${{ matrix.asset_suffix }}
      - uses: softprops/action-gh-release@v2
        with:
          files: dist/traceable-reqs-${{ github.ref_name }}-${{ matrix.asset_suffix }}
          fail_on_unmatched_files: true
