name: Coverage

on:
  workflow_dispatch:
  push:
    branches:
      - master
      - develop
      - fixes
      - release/*
  pull_request:
    branches:
      - master
      - develop
      - fixes
      - release/*

jobs:
  coverage:
    runs-on: ubuntu-22.04

    steps:
    - run: |
        sudo apt-get update
        sudo apt-get install -y \
            docbook-xsl \
            lcov \
            libargon2-dev \
            libc-ares-dev \
            libcjson-dev \
            libcjson1 \
            libcunit1-dev \
            libedit-dev \
            libgmock-dev \
            libmicrohttpd-dev \
            libssl-dev \
            libwrap0-dev \
            microsocks \
            python3-all \
            python3-paho-mqtt \
            python3-psutil \
            uthash-dev \
            xsltproc

    - uses: actions/checkout@v6

    - run: |
        make \
          WITH_COVERAGE=yes \
          CFLAGS="-O0 -Wall -ggdb -fprofile-arcs" \
          -j $(nproc) \
          binary
        make \
          WITH_COVERAGE=yes \
          CFLAGS="-O0 -Wall -ggdb -fprofile-arcs" \
          -j $(nproc) \
          test-compile

    - run: |
        make -C test test

    - run: |
        lcov --capture --directory . --output-file coverage.info --no-external

    - uses: codecov/codecov-action@v4
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        fail_ci_if_error: true
        files: ./coverage.info
        verbose: true
