fix: add pip timeout, retries, and mirror fallback to all CI workflows
- Wrap pip install in timeout 300 to prevent hanging on slow mirrors - Add --retries 3 --timeout 30 to pip for better resilience - Fallback chain: default index → Tsinghua mirror → default index - Applied to test.yml, deploy.yml, and deploy-dev.yml Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -61,17 +61,25 @@ jobs:
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout || pip install pytest-timeout
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
@@ -61,17 +61,25 @@ jobs:
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
+21
-13
@@ -74,27 +74,35 @@ jobs:
|
||||
cd dashboard/backend
|
||||
if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then
|
||||
echo "Restoring venv from cache $CACHE_KEY..."
|
||||
if cp -a $CACHE_DIR/venv . && [ -f venv/bin/activate ]; then
|
||||
if cp -a $CACHE_DIR/venv . && [ -f venv/bin/activate ]; then
|
||||
echo "Cache restored successfully"
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf venv
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt || pip install -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt || pip install -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt || \
|
||||
pip install -r requirements.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --retries 3 --timeout 30 -r requirements-dev.txt || \
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR --index-url https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements-dev.txt || \
|
||||
pip install -r requirements-dev.txt
|
||||
timeout 300 pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov || pip install pytest-timeout pytest-cov
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user