Testing CICD #5
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: Backend CI/CD | |
| on: | |
| push: | |
| branches: | |
| - "niteshsachde/cicd" | |
| - "main" | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend-cicd.yml" | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./backend | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_DB: test_db | |
| POSTGRES_USER: user | |
| POSTGRES_PASSWORD: password | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Tests | |
| env: | |
| SECRET_KEY: "test_secret_key" | |
| DEBUG: "True" | |
| DATABASE_URL: "postgres://user:password@localhost:5432/test_db" | |
| # Add these dummy values so Django settings don't crash during tests | |
| CLOUDINARY_CLOUD_NAME: "test_cloud" | |
| CLOUDINARY_API_KEY: "123456789" | |
| CLOUDINARY_API_SECRET: "test_secret" | |
| BREVO_API_KEY: "test_brevo_key" | |
| DEFAULT_FROM_EMAIL: "test@example.com" | |
| FRONTEND_URL: "http://localhost:3000" | |
| run: | | |
| pytest | |
| deploy: | |
| needs: test | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/niteshsachde/cicd' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger Render Deployment | |
| if: success() | |
| run: | | |
| if [ -n "${{ secrets.RENDER_DEPLOY_HOOK_URL }}" ]; then | |
| curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}" | |
| echo "Deployment triggered successfully." | |
| else | |
| echo "RENDER_DEPLOY_HOOK_URL not set. Skipping deployment trigger." | |
| echo "Please set RENDER_DEPLOY_HOOK_URL in your repository secrets." | |
| fi |