name: Fetch neuriplo versions.env
description: Downloads versions.env from the neuriplo repo selected from the current release line

runs:
  using: composite
  steps:
    - name: Fetch neuriplo versions.env
      shell: bash
      run: |
        # Precedence matches cmake/versions.cmake:
        #   1. NEURIPLO_VERSION pinned in versions.env (release tags use this).
        #   2. master if VERSION is a clean semver, else develop.
        neuriplo_ref=""
        if [ -f versions.env ]; then
          neuriplo_ref="$(awk -F= '/^NEURIPLO_VERSION=/{gsub(/[ \t\r"]/,"",$2); print $2; exit}' versions.env)"
        fi
        if [ -z "${neuriplo_ref}" ]; then
          neuriplo_ref="develop"
          if grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' VERSION; then
            neuriplo_ref="master"
          fi
        fi

        echo "Using neuriplo ref: ${neuriplo_ref}"
        mkdir -p build/_deps/neuriplo-src
        curl -fsSL "https://raw.githubusercontent.com/olibartfast/neuriplo/${neuriplo_ref}/versions.env" \
          -o build/_deps/neuriplo-src/versions.env
