.cached_testrunner:
  extends: .testrunner
  variables:
    PIP_CACHE_DIR: '${{CI_PROJECT_DIR}}/.cache/pip'
    EXT_CACHE_VENV: '${{CI_PROJECT_DIR}}/.cache/ext_cache_venv${{PYTHON_VERSION}}'
  before_script: |
    ulimit -c unlimited
    pyenv global 3.12 3.8 3.9 3.10 3.11 3.13 3.14
    export _CI_DD_AGENT_URL=http://${{HOST_IP}}:8126/
    set -e -o pipefail
    if [ ! -d $EXT_CACHE_VENV ]; then
        python$PYTHON_VERSION -m venv $EXT_CACHE_VENV
        source $EXT_CACHE_VENV/bin/activate
        pip install cmake setuptools_rust Cython
    else
        source $EXT_CACHE_VENV/bin/activate
    fi
    python scripts/ext_cache.py restore
    deactivate
  after_script: |
    set -e -o pipefail
    source $EXT_CACHE_VENV/bin/activate
    python scripts/ext_cache.py save
    deactivate
  cache:
    # Share pip between jobs of the same Python version
    - key: v5-build_base_venvs-${{PYTHON_VERSION}}-cache-{current_month}
      paths:
        - .cache
    - key: v5-build_base_venvs-${{PYTHON_VERSION}}-ext-{current_month}
      paths:
        - .ext_cache
    - key: v5-build_base_venvs-${{PYTHON_VERSION}}-download-cache-{current_month}
      paths:
        - .download_cache
