name: Library builds (shared)

on:
  push:
    branches: [ 'master', 'main', 'develop', 'actions_shared' ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ 'master', 'main', 'develop' ]

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

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      # fail-fast: Default is true, switch to false to allow one platform to fail and still run others
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest, macOS-latest]

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

    - uses: actions/setup-python@v4
      with:
        python-version: '3.x'

    - name: Install Python dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install requests packaging

    - 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 ..

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

    # - name: Tar.gz the shared library to maintain case sensitivy and file permissions
    #   working-directory: ./install_root/shared_library/
    #   shell: bash
    #   run: |
    #     set -x
    #     tar -cvzf CoolProp-${{ env.COOLPROP_VERSION }}-shared-${{ matrix.os }}.tar.gz ./*

    - name: Archive artifacts
      uses: actions/upload-artifact@v3
      with:
          name: shared_library
          path: install_root/shared_library

    # - name: Upload TGZ or ZIP to release
    #   if: contains(github.ref, 'refs/tags')
    #   uses: svenstaro/upload-release-action@v2
    #   with:
    #     repo_token: ${{ secrets.GITHUB_TOKEN }}
    #     file: install_root/shared_library/CoolProp-${{ env.COOLPROP_VERSION }}-shared-${{ matrix.os }}.tar.gz
    #     tag: ${{ github.ref }}
    #     overwrite: true
    #     file_glob: false
