name: CI
on: [push]
jobs:
  linux:
    name: '${{ matrix.os }}: ${{ matrix.compiler.vendor }}'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-22.04
          - ubuntu-20.04
        compiler:
          - vendor: gnu
            env: { CC: gcc }
          - vendor: llvm
            env: { CC: clang, CFLAGS: -gdwarf-4 }
    steps:
    - name: checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 1
    - name: deps
      run: sudo apt-get update -qq &&
           sudo apt-get install --no-install-recommends -y
               gcc
               git
               libyaml-dev
               make
               valgrind
    - name: build
      env: ${{ matrix.compiler.env }}
      run: make
    - name: tests
      env: ${{ matrix.compiler.env }}
      run: make test
    - name: valgrind
      env: ${{ matrix.compiler.env }}
      run: make valgrind-quiet
    - name: sanitize
      env: ${{ matrix.compiler.env }}
      run: make VARIANT=san test

  mac:
    name: 'macos: ${{ matrix.compiler.vendor }}'
    runs-on: macos-latest
    strategy:
      fail-fast: false
      matrix:
        compiler:
          - vendor: gnu
            env: { CC: gcc }
          - vendor: llvm
            env: { CC: clang }
    steps:
    - name: checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 1
    - name: deps
      run: brew update && brew install
               libyaml
    - name: build
      env: ${{ matrix.compiler.env }}
      run: LDFLAGS="-L$(brew --prefix)/lib"
           CFLAGS="-I$(brew --prefix)/include"
           make
    - name: test
      env: ${{ matrix.compiler.env }}
      run: LDFLAGS="-L$(brew --prefix)/lib"
           CFLAGS="-I$(brew --prefix)/include"
           make test
