diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 0000000..68b5755 --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,57 @@ +name: Backend CI/CD + +on: + push: + branches: + - main + +jobs: + test_backend: + runs-on: ubuntu-latest + + services: + mongodb: + image: mongo:latest + ports: + - 27017:27017 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js for Backend + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install Backend dependencies + run: | + cd backend + npm install + + - name: Run Backend tests + env: + MONGO_URI: mongodb://localhost:27017/testdb + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: cd backend && npm test + + deploy_backend: + needs: test_backend + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Deploy to Render + env: + RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} + RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }} + run: | + curl -X POST \ + -H "Authorization: Bearer $RENDER_API_KEY" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + -d '{}' \ + https://api.render.com/v1/services/$RENDER_SERVICE_ID/deploys +