diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index a5f4930..2717345 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -65,11 +65,33 @@ jobs: - name: Set up venv and install deps run: | set -euo pipefail - python3 -m venv .venv + # Prefer persistent cache if runner provides /cache + USE_CACHE=0 + if [ -d /cache ] && [ -w /cache ]; then + export PIP_CACHE_DIR=/cache/pip + mkdir -p "$PIP_CACHE_DIR" + REQ_HASH=$(sha256sum requirements.txt | awk '{print $1}') + PYVER=$(python3 -c 'import sys;print(".".join(map(str, sys.version_info[:2])))') + CACHE_VENV="/cache/venv-${REQ_HASH}-py${PYVER}" + if [ -d "$CACHE_VENV" ]; then + echo "Using cached virtualenv: $CACHE_VENV" + ln -s "$CACHE_VENV" .venv + USE_CACHE=1 + else + echo "Creating cached virtualenv: $CACHE_VENV" + python3 -m venv "$CACHE_VENV" + ln -s "$CACHE_VENV" .venv + fi + fi + . .venv/bin/activate python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest + if [ "$USE_CACHE" = "1" ]; then + # Ensure required packages are present; pip will use cache + pip install -r requirements.txt pytest || pip install -r requirements.txt pytest + else + pip install -r requirements.txt pytest + fi - name: Format check (black) run: | @@ -84,7 +106,7 @@ jobs: - name: Run tests (pytest) run: | . .venv/bin/activate - pytest -q + pytest -q --maxfail=1 - name: Build sample reports (no artifact upload) run: |