From 2c1d761fb421e2622e484ffd47f2bbfd1d31ec70 Mon Sep 17 00:00:00 2001 From: rahuldahal Date: Fri, 31 May 2024 14:51:18 +0545 Subject: [PATCH] devops: setup deploy workflow --- .github/workflows/deploy.yml | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0697360 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,52 @@ +name: Deploy to Render + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Check if schema.prisma has changed + id: schema_changed + run: | + git fetch origin main + git diff --exit-code origin/main -- prisma/schema.prisma || echo "schema_changed=true" >> $GITHUB_ENV + + - name: Generate Prisma client + if: env.schema_changed == 'true' + run: npx prisma generate + + - name: Create and apply Prisma migrations + if: env.schema_changed == 'true' + run: | + npx prisma migrate dev --name auto-migration + npx prisma migrate deploy + + - name: Build the application + run: yarn build + + - name: Deploy to Render + env: + RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} + SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }} + run: | + curl -X POST "https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys" \ + -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + --data '{"clearCache":false}'