name: CI
on:
  - push
  - pull_request
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - ubuntu-20.04
          - macos-10.15
          - windows-2019
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - name: Dependencies (shared)
        run: pip install meson ninja
      - name: Dependencies (ubuntu)
        if: contains(matrix.os, 'ubuntu')
        run: sudo apt update && sudo apt install -y gifsicle valgrind
      - name: Dependencies (macos)
        if: contains(matrix.os, 'macos')
        run: brew install gifsicle
      - name: Dependencies (windows)
        if: contains(matrix.os, 'windows')
        run: choco install gifsicle
      - name: Build
        run: meson setup build && meson compile -C build
      - name: Test
        run: meson test -C build
      - name: Verify GIF test output (gifsicle)
        run: for f in build/*.gif; do gifsicle --no-ignore-errors --info $f || exit 1; done
        shell: bash
      - name: Valgrind
        if: contains(matrix.os, 'ubuntu')
        run: basename -s .c tests/*.c | xargs meson test -C build --wrap "valgrind --memcheck:leak-check=full --memcheck:show-leak-kinds=definite --memcheck:error-exitcode=1"
        shell: bash
      - name: Valgrind output
        if: contains(matrix.os, 'ubuntu')
        run: cat build/meson-logs/testlog-valgrind.txt
