name: Coverage report
on:
  push:
    branches:
      - master
  pull_request:
jobs:
  coverage:
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@v4
    - name: Setup
      run: |
        sudo rm /etc/apt/sources.list.d/microsoft-prod.list
        sudo apt update
        sudo apt install -y lcov libboost-dev
    - name: Compile
      run: |
        ./autogen.sh
        ./configure --disable-shared CXXFLAGS='-O1 -fprofile-arcs -ftest-coverage' LDFLAGS='-lgcov'
        make -j 4
    - name: Capture baseline
      run: |
        mkdir -p coverage tmp
        lcov --no-external --capture --initial --directory . --output-file ./tmp/lcov_base.info
    - name: Run tests
      run: |
        ./test-suite/quantlib-test-suite --log_level=message
    - name: Run examples
      run: |
        make -C Examples check-examples
    - name: Capture coverage
      run: |
        lcov --no-external --capture --directory . --output-file ./tmp/lcov_run.info
        lcov --add-tracefile ./tmp/lcov_base.info --add-tracefile ./tmp/lcov_run.info --output-file ./tmp/lcov_total.info
        lcov --remove ./tmp/lcov_total.info "$PWD/Examples/*" "$PWD/test-suite/*" --output-file ./coverage/lcov.info
    - name: Upload coverage to Coveralls
      uses: coverallsapp/github-action@master
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        path-to-lcov: ./coverage/lcov.info
