name: Build

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'

jobs:
  build-arch:
    runs-on: ubuntu-latest
    container:
      image: archlinux:latest
    steps:
      - uses: actions/checkout@v2

      - name: Install dependencies
        run: |
          pacman -Syu --noconfirm base-devel rust
          useradd builder -m -G wheel
          echo 'builder ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

      - name: Build Arch package
        run: |
          chown -R builder:builder .
          cd build/arch
          sudo -u builder bash -c "makepkg -sf --noconfirm"

      - name: Print current directory
        run: ls -la

      - name: Upload Arch package
        uses: actions/upload-artifact@v2
        with:
          name: rustmon.pkg.tar.zst
          path: ./build/arch/*.pkg.tar

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install dependencies
        run: sudo apt-get install -y dpkg-dev

      - name: Build Debian package
        run: |
          cd build/debian
          sh debian.sh -y

      - name: Upload Debian package
        uses: actions/upload-artifact@v2
        with:
          name: rustmon.deb
          path: build/debian/rustmon.deb
