name: CI

on:
  push:
  pull_request:

jobs:
  build-and-test:

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

    strategy:
      matrix:
        toolchain:
          - linux-gcc
          # - macos-clang
          # - windows-msvc

        configuration:
          - Release

        include:
          - toolchain: linux-gcc
            os: ubuntu-latest
            compiler: gcc

          #- toolchain: macos-clang
          #  os: macos-latest
          #  compiler: clang

          #- toolchain: windows-msvc
          #  os: windows-latest
          #  compiler: msvc

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

      - name: Install conan
        shell: bash
        run: |
            python3 -m pip install --upgrade pip setuptools
            python3 -m pip install conan

      - name: Setup conan
        shell: bash
        run: |
          conan profile new default --detect
          conan profile update settings.compiler.libcxx=libstdc++11 default

      - name: Install conan libraries
        shell: bash
        run: |
            mkdir -p build
            cd build
            conan install .. --build

      - name: Configure (${{ matrix.configuration }})
        run: cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=${{ matrix.configuration }}

      - name: Build with ${{ matrix.compiler }}
        run: cmake --build build

      - name: Run tests ${{ matrix.compiler }}
        shell: bash
        run: cd build && ctest --verbose -C ${{ matrix.configuration }}

      - uses: actions/upload-artifact@v2
        if: ${{ runner.os == 'macOS' }}
        with:
          name: shp-cli-macos
          path: build/app/shp-cli

      - uses: actions/upload-artifact@v2
        if: ${{ runner.os == 'Linux' }}
        with:
          name: shp-cli-linux
          path: build/app/shp-cli

      - uses: actions/upload-artifact@v2
        if: ${{ runner.os == 'Windows' }}
        with:
          name: shp-cli-windows
          path: build/app/shp-cli.exe
