name: Testing Catch2

on:
  push:
    branches: [ 'master', 'main', 'develop', 'actions_tests' ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ 'master', 'main', 'develop' ]
  #schedule:
  #  - cron: '15 8 * * 3' # Run weekly

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
      with:
        submodules: recursive

    - name: Build REFPROP
      shell: bash
      run: |
        set -x
        cd .github/workflows
        chmod +x buildREFPROP.sh
        ./buildREFPROP.sh
        tree `pwd`
        echo COOLPROP_REFPROP_ROOT=`pwd`/gpgREFPROP/REFPROP-cmake/bld >> $GITHUB_ENV
      env:
          REFPROP_GPG_PASSPHRASE: ${{ secrets.REFPROP_GPG_PASSPHRASE }}
    
    - name: Extract CoolProp version from CMakeLists.txt
      shell: bash
      run: |
        set -x
        COOLPROP_VERSION=$(python dev/extract_version.py --cmake-only)
        echo COOLPROP_VERSION=$COOLPROP_VERSION >> $GITHUB_ENV
        # Create the build directory too
        mkdir build

    - name: Configure CMake
      working-directory: ./build
      shell: bash
      run: cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCOOLPROP_SHARED_LIBRARY:BOOL=ON -DCOOLPROP_CATCH_MODULE:BOOL=ON ..

    - name: Build
      working-directory: ./build
      shell: bash
      run: |
        set -x
        cmake --build . --target install -j $(nproc) --config $BUILD_TYPE

    # - name: Test
    #   working-directory: ./build
    #   shell: bash
    #   # Execute tests defined by the CMake configuration.
    #   # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
    #   run: |
    #     ctest -j 1

    # - name: Rerun failed Tests
    #   if: failure()
    #   working-directory: ./build
    #   shell: bash
    #   # Execute tests defined by the CMake configuration.
    #   # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
    #   run: |
    #     ctest -j 1 --rerun-failed --output-on-failure

    # TODO: pick one style, for now I'm doing this so I can report zero new failures compared to catch1
    - name: Rerun failed Tests in CatchTestRunner directly
      # if: failure()
      working-directory: ./build
      shell: bash
      # Execute tests defined by the CMake configuration.
      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
      run: |
        ./CatchTestRunner
