50e97c4a70
Deploy Claude Dev (Dev) / deploy-claude-dev-dev (push) Successful in 1m45s
Deploy Dashboard (Dev) / Frontend Tests (push) Has been cancelled
Deploy Dashboard (Dev) / Deploy to Dev (push) Has been cancelled
Deploy Dashboard (Dev) / Backend Tests (push) Has been cancelled
CI runner in China can't reach GitHub to download the checkout action. Clone directly from internal Gitea container (http://gitea:3000) instead. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
200 lines
6.9 KiB
YAML
200 lines
6.9 KiB
YAML
name: Run Tests
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
paths:
|
|
- 'dashboard/**'
|
|
- '.gitea/workflows/test.yml'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
gitleaks:
|
|
name: Secret Detection
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
run: |
|
|
if [ ! -d .git ]; then
|
|
git clone "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
|
fi
|
|
continue-on-error: true
|
|
|
|
- name: Run gitleaks
|
|
run: |
|
|
# Try to run gitleaks; GitHub may be unreachable from the runner
|
|
if curl -fsSL --connect-timeout 10 "https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz" -o gitleaks.tar.gz 2>/dev/null; then
|
|
tar xzf gitleaks.tar.gz
|
|
./gitleaks detect --source . --no-git --verbose 2>&1 || echo "gitleaks found issues (non-blocking)"
|
|
else
|
|
echo "⚠️ Skipping gitleaks — GitHub unreachable from CI runner"
|
|
fi
|
|
continue-on-error: true
|
|
|
|
backend-tests:
|
|
name: Backend Tests
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
SECRET_KEY: test-secret-key-for-ci-environment-32chars-minimum
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
run: |
|
|
if [ ! -d .git ]; then
|
|
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
|
fi
|
|
|
|
- name: Setup Python
|
|
run: |
|
|
python3 --version
|
|
python3 -c "import sys; assert sys.version_info[:2] == (3, 12), f'Expected Python 3.12, got {sys.version}'; print('Python 3.12 confirmed')"
|
|
pip3 --version
|
|
|
|
- name: Cache Python dependencies
|
|
id: cache-python
|
|
run: |
|
|
CACHE_KEY="python-$(cat dashboard/backend/requirements.txt dashboard/backend/requirements-dev.txt | md5sum | cut -d' ' -f1)"
|
|
CACHE_DIR="/tmp/pytest-cache/$CACHE_KEY"
|
|
PIP_CACHE_DIR="/tmp/pip-cache"
|
|
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
|
echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV
|
|
echo "PIP_CACHE_DIR=$PIP_CACHE_DIR" >> $GITHUB_ENV
|
|
mkdir -p "$PIP_CACHE_DIR"
|
|
if [ -d "$CACHE_DIR" ]; then
|
|
echo "Cache hit for $CACHE_KEY"
|
|
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Cache miss for $CACHE_KEY"
|
|
echo "cache-hit=false" >> $GITHUB_OUTPUT
|
|
mkdir -p "$CACHE_DIR"
|
|
fi
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
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
|
|
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 -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/ || echo "Warning: cache save failed"
|
|
fi
|
|
|
|
- name: Run tests with coverage
|
|
run: |
|
|
cd dashboard/backend
|
|
. venv/bin/activate
|
|
pytest tests/ -v --timeout=60 \
|
|
--cov=. --cov-report=xml --cov-report=term \
|
|
--junit-xml=test-results.xml \
|
|
--cov-fail-under=49
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Backend tests failed!"
|
|
exit 1
|
|
fi
|
|
echo "✅ Backend tests passed"
|
|
|
|
- name: Upload coverage report
|
|
if: always()
|
|
run: |
|
|
cd dashboard/backend
|
|
if [ -f coverage.xml ]; then
|
|
echo "Coverage report generated"
|
|
cat coverage.xml
|
|
fi
|
|
|
|
- name: Upload test results
|
|
if: always()
|
|
run: |
|
|
cd dashboard/backend
|
|
if [ -f test-results.xml ]; then
|
|
echo "Test results generated"
|
|
cat test-results.xml | head -50
|
|
fi
|
|
|
|
frontend-tests:
|
|
name: Frontend Tests
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
run: |
|
|
if [ ! -d .git ]; then
|
|
git clone --depth=1 "http://gitea:3000/${GITHUB_REPOSITORY}.git" .
|
|
fi
|
|
|
|
- name: Setup Node.js
|
|
run: |
|
|
node --version
|
|
echo "Node $(node --version) detected"
|
|
npm --version
|
|
|
|
- name: Cache Node dependencies
|
|
id: cache-node
|
|
run: |
|
|
CACHE_KEY="node-$(md5sum dashboard/frontend/package-lock.json | cut -d' ' -f1)"
|
|
CACHE_DIR="/tmp/npm-cache/$CACHE_KEY"
|
|
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
|
echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV
|
|
if [ -d "$CACHE_DIR" ]; then
|
|
echo "Cache hit for $CACHE_KEY"
|
|
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Cache miss for $CACHE_KEY"
|
|
echo "cache-hit=false" >> $GITHUB_OUTPUT
|
|
mkdir -p "$CACHE_DIR"
|
|
fi
|
|
|
|
- name: Install dependencies
|
|
env:
|
|
NODE_OPTIONS: "--max-old-space-size=2048"
|
|
run: |
|
|
cd dashboard/frontend
|
|
# Use npmmirror for China accessibility
|
|
npm config set registry https://registry.npmmirror.com || true
|
|
if [ "${{ steps.cache-node.outputs.cache-hit }}" = "true" ]; then
|
|
echo "Restoring from cache $CACHE_KEY..."
|
|
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/ || echo "Warning: cache save failed"
|
|
fi
|
|
|
|
- name: Run tests
|
|
env:
|
|
NODE_OPTIONS: "--max-old-space-size=2048"
|
|
run: |
|
|
cd dashboard/frontend
|
|
npm run test:coverage -- --reporter=verbose --run --pool=forks --poolOptions.forks.maxForks=2
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "❌ Frontend tests failed!"
|
|
exit 1
|
|
fi
|
|
echo "✅ Frontend tests passed"
|