name: Tests
on:
  push:
    branches:
      - master
      - v*
  pull_request:
    branches:
      - master

jobs:
  pre-commit:
    name: Formatting
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v1
    - name: set PY
      run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)"
    - uses: actions/cache@v1
      with:
        path: ~/.cache/pre-commit
        key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
    - uses: pre-commit/action@v1.0.0

  cuda-build:
    name: CUDA build only
    runs-on: ubuntu-latest
    container: nvidia/cuda:10.2-devel-ubuntu18.04
    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true
    - name: Add wget
      run: apt-get update && apt-get install -y wget
    - name: Install Modern CMake
      run: wget -qO- "https://cmake.org/files/v3.16/cmake-3.16.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
    - name: Configure
      run: cmake -S . -B build -DCLI11_CUDA_TESTS=ON
    - name: Build
      run: cmake --build build -j2

  cmake-config:
    name: CMake config check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true
    - name: CMake 3.4
      uses: ./.github/actions/cmake_config
      with:
        version: 3.4.3
    - name: CMake 3.5
      uses: ./.github/actions/cmake_config
      with:
        version: 3.5.2
      if: success() || failure()
    - name: CMake 3.6
      uses: ./.github/actions/cmake_config
      with:
        version: 3.6.3
      if: success() || failure()
    - name: CMake 3.7
      uses: ./.github/actions/cmake_config
      with:
        version: 3.7.2
      if: success() || failure()
    - name: CMake 3.8
      uses: ./.github/actions/cmake_config
      with:
        version: 3.8.2
      if: success() || failure()
    - name: CMake 3.9
      uses: ./.github/actions/cmake_config
      with:
        version: 3.9.6
      if: success() || failure()
    - name: CMake 3.10
      uses: ./.github/actions/cmake_config
      with:
        version: 3.10.3
      if: success() || failure()
    - name: CMake 3.11 (full)
      uses: ./.github/actions/cmake_config
      with:
        version: 3.11.4
        options: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
      if: success() || failure()
    - name: CMake 3.12
      uses: ./.github/actions/cmake_config
      with:
        version: 3.12.4
      if: success() || failure()
    - name: CMake 3.13
      uses: ./.github/actions/cmake_config
      with:
        version: 3.13.5
      if: success() || failure()
    - name: CMake 3.14
      uses: ./.github/actions/cmake_config
      with:
        version: 3.14.7
      if: success() || failure()
    - name: CMake 3.15
      uses: ./.github/actions/cmake_config
      with:
        version: 3.15.6
      if: success() || failure()
    - name: CMake 3.16 (full)
      uses: ./.github/actions/cmake_config
      with:
        version: 3.16.2
        options: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
      if: success() || failure()
