name: Test Colab Simulated Environment (Master Wheel)

# This workflow simulates a Google Colab environment (Python 3.12.x)
# and installs the CURRENT master branch by building a wheel locally
# (testing the distributable artifact rather than the published PyPI release).

on:
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: test-colab-simulated-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test-colab-simulated:
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - name: Checkout repository (master)
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Python 3.12
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Upgrade pip & install build backend
        run: |
          python -m pip install --upgrade pip
          pip install build

      - name: Install Colab-like core package versions
        run: |
          pip install numpy==1.26.4 pandas==2.2.2 scikit-learn==1.5.0 onnx==1.16.0 onnxruntime==1.18.0 tensorflow==2.19.0 torch==2.8.0 seaborn==0.13.2 matplotlib==3.9.0 requests==2.32.4

      - name: Print core package versions to confirm environment
        run: |
          echo "=== Python Version ==="
          python --version
          echo ""
          echo "=== Package Versions ==="
          python -c "import numpy; print('numpy:', numpy.__version__)"
          python -c "import pandas; print('pandas:', pandas.__version__)"
          python -c "import sklearn; print('scikit-learn:', sklearn.__version__)"
          python -c "import onnx; print('onnx:', onnx.__version__)"
          python -c "import onnxruntime; print('onnxruntime:', onnxruntime.__version__)"
          python -c "import tensorflow; print('tensorflow:', tensorflow.__version__)"
          python -c "import torch; print('torch:', torch.__version__)"
          python -c "import seaborn; print('seaborn:', seaborn.__version__)"
          python -c "import matplotlib; print('matplotlib:', matplotlib.__version__)"
          python -c "import requests; print('requests:', requests.__version__)"
          echo ""

      - name: Build wheel artifact for aimodelshare (master)
        run: |
          python -m build --wheel
          echo "=== Built artifacts ==="
          ls -1 dist

      - name: Install built wheel
        run: |
          WHEEL_FILE=$(ls dist/*.whl | head -n 1)
          echo "Installing wheel: $WHEEL_FILE"
          pip install "$WHEEL_FILE"

      - name: Test aimodelshare import & version
        run: |
          python -c "import importlib.metadata as md, aimodelshare; print('aimodelshare imported successfully; version:', md.version('aimodelshare'))"

      - name: Upload wheel artifact
        uses: actions/upload-artifact@v4
        with:
          name: aimodelshare-wheel
          path: dist/*.whl
          if-no-files-found: error
          retention-days: 7

      - name: Summary
        if: always()
        run: |
          echo "=== Test Summary ==="
          python -c "import importlib.metadata as md; print('Installed aimodelshare version:', md.version('aimodelshare'))"
          echo "Python version: 3.12"
          echo "Job status: ${{ job.status }}"
