Refactoring and testing #12
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| jobs: | |
| backend-lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| working-directory: backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run linting | |
| working-directory: backend | |
| run: | | |
| pip install ruff | |
| ruff check . --output-format=concise | |
| simulator-lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| working-directory: simulator | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run linting | |
| working-directory: simulator | |
| run: | | |
| pip install ruff | |
| ruff check . --output-format=concise | |
| frontend-lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: web/package-lock.json | |
| - name: Install dependencies | |
| working-directory: web | |
| run: npm ci | |
| - name: Run linter | |
| working-directory: web | |
| run: npm run lint | |
| backend-tests: | |
| needs: [backend-lint] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: test | |
| POSTGRES_PASSWORD: test | |
| POSTGRES_DB: test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:7-alpine | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| working-directory: backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run unit tests | |
| working-directory: backend | |
| run: | | |
| pytest tests/unit -v --cov=api --cov=database --cov-report=xml --cov-report=term | |
| - name: Run integration tests | |
| working-directory: backend | |
| run: | | |
| pytest tests/integration -v | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./backend/coverage.xml | |
| flags: backend | |
| name: backend-coverage | |
| frontend-tests: | |
| needs: [frontend-lint] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: web/package-lock.json | |
| - name: Install dependencies | |
| working-directory: web | |
| run: npm ci | |
| - name: Type check | |
| working-directory: web | |
| run: npx tsc --noEmit | |
| e2e-tests: | |
| needs: [backend-tests, frontend-tests] | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: test | |
| POSTGRES_PASSWORD: test | |
| POSTGRES_DB: test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:7-alpine | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: web/package-lock.json | |
| - name: Install backend dependencies | |
| working-directory: backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Install frontend dependencies | |
| working-directory: web | |
| run: npm ci | |
| - name: Install E2E test dependencies | |
| working-directory: tests | |
| run: npm ci | |
| - name: Install Playwright browsers | |
| working-directory: tests | |
| run: npx playwright install --with-deps chromium | |
| continue-on-error: true | |
| - name: Run database migrations | |
| working-directory: backend | |
| run: | | |
| alembic upgrade head | |
| env: | |
| DATABASE_URL: postgresql+asyncpg://test:test@localhost:5432/test | |
| - name: Start backend server | |
| working-directory: backend | |
| run: | | |
| nohup uvicorn main:app --host 0.0.0.0 --port 8000 > /tmp/backend.log 2>&1 & | |
| echo $! > /tmp/backend.pid | |
| env: | |
| DATABASE_URL: postgresql+asyncpg://test:test@localhost:5432/test | |
| REDIS_URL: redis://localhost:6379 | |
| ISSUER_URI: http://localhost:8080/realms/tasks | |
| PUBLIC_ISSUER_URI: http://localhost:8080/realms/tasks | |
| CLIENT_ID: tasks-backend | |
| CLIENT_SECRET: tasks-secret | |
| ENV: test | |
| INFLUXDB_URL: http://localhost:8086 | |
| INFLUXDB_TOKEN: test-token | |
| INFLUXDB_ORG: test | |
| INFLUXDB_BUCKET: test | |
| - name: Build frontend | |
| working-directory: web | |
| run: npm run build | |
| env: | |
| NEXT_PUBLIC_API_URL: http://localhost:8000/graphql | |
| - name: Start frontend server | |
| working-directory: web | |
| run: | | |
| nohup npm start > /tmp/frontend.log 2>&1 & | |
| echo $! > /tmp/frontend.pid | |
| env: | |
| NEXT_PUBLIC_API_URL: http://localhost:8000/graphql | |
| - name: Wait for backend | |
| run: | | |
| echo "Waiting for backend to start..." | |
| sleep 5 | |
| for i in {1..60}; do | |
| if curl -f -s http://localhost:8000/health > /dev/null 2>&1; then | |
| echo "Backend is ready!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i/60: Backend not ready yet..." | |
| sleep 2 | |
| done | |
| echo "Backend failed to start after 120 seconds" | |
| echo "=== Backend Log ===" | |
| cat /tmp/backend.log || echo "No backend log found" | |
| exit 1 | |
| - name: Wait for frontend | |
| run: | | |
| echo "Waiting for frontend to start..." | |
| sleep 5 | |
| for i in {1..60}; do | |
| if curl -f -s http://localhost:3000 > /dev/null 2>&1; then | |
| echo "Frontend is ready!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i/60: Frontend not ready yet..." | |
| sleep 2 | |
| done | |
| echo "Frontend failed to start after 120 seconds" | |
| echo "=== Frontend Log ===" | |
| cat /tmp/frontend.log || echo "No frontend log found" | |
| exit 1 | |
| - name: Run E2E tests | |
| working-directory: tests | |
| env: | |
| E2E_BASE_URL: http://localhost:3000 | |
| run: npx playwright test | |
| - name: Upload Playwright report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-report | |
| path: tests/playwright-report/ | |
| retention-days: 30 | |
| - name: Upload server logs | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: server-logs | |
| path: | | |
| /tmp/backend.log | |
| /tmp/frontend.log | |
| retention-days: 7 | |
| build: | |
| needs: [backend-tests, frontend-tests, e2e-tests, simulator-lint] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: web/package-lock.json | |
| - name: Install backend dependencies | |
| working-directory: backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Install frontend dependencies | |
| working-directory: web | |
| run: npm ci | |
| - name: Build frontend | |
| working-directory: web | |
| run: npm run build | |
| - name: Upload build artifacts | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-build | |
| path: web/.next | |
| retention-days: 7 |