fix: re-enable test workflow with reliable triggers and production gate
- Re-enable test.yml to run on PRs to main (not every push) - Add cache validation with fallback to fresh install for both Python/Node - Add PyPI fallback when mirror fails - Increase pytest timeout from 30s to 60s - Add backend+frontend test gate to production deploy workflow Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+29
-18
@@ -1,17 +1,12 @@
|
||||
name: Run Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'dashboard/**'
|
||||
- '.gitea/workflows/test.yml'
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# branches: [main]
|
||||
# paths:
|
||||
# - 'dashboard/**'
|
||||
# - '.gitea/workflows/test.yml'
|
||||
# pull_request:
|
||||
# branches: [main]
|
||||
# paths:
|
||||
# - 'dashboard/**'
|
||||
# - '.gitea/workflows/test.yml'
|
||||
|
||||
jobs:
|
||||
backend-tests:
|
||||
@@ -55,23 +50,33 @@ jobs:
|
||||
cd dashboard/backend
|
||||
if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then
|
||||
echo "Restoring venv from cache $CACHE_KEY..."
|
||||
cp -a $CACHE_DIR/venv .
|
||||
if cp -a $CACHE_DIR/venv . && [ -f venv/bin/activate ]; then
|
||||
echo "Cache restored successfully"
|
||||
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
|
||||
echo "Installing fresh dependencies..."
|
||||
python3 -m venv venv
|
||||
. venv/bin/activate
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR -r requirements-dev.txt
|
||||
pip install --cache-dir=$PIP_CACHE_DIR pytest-timeout pytest-cov
|
||||
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
|
||||
echo "Saving venv to cache $CACHE_KEY..."
|
||||
cp -a venv $CACHE_DIR/
|
||||
cp -a venv $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: |
|
||||
cd dashboard/backend
|
||||
. venv/bin/activate
|
||||
pytest tests/ -v --timeout=30 \
|
||||
pytest tests/ -v --timeout=60 \
|
||||
--cov=. --cov-report=xml --cov-report=term \
|
||||
--junit-xml=test-results.xml \
|
||||
--cov-fail-under=49
|
||||
@@ -138,12 +143,18 @@ jobs:
|
||||
cd dashboard/frontend
|
||||
if [ "${{ steps.cache-node.outputs.cache-hit }}" = "true" ]; then
|
||||
echo "Restoring from cache $CACHE_KEY..."
|
||||
cp -a $CACHE_DIR/node_modules .
|
||||
if cp -a $CACHE_DIR/node_modules . && [ -d node_modules ]; then
|
||||
echo "Cache restored successfully"
|
||||
else
|
||||
echo "Cache corrupted, installing fresh..."
|
||||
rm -rf node_modules
|
||||
npm ci
|
||||
fi
|
||||
else
|
||||
echo "Installing fresh dependencies..."
|
||||
npm ci
|
||||
echo "Saving to cache $CACHE_KEY..."
|
||||
cp -a node_modules $CACHE_DIR/
|
||||
cp -a node_modules $CACHE_DIR/ || echo "Warning: cache save failed"
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
|
||||
Reference in New Issue
Block a user