145 lines
4.7 KiB
YAML
145 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
|
|
|
|
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
|
|
|
|
- name: Run unit tests
|
|
run: |
|
|
pytest tests/unit/ -v --cov=. --cov-report=term --cov-report=html --cov-report=xml 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 --cov=. --cov-append --cov-report=term --cov-report=html --cov-report=xml 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 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
|