# Copyright (c) 2021 Morwenn
# SPDX-License-Identifier: MIT

name: Ubuntu Builds

on:
  push:
    paths:
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'examples/**'
      - 'include/**'
      - 'testsuite/**'
  pull_request:
    paths:
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'examples/**'
      - 'include/**'
      - 'testsuite/**'

jobs:
  build:
    runs-on: ubuntu-16.04

    strategy:
      fail-fast: false
      matrix:
        # Default configuration corresponds to a release
        # build without additional tooling, also provides
        # default options for other builds
        cxx:
          - g++-5
          - clang++-6.0
        build_type: [Release]
        sanitize: ['']
        valgrind: [OFF]

        # Below are debug builds with tooling
        include:
          # GCC builds
          - cxx: g++-5
            build_type: Debug
            valgrind: ON
          - cxx: g++-5
            build_type: Debug
            sanitize: address
          - cxx: g++-5
            build_type: Debug
            sanitize: undefined
          # Clang builds
          - cxx: clang++-6.0
            build_type: Debug
            valgrind: ON
          - cxx: clang++-6.0
            build_type: Debug
            sanitize: address
          - cxx: clang++-6.0
            build_type: Debug
            sanitize: undefined

    steps:
      - uses: actions/checkout@v2

      - name: Install Valgrind
        if: ${{matrix.valgrind == 'ON'}}
        run: sudo apt install -y valgrind

      - name: Configure CMake
        working-directory: ${{runner.workspace}}
        env:
          CXX: ${{matrix.cxx}}
        run: |
          cmake -H${{github.event.repository.name}} -Bbuild \
                -DCMAKE_CONFIGURATION_TYPES=${{matrix.build_type}} \
                -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
                -DSANITIZE=${{matrix.sanitize}} \
                -DUSE_VALGRIND=${{matrix.valgrind}} \
                -G"Unix Makefiles" \
                -DBUILD_EXAMPLES=ON

      - name: Build the test suite
        shell: bash
        working-directory: ${{runner.workspace}}/build
        run: cmake --build . --config ${{matrix.build_type}} -j 2

      - name: Run the test suite with Memcheck
        if: ${{matrix.valgrind != 'ON'}}
        env:
          CTEST_OUTPUT_ON_FAILURE: 1
        working-directory: ${{runner.workspace}}/build
        run: ctest -C ${{matrix.build_type}}

      - name: Run the test suite
        if: ${{matrix.valgrind == 'ON'}}
        env:
          CTEST_OUTPUT_ON_FAILURE: 1
        working-directory: ${{runner.workspace}}/build
        run: |
          ctest -T memcheck -C ${{matrix.build_type}} -j 2
          find ./Testing/Temporary -name "MemoryChecker.*.log" -size +1300c | xargs cat;

Add a GitHub Action for Ubuntu builds
Add a GitHub Action for Ubuntu builds

The actions tests both g++ 5.5 and clang++ 6, with ubsan, asan and
Valgrind memcheck.

[ci skip]
