name: "Tests"

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  petanque:

    strategy:
      matrix:
        build_type: ["Debug", "Release"]
        config:
          - os: ubuntu-latest
            shared_libs: ON
            cc: gcc
            cxx: g++
          - os: macos-latest
            shared_libs: ON
            cc: clang
            cxx: clang++
          - os: windows-latest
            shared_libs: OFF
            cc: cl.exe
            cxx: cl.exe


    runs-on: ${{ matrix.config.os }}

    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies (Ubuntu)
      if: runner.os == 'Linux'
      run: |
        sudo apt install ninja-build
    - name: Install dependencies (OSX)
      if: runner.os == 'macOS'
      run: |
        brew install ninja
    - name: Install dependencies (Windows)
      if: runner.os == 'Windows'
      run: |
        choco install ninja
    - uses: ilammy/msvc-dev-cmd@v1
      if: runner.os == 'Windows'
    - name: CMake
      working-directory: petanque
      run: |
        mkdir build
        cd build && cmake -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_SHARED_LIBS=${{ matrix.config.shared_libs }} -G Ninja ..
    - name: Build
      working-directory: petanque/build
      run: ninja
    - name: Tests
      working-directory: petanque/build
      run: ninja test

  python:

    strategy:
      matrix:
        python-version: [3.5, 3.6, 3.7, 3.8]
        os: [ubuntu-latest, macos-latest, windows-latest]

    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2
    - uses: ilammy/msvc-dev-cmd@v1
      if: runner.os == 'Windows'
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install pytanque
      working-directory: petanque
      run: |
        python ./setup.py install
    - name: Install arybo
      run: |
        python ./setup.py install
    - name: Tests
      run: |
        python -m unittest discover tests/arybo -p '*.py' 
