#!/bin/bash
# WF 2023-07-19
# WF 2025-11-12 - fixes missing qlever script
# WF 2026-02-28
# Check if running in GitHub Actions and apt-get is available
if [[ -n "$GITHUB_ACTIONS" && -x "$(command -v apt-get)" ]]; then
    echo "Running in GitHub Actions with apt-get available. Installing dependencies..."
    sudo apt-get update
    # install dependencies
    sudo apt-get install rcs python3-pip
    # install qlever
    pip install qlever
fi
# Check if pipx is available, install if not
if ! command -v pipx &> /dev/null; then
    echo "pipx not found, installing..."
    python3 -m pip install --user pipx
    python3 -m pipx ensurepath
fi

# Install qlever if not already installed
if ! command -v qlever &> /dev/null; then
    echo "qlever not found, installing via pipx..."
    pipx install qlever || echo "Warning: qlever installation failed (optional)"

    # **FIX: Immediately update PATH for current session**
    export PATH="$HOME/.local/bin:$PATH"

    # Verify qlever is now available
    if command -v qlever &> /dev/null; then
        echo "✅ qlever successfully installed and available"
    else
        echo "❌ Warning: qlever still not found in PATH after installation"
    fi
fi


# Build free Stardog Docker image if in CI
if [[ -n "$GHACTIONS" ]]; then
    echo "Building free Stardog Docker image for CI..."
    scripts/build-stardog-free
fi

# simple install via pyproject.toml
pip install .
