name: CentOs

on:
  push:
    branches:
      - main
      - tmp
  pull_request:
    branches:
      - main
    types: [opened, synchronize, reopened]
  release:
    types: [created]

jobs:
  centos8:
    runs-on: ubuntu-latest
    container: 'centos:8'
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: false
          fetch-depth: 1
      - name: Install CentOs Prerequisites
        run: |
          sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
          sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
          yum -y update
          yum -y install curl gpg
          curl 'https://packages.ntop.org/centos/ntop.repo' > /etc/yum.repos.d/ntop.repo
          curl 'https://packages.ntop.org/centos/RPM-GPG-KEY-deri' | gpg --import
          yum -y install yum-utils dnf-plugins-core epel-release
          dnf config-manager --set-enabled powertools
          yum -y update
          yum -y install rpm-build gcc gcc-c++ autoconf automake make cmake flex bison gettext pkg-config libtool ndpi-dev libpcap-devel zlib-devel python3.8 git wget unzip /usr/lib64/libasan.so.5.0.0 /usr/lib64/libubsan.so.1.0.0
          repoquery -l ndpi-dev
      - name: Configure nDPId
        run: |
          mkdir build && cd build
          cmake .. -DENABLE_SYSTEMD=ON -DBUILD_EXAMPLES=ON -DENABLE_SANITIZER=ON -DNDPI_NO_PKGCONFIG=ON -DSTATIC_LIBNDPI_INSTALLDIR=/usr
      - name: Build nDPId
        run: |
          make -C build all VERBOSE=1
      - name: CPack RPM
        run: |
          cd ./build && cpack -G RPM && cd ..
      - name: Upload RPM
        uses: actions/upload-artifact@v3
        with:
          name: nDPId-centos-packages
          path: build/*.rpm
      - name: Upload on Failure
        uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: autoconf-config-log
          path: |
            build/CMakeCache.txt
            libnDPI/config.log
