Skip to content

feat: enforce TDD with pre-commit hooks for tests and coverage #6

feat: enforce TDD with pre-commit hooks for tests and coverage

feat: enforce TDD with pre-commit hooks for tests and coverage #6

Workflow file for this run

name: Tests and Quality Checks
on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop
workflow_dispatch:
jobs:
frontend-tests:
name: Frontend Tests
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Run linting
working-directory: frontend
run: npm run lint
- name: Run type checking
working-directory: frontend
run: npm run typecheck
- name: Run unit tests
working-directory: frontend
run: npm test -- --coverage --passWithNoTests
- name: Check coverage threshold
working-directory: frontend
run: npm test -- --coverage --coverageThreshold='{"global":{"lines":85,"statements":85,"branches":75,"functions":85}}'
continue-on-error: true # Don't fail CI until we reach 85%
- name: Upload coverage reports
uses: codecov/codecov-action@v4
if: always()
with:
files: ./frontend/coverage/lcov.info
flags: frontend
fail_ci_if_error: false
backend-tests:
name: Backend Tests
runs-on: ubuntu-latest
timeout-minutes: 15
services:
mongodb:
image: mongo:7
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.adminCommand({ping: 1})'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
working-directory: backend
run: |
uv sync
- name: Run tests with coverage
working-directory: backend
env:
MONGODB_URL: mongodb://localhost:27017/autoauthor_test
run: |
uv run pytest tests/ --cov=app --cov-report=xml --cov-report=term
- name: Check coverage threshold
working-directory: backend
run: |
uv run pytest --cov=app tests/ --cov-fail-under=85
continue-on-error: true # Don't fail CI until we reach 85%
- name: Upload coverage reports
uses: codecov/codecov-action@v4
if: always()
with:
files: ./backend/coverage.xml
flags: backend
fail_ci_if_error: false
e2e-tests:
name: E2E Tests (Playwright)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Install Playwright browsers
working-directory: frontend
run: npx playwright install --with-deps chromium
- name: Run E2E tests
working-directory: frontend
env:
BYPASS_AUTH: true # Use auth bypass for CI testing
run: npx playwright test
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 7
quality-summary:
name: Quality Summary
runs-on: ubuntu-latest
needs: [frontend-tests, backend-tests, e2e-tests]
if: always()
steps:
- name: Check test results
run: |
echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Frontend Tests: ${{ needs.frontend-tests.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Backend Tests: ${{ needs.backend-tests.result }}" >> $GITHUB_STEP_SUMMARY
echo "- E2E Tests: ${{ needs.e2e-tests.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.frontend-tests.result }}" == "failure" ] || \
[ "${{ needs.backend-tests.result }}" == "failure" ] || \
[ "${{ needs.e2e-tests.result }}" == "failure" ]; then
echo "❌ **Quality checks failed**" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "✅ **All quality checks passed**" >> $GITHUB_STEP_SUMMARY
fi