name: Coverage Analysis

on:
  push:
    branches: [ master ]
  pull_request:

  workflow_dispatch:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-16.04]
      fail-fast: false
    env:
      BUILD_TYPE: Coverage



    steps:
      - uses: actions/checkout@v2

      - name: ccache
        uses: hendrikmuhs/ccache-action@v1

      - name: Install dependencies (Linux)
        run: |
          ./scripts/install_linux_deps.sh
          ./scripts/install_linux_fmt_deps.sh

      - name: Install Coverage
        run: |
          wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.14.orig.tar.gz
          tar xf lcov_1.14.orig.tar.gz
          sudo make -C lcov-1.14/ install

      - name: Run tests for coverage
        run: |
          mkdir build
          cd build
          cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
          make
          make CTEST_OUTPUT_ON_FAILURE=1 test

      - name: Run lcov
        run: |
          set -x
          cd build
          lcov --directory . --capture --output-file coverage.info
          lcov --remove coverage.info 'test/*' '/usr/*' --output-file coverage.info
          lcov --list coverage.info
          ls
          pwd

      - name: Coveralls
        uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: /home/runner/work/Sophus/Sophus/build/coverage.info
