name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  build:
    name: build ${{ matrix.target }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target: [x86_64-unknown-linux-gnu]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --release --target ${{ matrix.target }}
      - name: package
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/aimgr dist/
          cp README.md LICENSE CHANGELOG.md dist/
          tar -czf aimgr-${{ github.ref_name }}-${{ matrix.target }}.tar.gz -C dist .
      - uses: actions/upload-artifact@v7
        with:
          name: aimgr-${{ matrix.target }}
          path: aimgr-*.tar.gz

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          path: artifacts
          merge-multiple: true
      - uses: softprops/action-gh-release@v3
        with:
          files: artifacts/*.tar.gz
          generate_release_notes: true
