name: Conda

on:
    push:
        paths-ignore:
            - 'doc/**'
    pull_request:
        paths-ignore:
            - 'doc/**'

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Conda ${{ matrix.platform }}
    defaults:
      run:
        shell: bash -l {0}
    runs-on: ${{ matrix.platform }}
    if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
    strategy:
      fail-fast: true
      matrix:
        platform: ['windows-latest','macos-latest','ubuntu-latest']

    env:
      PDAL_PLATFORM: ${{ matrix.platform }}
    steps:
    - uses: actions/checkout@v4

    - name: Support longpaths
      run: git config --system core.longpaths true
      if: matrix.platform == 'windows-latest'

    - name: Cache Conda Environment
      uses: actions/cache@v4
      with:
        path: ~/conda_pkgs_dir
        key: ${{ runner.os }}-${{ steps.get-date.outputs.today }}-conda-${{ env.CACHE_NUMBER }}

    - uses: conda-incubator/setup-miniconda@v3
      with:
        miniforge-variant: Miniforge3
        miniforge-version: latest
        use-mamba: true
        auto-update-conda: true
        use-only-tar-bz2: false


    - name: Setup
      run: |
          source ./scripts/ci/conda/setup.sh

    - name: Build
      run: |
          source ../scripts/ci/conda/compile.sh
      working-directory: ./libpdal-feedstock

    - name: Debug
      run: |
          conda activate test
          conda info
          conda list

    - uses: ilammy/msvc-dev-cmd@v1
      if: matrix.platform == 'windows-latest'

    - name: Test
      run: |
          source ./scripts/ci/conda/examples.sh

    - uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.platform }}-conda-package
        path: ./libpdal-feedstock/packages/

    - name: Deploy to pdal-master Conda channel
      if: github.ref == 'refs/heads/master'
      env:
        ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
      run: |
          source ../scripts/ci/conda/upload.sh || true
      working-directory: ./libpdal-feedstock
