---

name: Build on various Operating Systems

on:
  push:
    branches: [devel, master]
  pull_request:
    branches: [devel, master]

env:
  ARTIFACT: lsp-audio-pipewire-lib
  VALGRIND_ARGS: --error-exitcode=255 --leak-check=full --track-origins=yes --keep-debuginfo=yes --suppressions=.github/workflows/valgrind.supp

jobs:
  arch_linux:
    runs-on: ubuntu-latest
    container:
      image: archlinux:latest
    steps:
      - name: Add debug repositories
        run: |
          printf "[core-debug]\nInclude = /etc/pacman.d/mirrorlist\n[extra-debug]\nInclude = /etc/pacman.d/mirrorlist\n[multilib-debug]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
          printf 'Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch\n%s\n' "$(cat /etc/pacman.d/mirrorlist)" > /etc/pacman.d/mirrorlist
      - name: Install dependencies
        run: pacman --noconfirm -Syu base-devel glibc-debug git pipewire pipewire-jack valgrind
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test strict"
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            valgrind ${{env.VALGRIND_ARGS}} .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
  arch_linux_asan:
    runs-on: ubuntu-latest
    container:
      image: archlinux:latest
    steps:
      - name: Add debug repositories
        run: |
          printf "[core-debug]\nInclude = /etc/pacman.d/mirrorlist\n[extra-debug]\nInclude = /etc/pacman.d/mirrorlist\n[multilib-debug]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
          printf 'Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch\n%s\n' "$(cat /etc/pacman.d/mirrorlist)" > /etc/pacman.d/mirrorlist
      - name: Install dependencies
        run: pacman --noconfirm -Syu base-devel glibc-debug pipewire pipewire-jack git
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test debug strict asan"
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
  arch_linux_debug:
    runs-on: ubuntu-latest
    container:
      image: archlinux:latest
    steps:
      - name: Add debug repositories
        run: |
          printf "[core-debug]\nInclude = /etc/pacman.d/mirrorlist\n[extra-debug]\nInclude = /etc/pacman.d/mirrorlist\n[multilib-debug]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
          printf 'Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch\n%s\n' "$(cat /etc/pacman.d/mirrorlist)" > /etc/pacman.d/mirrorlist
      - name: Install dependencies
        run: pacman --noconfirm -Syu base-devel glibc-debug git pipewire pipewire-jack valgrind
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test debug strict"
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            valgrind ${{env.VALGRIND_ARGS}} .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
  opensuse_leap:
    runs-on: ubuntu-latest
    container:
      image: opensuse/leap:latest
    steps:
      - name: Install dependencies
        run: zypper --non-interactive --no-gpg-checks in tar gzip git pipewire-devel pipewire-libjack-0_3-devel make valgrind gcc gcc-c++ glibc-locale
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test strict"
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            valgrind ${{env.VALGRIND_ARGS}} .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
  opensuse_tumbleweed_clang:
    runs-on: ubuntu-latest
    container:
      image: opensuse/tumbleweed:latest
    steps:
      - name: Install dependencies
        run: zypper --non-interactive --no-gpg-checks in tar gzip git pipewire-devel pipewire-libjack-0_3-devel make valgrind gcc gcc-c++ glibc-locale glibc-gconv-modules-extra libstdc++-devel clang
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test strict" CC=clang CXX=clang++
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            valgrind ${{env.VALGRIND_ARGS}} .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
  debian_stable:
    runs-on: ubuntu-latest
    container:
      image: debian:stable
    steps:
      - name: Update repositories
        run: apt-get update
      - name: Install dependencies
        run: apt-get -y install git libpipewire-0.3-dev pipewire-jack libspa-0.2-dev make pkg-config valgrind gcc g++
      - uses: actions/checkout@v3
      - name: Configure project
        run: make config FEATURES="test strict"
      - name: Fetch project dependencies
        run: make fetch
      - name: Build project
        run: make VERBOSE=1
      - name: Run unit tests
        run: .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1
      - name: Run unit tests with memcheck
        run: |
          for test in $(.build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --list --suppress); do \
            echo "***** MEMCHECK $test *****"; \
            valgrind ${{env.VALGRIND_ARGS}} .build/target/${{env.ARTIFACT}}/${{env.ARTIFACT}}-test utest --verbose --jobs 1 --nofork --debug $test; \
          done
