name: Build and test

on:
  - push
  - pull_request

jobs:
  linux:
    name: ${{ matrix.container }} (${{ matrix.options}}, ${{ matrix.compiler}})
    env:
      DEBIAN_FRONTEND: noninteractive
      CC: ${{ matrix.compiler}}
      BUILDOPTS: $${{ matrix.options }}
    strategy:
      matrix:
        compiler:
          - gcc
          - clang
        container:
          - debian:stable
          - debian:testing
          - ubuntu:latest
        options:
          - assert=no errorcheck=yes
          - opt=no cairo=no errorcheck=yes
          - amalgamation=yes errorcheck=yes
    runs-on: ubuntu-latest
    container:
      image: ${{ matrix.container }}
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
      - name: Install deps
        run: |
             apt update
             apt -yq install build-essential libpango1.0-dev libcairo2-dev \
                             ncbi-blast+ ruby clang
      - name: Set up user
        run: |
             useradd -m -g users testuser
             chown -R testuser:users .
      - name: Build with ${{ matrix.options }}
        run: |
             su -c "make ${{ matrix.options }}" testuser
      - name: Run tests
        run: |
             su -c "scripts/citest.rb" testuser
  macos-latest:
    name: macOS-latest (${{ matrix.options}})
    strategy:
      matrix:
        options:
          - assert=no errorcheck=yes
          - opt=no cairo=no errorcheck=yes
          - amalgamation=yes errorcheck=yes
    runs-on: macos-latest
    env:
      BUILDOPTS: $${{ matrix.options }}
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
      - name: Install deps
        run: |
         brew install pango cairo libffi pkg-config blast
      - name: Build with ${{ matrix.options }}
        run: |
             make ${{ matrix.options }}
      - name: Run tests
        run: |
             scripts/citest.rb
  windows-cross:
    name: mingw-w64 (fpic=no cairo=no sharedlib=no errorcheck=yes, ${{ matrix.mingw-arch }})
    strategy:
      matrix:
        mingw-arch:
          - machine: i686
            buildopts: fpic=no cairo=no sharedlib=no 64bit=no errorcheck=yes
          - machine: x86_64
            buildopts: fpic=no cairo=no sharedlib=no errorcheck=yes
    env:
      DEBIAN_FRONTEND: noninteractive
      CC: ${{ matrix.mingw-arch.machine }}-w64-mingw32-gcc
      SYSTEM: Windows
      MACHINE: ${{ matrix.mingw-arch.machine }}
      AR: ${{ matrix.mingw-arch.machine }}-w64-mingw32-ar
      CFLAGS: -Wno-error=attributes -Wno-error=unused-parameter -DSQLITE_MALLOCSIZE=_msize
    runs-on: ubuntu-latest
    container: debian:buster
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
      - name: Install deps
        run: |
             apt update
             apt -yq install build-essential ncbi-blast+ ruby \
                     binutils-mingw-w64-i686 gcc-mingw-w64-i686 \
                     binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64
      - name: Build
        run: |
             make ${{ matrix.mingw-arch.buildopts }}
