Files
nas-tools/.gitea/workflows/test.yml
T
Gan, Jimmy 084148ed32
Run Tests / Backend Tests (push) Failing after 1m39s
Run Tests / Frontend Tests (push) Failing after 43s
Run Tests / Test Summary (push) Failing after 41s
fix: add SECRET_KEY environment variable to test workflow
2026-03-31 15:30:55 +08:00

148 lines
4.7 KiB
YAML

name: Run Tests
on:
push:
branches: [main, dev]
pull_request:
branches: [main]
jobs:
backend-tests:
name: Backend Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: dashboard/backend
env:
SECRET_KEY: test-secret-key-for-ci-environment-32chars-minimum
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install pytest-timeout
- name: Run unit tests
run: |
pytest tests/unit/ -v --timeout=30 -x 2>&1 | tee unit-test-output.txt
echo "UNIT_TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV
continue-on-error: true
- name: Run integration tests
run: |
pytest tests/integration/ -v --timeout=30 -x 2>&1 | tee integration-test-output.txt
echo "INTEGRATION_TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV
continue-on-error: true
- name: Display test results
if: always()
run: |
echo "## Backend Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Unit Tests (Exit Code: ${UNIT_TEST_EXIT_CODE:-N/A})" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -50 unit-test-output.txt >> $GITHUB_STEP_SUMMARY 2>/dev/null || echo "No unit test output" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Integration Tests (Exit Code: ${INTEGRATION_TEST_EXIT_CODE:-N/A})" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -50 integration-test-output.txt >> $GITHUB_STEP_SUMMARY 2>/dev/null || echo "No integration test output" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Upload backend coverage report
if: always()
uses: actions/upload-artifact@v3
with:
name: backend-coverage
path: dashboard/backend/htmlcov/
- name: Upload backend coverage XML
if: always()
uses: actions/upload-artifact@v3
with:
name: backend-coverage-xml
path: dashboard/backend/coverage.xml
frontend-tests:
name: Frontend Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: dashboard/frontend
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: dashboard/frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
run: |
npm run test:coverage -- --reporter=verbose --run 2>&1 | tee test-output.txt
echo "FRONTEND_TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV
continue-on-error: true
- name: Display test results
if: always()
run: |
echo "## Frontend Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Test Output (Exit Code: ${FRONTEND_TEST_EXIT_CODE:-N/A})" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -50 test-output.txt >> $GITHUB_STEP_SUMMARY 2>/dev/null || echo "No test output" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Upload frontend coverage report
if: always()
uses: actions/upload-artifact@v3
with:
name: frontend-coverage
path: dashboard/frontend/coverage/
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [backend-tests, frontend-tests]
if: always()
steps:
- name: Download backend coverage
uses: actions/download-artifact@v3
with:
name: backend-coverage-xml
path: ./backend-coverage
continue-on-error: true
- name: Download frontend coverage
uses: actions/download-artifact@v3
with:
name: frontend-coverage
path: ./frontend-coverage
continue-on-error: true
- name: Test Summary
run: |
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Backend tests completed" >> $GITHUB_STEP_SUMMARY
echo "✅ Frontend tests completed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports uploaded as artifacts." >> $GITHUB_STEP_SUMMARY