fix(backend): correct import formatting in main.py #81
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop, dockerized-frontendlol ] | |
| pull_request: | |
| branches: [ main, develop, dockerized-frontendlol ] | |
| jobs: | |
| # Frontend CI/CD | |
| frontend: | |
| name: Frontend CI/CD | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./frontend | |
| strategy: | |
| matrix: | |
| node-version: [18.x, 20.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| cache-dependency-path: package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run ESLint | |
| run: npm run lint | |
| - name: Run type checking | |
| run: npm run type-check | |
| - name: Run tests | |
| run: npm run test | |
| - name: Build application | |
| run: npm run build | |
| env: | |
| NEXT_PUBLIC_BACKEND_URL: ${{ secrets.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000' }} | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: matrix.node-version == '20.x' | |
| with: | |
| name: frontend-build | |
| path: frontend/.next/ | |
| retention-days: 1 | |
| # Backend CI/CD | |
| backend: | |
| name: Backend CI/CD | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./backend | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11"] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| cache-dependency-path: backend/requirements-dev.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-dev.txt | |
| - name: Run code formatting check (Black) | |
| run: black --check --diff . | |
| - name: Run import sorting check (isort) | |
| run: isort --check-only --diff . | |
| - name: Run linting (flake8) | |
| run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| - name: Run tests with coverage | |
| run: pytest --cov=. --cov-report=xml --cov-report=html | |
| env: | |
| TESTING: true | |
| DATABASE_URL: ${{ secrets.DATABASE_URL || 'sqlite:///test.db' }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'test-key' }} | |
| - name: Upload coverage reports | |
| uses: codecov/codecov-action@v3 | |
| if: matrix.python-version == '3.11' | |
| with: | |
| file: ./backend/coverage.xml | |
| flags: backend | |
| name: backend-coverage | |
| # Integration Tests | |
| integration: | |
| name: Integration Tests | |
| runs-on: ubuntu-latest | |
| needs: [frontend, backend] | |
| if: github.event_name == 'pull_request' | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_PASSWORD: test | |
| POSTGRES_DB: smartquery_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| cache-dependency-path: package-lock.json | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| cache-dependency-path: backend/requirements-dev.txt | |
| - name: Install frontend dependencies | |
| working-directory: ./frontend | |
| run: npm ci | |
| - name: Install backend dependencies | |
| working-directory: ./backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-dev.txt | |
| - name: Start backend server | |
| working-directory: ./backend | |
| run: | | |
| uvicorn main:app --host 0.0.0.0 --port 8000 & | |
| sleep 10 | |
| env: | |
| DATABASE_URL: postgresql://postgres:test@localhost:5432/smartquery_test | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'test-key' }} | |
| - name: Run integration tests | |
| working-directory: ./frontend | |
| run: npm run test:integration | |
| env: | |
| NEXT_PUBLIC_BACKEND_URL: http://localhost:8000 | |
| - name: Health check | |
| run: | | |
| curl -f http://localhost:8000/health || exit 1 | |
| # Security and Quality Checks | |
| security: | |
| name: Security & Quality | |
| runs-on: ubuntu-latest | |
| permissions: | |
| security-events: write | |
| actions: read | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| scan-type: 'fs' | |
| scan-ref: '.' | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| - name: Upload Trivy scan results | |
| uses: github/codeql-action/upload-sarif@v3 | |
| if: always() | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| - name: Setup Node.js for audit | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| cache-dependency-path: package-lock.json | |
| - name: Frontend security audit | |
| working-directory: ./frontend | |
| run: npm audit --audit-level=high || echo "Security audit found issues but continuing..." | |
| - name: Setup Python for security check | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install safety | |
| run: pip install safety | |
| - name: Backend security audit | |
| working-directory: ./backend | |
| run: safety check -r requirements-dev.txt || echo "Security audit found issues but continuing..." | |
| # Deployment (only on main branch) | |
| deploy: | |
| name: Deploy | |
| runs-on: ubuntu-latest | |
| needs: [frontend, backend, security] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download frontend build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frontend-build | |
| path: frontend/.next/ | |
| - name: Deploy to staging | |
| run: | | |
| echo "Deploying to staging environment..." | |
| # Add your deployment commands here | |
| # For example: deploy to Vercel, AWS, etc. | |
| - name: Notify deployment | |
| uses: 8398a7/action-slack@v3 | |
| if: always() | |
| with: | |
| status: ${{ job.status }} | |
| text: 'Deployment completed' | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |