name: "Code Coverage"
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
jobs:
  build:
    name: Build
    runs-on: ubuntu-20.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y autopoint build-essential libdbi-dev libtool-bin tcl-dev lua5.1 liblua5.1-0-dev \
                                valgrind dc python3-pip python3-setuptools libpango1.0-dev ghostscript gettext
        sudo pip install cpp-coveralls
    
    - name: Build
      run: |
        V=$(cat VERSION)
        ./bootstrap
        ./configure --prefix=/opt/rrdtool-master \
                    CFLAGS='-fprofile-arcs -ftest-coverage -O0' \
                    LIBS=-lgcov
        make
        sudo make install
        /opt/rrdtool-master/bin/rrdtool
        /opt/rrdtool-master/share/rrdtool/examples/4charts.pl
    - name: Run Checks
      run: |
        make check
    - name: Test bindings
      run: |
        (cd bindings/perl-shared && make test)
        (cd bindings/python && sudo chown -R $USER . && python setup.py test)
    - name: Run "rrdcached-tcp"
      run: |  
        make check TESTS_STYLE="rrdcached-tcp"
    - name: Run "rrdcached-udp"
      run: |
        make check TESTS_STYLE="rrdcached-unix"
    - name: Run valgrind
      run: |
        make check TESTS_STYLE="valgrind-logfile" TESTS="modify1 modify2 modify3 modify4 modify5 tune1 tune2 graph1 rrdcreate dump-restore create-with-source-1 create-with-source-2 create-with-source-3 create-with-source-4 create-with-source-and-mapping-1 create-from-template-1 dcounter1 vformatter1 list1 pdp-calc1"
        podchecker doc/*.pod
    - name: gcov
      run: |
        (cd src && gcov *.gcno)
        (cd src && gcov .libs/*.gcno)
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v3    
