name: Build Debian/Redhat packages

on:
  push:
    # Pattern matched against refs/tags
    tags:
      - "*" # Push events to every tag not containing /
      # Allow manual triggering
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-22.04

    steps:
      - name: Checkout sources
        uses: actions/checkout@v4
      - name: Use latest Rust stable toolchain
        uses: dtolnay/rust-toolchain@nightly
      - name: Install build deps
        run: sudo apt-get install -y libacl1-dev
      - name: Install cargo-deb
        run: cargo install cargo-deb
      - name: Build package with cargo-deb
        run: cargo deb --install --separate-debug-symbols --compress-debug-symbols --profile deb -- --locked --features "std" --features "acls"
      - name: Install alien
        run: sudo apt-get install -y alien
      - name: Convert deb to rpm with alien
        working-directory: target/debian
        run: sudo alien --to-rpm httm_*.deb
      - name: Upload binaries to release
        uses: softprops/action-gh-release@v2
        if: ${{startsWith(github.ref, 'refs/tags/') }}
        with:
          files: target/debian/httm*.*
      - name: Upload both build artifacts to GH action
        uses: actions/upload-artifact@v4
        with:
          name: cargo-deb-upload
          path: target/debian/httm*.*

  # publish:
  #   runs-on: ubuntu-20.04
  #   steps:
  #   - name: Checkout sources
  #     uses: actions/checkout@v3
  #   - name: cargo publish
  #     env:
  #       CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  #     run: cargo login "$CARGO_REGISTRY_TOKEN" && cargo publish --token "$CARGO_REGISTRY_TOKEN"
