name: FluidSynth Linux

on:
  pull_request:
  push:
    paths-ignore:
      - '.azure/**'
      - '.circleci/**'
      - '.github/workflows/sonarcloud.yml'
      - '.cirrus.yml'
      - 'README.md'

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: RelWithDebInfo

jobs:
  build:
    # The CMake configure and build commands are platform agnostic and should work equally
    # well on Windows or Mac.  You can convert this to a matrix build if you need
    # cross-platform coverage.
    # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        CC: [""]
        CXX: [""]
        CMAKE_FLAGS: ["-Denable-profiling=1","-Denable-floats=1 -Denable-profiling=1","-Denable-floats=1","-Denable-trap-on-fpe=1","-Denable-fpe-check=1","-Denable-ipv6=0","-Denable-network=0","-Denable-aufile=0","-DBUILD_SHARED_LIBS=0","-Denable-ubsan=1 -Denable-debug=1", "-Denable-debug=1 -DCMAKE_C_FLAGS_DEBUG=-fuse-ld=gold"]
        include:
          - CC: "clang-7"
            CXX: "clang++-7"
            CMAKE_FLAGS: ""
          - CC: "clang-8"
            CXX: "clang++-8"
            CMAKE_FLAGS: ""
          - CC: "clang-10"
            CXX: "clang++-10"
            CMAKE_FLAGS: ""
          - CC: "clang-12"
            CXX: "clang++-12"
            CMAKE_FLAGS: ""
# clang9 is covered by openSUSE Leap 15.2
# clang11 is covered by openSUSE Leap 15.3

    steps:
    - uses: actions/checkout@v2

    - name: Add apt-get repositories
      run: |
        sudo add-apt-repository ppa:ubuntu-toolchain-r/test

    - name: Update apt
      run: sudo apt-get update -y

    - name: Install Dependencies
      run: sudo -E apt-get -yq --no-install-suggests --no-install-recommends install cmake-data cmake libglib2.0-0 libsndfile-dev libasound2-dev libjack-dev portaudio19-dev libsdl2-dev libpulse-dev libdbus-1-dev libsystemd-dev libinstpatch-dev libreadline-dev g++-7 g++-8 clang-7 clang-8 clang-9 clang-10 clang-tidy-10

    - name: Create Build Environment
      # Some projects don't allow in-source building, so create a separate build directory
      # We'll use this as our working directory for all subsequent commands
      run: |
        echo Can execute `nproc` make jobs in parallel
        cmake --version
        cmake -E make_directory ${{github.workspace}}/build
        sudo ln -s /usr/bin/clang-tidy-10 /usr/bin/clang-tidy
        which clang-tidy || true
        ls -la `which clang-tidy` || true
        echo $PATH
        echo $SONARSC

    - name: Configure CMake
      # Use a bash shell so we can use the same syntax for environment variable
      # access regardless of the host operating system
      shell: bash
      working-directory: ${{github.workspace}}/build
      # Note the current convention is to use the -S and -B options here to specify source 
      # and build directories, but this is only available with CMake 3.13 and higher.  
      # The CMake binaries on the Github Actions machines are (as of this writing) 3.12
      run: |
        export CC=${{ matrix.CC }}
        export CXX=${{ matrix.CXX }}
        cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -Werror=dev ${{ matrix.CMAKE_FLAGS }} -DCMAKE_INSTALL_PREFIX=$HOME/fluidsynth_install -Denable-portaudio=1 -Denable-ladspa=1 -DCMAKE_VERBOSE_MAKEFILE=1 -DNO_GUI=1 $GITHUB_WORKSPACE

    - name: Build
      working-directory: ${{github.workspace}}/build
      shell: bash
      # Execute the build.  You can specify a specific target with "--target <NAME>"
      run: make -j`nproc`

    - name: Test
      working-directory: ${{github.workspace}}/build
      shell: bash
      # Execute tests defined by the CMake configuration.
      run: make -j`nproc` check

    - name: Demo
      working-directory: ${{github.workspace}}/build
      shell: bash
      run: make -j`nproc` demo

    - name: Install
      working-directory: ${{github.workspace}}/build
      run: make install
