name: Publish Release

permissions:
  contents: write

on:
  push:
    tags:
      - "v*" # Only triggers when you push a tag like v1.0.0
  workflow_dispatch:

jobs:
  release:
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            archive: pryr-x86_64-unknown-linux-gnu.tar.gz
            is_windows: false
          - os: windows-latest
            archive: pryr-x86_64-pc-windows-msvc.zip
            is_windows: true

    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Build app
        run: cargo build --release

      - name: Package Binaries (Linux)
        if: matrix.is_windows == false
        run: |
          cd target/release
          tar -czvf ../../${{ matrix.archive }} pryr pryrd

      - name: Package Binaries (Windows)
        if: matrix.is_windows == true
        shell: pwsh
        run: |
          cd target/release
          Compress-Archive -Path pryr.exe, pryrd.exe -DestinationPath ../../${{ matrix.archive }}

      - name: Upload to GitHub Releases
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: ${{ matrix.archive }}
          append_body: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
