---
name: Quick Tests

# yamllint disable-line rule:truthy
on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  smoketest:
    name: Smoke test
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Fix Checkout
        run: |
          git fetch --force --tags

      - name: Run minimal test set
        run: |
          ./autogen.sh
          ./configure
          make -j4 all
          make test

      - if: ${{ failure() }}
        name: Upload tests output
        uses: actions/upload-artifact@v6
        with:
          name: tests-smoketest
          path: tests

  smoketest_all_opts:
    name: Smoke test With all options turned on
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Fix Checkout
        run: |
          git fetch --force --tags

      - name: Install libraries needed for all options turned on
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libminiupnpc-dev \
            libnatpmp-dev \
            libpcap-dev \
            libcap-dev \
            libzstd-dev

      - name: Run minimal test set
        run: |
          ./autogen.sh
          ./configure \
            --enable-pthread \
            --enable-miniupnp \
            --enable-natpmp \
            --enable-cap \
            --enable-pcap \
            --with-openssl \
            --with-zstd \
            CFLAGS="-O3 -fprofile-arcs -ftest-coverage"
            LDFLAGS="--coverage"
          make build-dep
          make -j4 all examples
          make test

      - name: Generate coverage reports
        run: |
          make gcov
          make cover COVERAGEDIR=coverage/ubuntu-22.04
        shell: bash

      - name: Upload gcovr report artifact
        uses: actions/upload-artifact@v6
        with:
          name: coverage
          path: coverage

      - name: Upload data to codecov
        uses: codecov/codecov-action@v7
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  lint:
    name: Code syntax
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Fix Checkout
        run: |
          git fetch --force --tags


      - name: Make the makefiles
        run: |
          ./autogen.sh
          ./configure

      - name: Install essential
        run: |
          sudo apt update
          make build-dep

      - name: Run the lint tools
        run: |
          make lint
