name: build

on: [push, pull_request]

jobs:
  build-ubuntu:
    runs-on: ubuntu-20.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
      with:
        submodules: recursive
    - name: Update package database
      run: sudo apt -y update
    - name: Install deps
      run: sudo apt -y install git make gcc-10 g++-10 ccache cmake libyaml-cpp-dev clang-12 libclang-12-dev libclang-cpp12-dev lcov
    - name: Select g++ version
      run: |
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
        sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
    - name: Build and unit test
      run: |
        NUMPROC=2 CMAKE_CXX_FLAGS="--coverage -fno-inline" CMAKE_EXE_LINKER_FLAGS="-lgcov --coverage" make test
    - name: Run coverage
      run: |
        lcov -c -d debug -o coverage.info
        lcov -e coverage.info "$PWD/src/*" -o coverage-src.info
        lcov -l coverage-src.info
    - name: Upload coverage
      uses: codecov/codecov-action@v2
      with:
        files: coverage-src.info
        name: clang-uml
        fail_ci_if_error: true