Skip to content

Commit

Permalink
feat: add custom render build script
Browse files Browse the repository at this point in the history
- Fetch latest code from origin main
- Check if schema.prisma has changed
- Run Prisma generate and migrate commands if schema has changed
- Install dependencies using yarn
- Build the application
  • Loading branch information
rahuldahal committed May 31, 2024
1 parent 6afe33c commit f55b752
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
57 changes: 24 additions & 33 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,43 @@
name: Deploy to Render
name: Trigger Deploy to Render

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

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
id: deploy
env:
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
run: |
curl --request POST \
response=$(curl --write-out "%{http_code}" --silent --output response.json --request POST \
--url "https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys" \
--header "accept: application/json" \
--header "authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \
--header "content-type: application/json"
--header "content-type: application/json")
echo "HTTP_RESPONSE=$response" >> $GITHUB_ENV
if [[ "$response" -eq 200 ]]; then
echo "Deployment triggered successfully"
else
echo "Deployment failed"
cat response.json
exit 1
fi
- name: Success Step
if: success()
run: echo "Deployment was successful"

- name: Failure Step
if: failure()
run: echo "Deployment failed"
23 changes: 23 additions & 0 deletions render-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

git fetch origin main

# Check if schema.prisma has changed
if git diff --exit-code origin/main -- prisma/schema.prisma; then
echo "schema.prisma has not changed. Skipping Prisma commands."
else
echo "schema.prisma has changed. Running Prisma commands."

# Generate Prisma client
npx prisma generate

# Create and apply Prisma migrations
npx prisma migrate dev --name auto-migration
npx prisma migrate deploy
fi

yarn install --frozen-lockfile

yarn build

0 comments on commit f55b752

Please sign in to comment.