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-20.04

    steps:
    - name: Checkout sources
      uses: actions/checkout@v3
    - name: Install build dep 
      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 --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@v1
      if: ${{startsWith(github.ref, 'refs/tags/') }}
      with:
          files: target/debian/httm*.*
    - name: Upload both build artifacts to GH action
      uses: actions/upload-artifact@v3.1.0
      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"
