name: build

on:
  push:
    paths-ignore:
      - 'docs/**'
      - 'packaging/**'
      - 'util/**'
      - 'uml/**'
      - '**.md'
    branches-ignore:
      - 'noactions/*'
  pull_request:
    paths-ignore:
      - 'docs/**'
      - 'packaging/**'
      - 'util/**'
      - 'uml/**'
      - '**.md'
      - '**.svg'
      - '**.png'
    branches-ignore:
      - 'noactions/*'

jobs:
  build-ubuntu:
    runs-on: ubuntu-22.04
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3
    - name: Update package database
      run: sudo apt -y update
    - name: Install deps
      run: sudo apt -y install git make pkg-config gcc-11 g++-11 ccache cmake libyaml-cpp-dev llvm-15 clang-15 libclang-15-dev libclang-cpp15-dev clang-format-15 lcov zlib1g-dev libunwind-dev libdw-dev
    - name: Select g++ version
      run: |
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
        sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11
    - name: Check code formatting
      run: |
        make check-formatting
    - name: Build and unit test
      run: |
        NUMPROC=2 CMAKE_CXX_FLAGS="--coverage -fno-inline" CMAKE_EXE_LINKER_FLAGS="-lgcov --coverage" LLVM_VERSION=15 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@v3
      with:
        files: coverage-src.info
        name: clang-uml
        fail_ci_if_error: true