Files
nas-tools/.gitea/workflows/test.yml
T
Gan, Jimmy 7ad4095ad6
Run Tests / Backend Tests (push) Has started running
Run Tests / Frontend Tests (push) Has been cancelled
Run Tests / Test Summary (push) Has been cancelled
fix: add exit code validation to test workflow to properly fail on test failures
2026-03-31 19:03:53 +08:00

177 lines
5.6 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: Check test results
if: always()
run: |
if [ "${UNIT_TEST_EXIT_CODE:-1}" != "0" ] || [ "${INTEGRATION_TEST_EXIT_CODE:-1}" != "0" ]; then
echo "❌ Backend tests failed"
exit 1
fi
echo "✅ All backend tests passed"
- 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: Check test results
if: always()
run: |
if [ "${FRONTEND_TEST_EXIT_CODE:-1}" != "0" ]; then
echo "❌ Frontend tests failed"
exit 1
fi
echo "✅ All frontend tests passed"
- 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: Check job results
run: |
echo "Backend tests: ${{ needs.backend-tests.result }}"
echo "Frontend tests: ${{ needs.frontend-tests.result }}"
if [ "${{ needs.backend-tests.result }}" != "success" ] || [ "${{ needs.frontend-tests.result }}" != "success" ]; then
echo "❌ Some tests failed"
exit 1
fi
echo "✅ All tests passed"
- 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 passed" >> $GITHUB_STEP_SUMMARY
echo "✅ Frontend tests passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports uploaded as artifacts." >> $GITHUB_STEP_SUMMARY