name: Build

on: [push, pull_request]

jobs:
  build:
    name: Build and test Thug on ${{ matrix.os }}
    runs-on: ubuntu-18.04
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        os: [ubuntu-18.04]

    steps:
      - name: STEP 1. Checkout repository
        uses: actions/checkout@v2

      - name: STEP 2. Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: STEP 3. Install libemu
        run: |
          git clone https://github.com/buffer/libemu.git
          cd libemu
          autoreconf -v -i
          ./configure
          sudo make install
          cd -
          sudo ldconfig

      - name: STEP 4. Install dependencies
        run: |
          sudo apt-get install python python3 python3-dev
          sudo apt-get install build-essential libboost-dev libboost-system-dev libboost-python-dev systemtap-sdt-dev
          sudo apt-get install libfuzzy-dev graphviz libgraphviz-dev tesseract-ocr unrar xfonts-base xfonts-75dpi
          wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb
          sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

      - name: STEP 5. Install Tox
        run: |
          pip3 install tox tox-gh-actions

      - name: STEP 6. Build Thug
        run: |
          sudo mkdir -p /etc/thug/{rules,personalities,scripts}
          sudo cp -R thug/Classifier/rules/* /etc/thug/rules/
          sudo cp -R thug/DOM/personalities/* /etc/thug/personalities
          sudo cp -t /etc/thug/scripts thug/DOM/{thug.js,storage.js,date.js,eval.js,write.js}
          sudo cp -t /etc/thug/ conf/thug.conf
          sudo cp -t /etc/thug/ conf/inspector.json

      - name: STEP 7. Test Thug
        run: |
          tox
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
