name: Build Release Binaries

on:
  push:
    branches:
      - main
      - 'feat/*'
    tags:
      - 'v*'
    paths-ignore:
      - '.gitea/**'
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  build-amd64:
    runs-on: ubuntu-latest
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - uses: actions/checkout@v4

      - name: Init submodules
        run: |
          git config --global url."https://git.manko.yoga/".insteadOf "ssh://git@git.manko.yoga:222/"
          git submodule update --init --recursive

      - name: Install Rust + dependencies
        run: |
          curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
          source "$HOME/.cargo/env"
          apt-get update && apt-get install -y cmake pkg-config libasound2-dev ninja-build
          rustc --version

      - name: Build relay + tools
        run: |
          source "$HOME/.cargo/env"
          cargo build --release --bin wzp-relay --bin wzp-client --bin wzp-bench --bin wzp-web

      - name: Run tests
        run: |
          source "$HOME/.cargo/env"
          cargo test --workspace --lib

      - name: Upload to rustypaste
        env:
          PASTE_AUTH: ${{ secrets.PASTE_AUTH }}
          PASTE_URL: ${{ secrets.PASTE_URL }}
        run: |
          tar czf /tmp/wzp-linux-amd64.tar.gz \
            -C target/release wzp-relay wzp-client wzp-web wzp-bench
          ls -lh /tmp/wzp-linux-amd64.tar.gz
          LINK=$(curl -sF "file=@/tmp/wzp-linux-amd64.tar.gz" \
            -H "Authorization: ${PASTE_AUTH}" \
            "https://${PASTE_URL}")
          echo "Download: ${LINK}"
