1- name : Pull Request build+deploy
1+ name : Pull Request Preview Deployment
22
33on :
44 pull_request :
55 types : ['opened', 'edited', 'synchronize']
66 branches :
7- - ' **'
7+ - ' **'
8+
89
910jobs :
10- deploy :
11- environment : branch-deploy
11+
12+ Deploy-PR-Preview :
13+ # needs: [Continuous-Integration]
14+ # environment: branch-deploy
1215 name : Build and deploy
1316 runs-on : ubuntu-latest
17+
1418 steps :
1519 - name : Checkout code
1620 uses : actions/checkout@v4
@@ -20,17 +24,13 @@ jobs:
2024 with :
2125 version : 10
2226
23-
24- - name : Set up Docker
25- uses : docker/setup-docker-action@v4
26-
2727 - name : Setup Node
2828 uses : actions/setup-node@v4
2929 with :
3030 node-version : 20
3131 cache : ' pnpm'
3232
33- - name : Setup deployment
33+ - name : Initialize deployment status
3434 uses : bobheadxi/deployments@v1
3535 id : deployment
3636 with :
@@ -39,24 +39,46 @@ jobs:
3939 env : branch-deploy-${{ github.head_ref }}
4040 ref : ${{ github.head_ref }}
4141
42- - name : Install dependencies
43- run : ./setup.sh
44-
45- - name : Deploy to Netlify
46- uses : nwtgck/actions-netlify@v3.0
47- with :
48- publish-dir : ' ./next'
49- production-branch : main
50- github-token : ${{ secrets.GITHUB_TOKEN }}
51- deploy-message : " Deploy from GitHub Actions"
52- enable-pull-request-comment : false
53- enable-commit-comment : true
54- overwrites-pull-request-comment : true
55- alias : deploy-preview-${{ github.event.number }}-100xdevs
42+ - name : Install dependencies and build
43+ run : |
44+ pnpm i -g vercel
45+ pnpm install
46+
5647 env :
57- NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
58- NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
59- timeout-minutes : 1
48+ DATABASE_URL : ${{ secrets.DB_URL }}
49+
50+ - name : Deploy to vercel
51+ env :
52+ DB_URL : ${{ secrets.DB_URL }}
53+ run : |
54+ chmod +x ./scripts/set-vercel-env.sh
55+ cp .env.example .env
56+ sed -i '/^DATABASE_URL=/d' .env
57+ echo "DATABASE_URL=${{ secrets.DB_URL }}" >> .env
58+ vercel link --yes --project pr-${{ github.event.pull_request.number }}-cms --token ${{ secrets.VERCEL_TOKEN }}
59+
60+ sed -i '/^NEXTAUTH_URL=/d' .env
61+ echo "NEXTAUTH_URL=https://pr-${{ github.event.pull_request.number }}-cms.vercel.app" >> .env
62+
63+ if ! vercel env ls --token ${{ secrets.VERCEL_TOKEN }} | grep "DATABASE_URL"; then
64+ echo "Setting up Vercel env..."
65+ ./scripts/set-vercel-env.sh production ${{ secrets.VERCEL_TOKEN }} https://pr-${{ github.event.pull_request.number }}-cms.vercel.app || echo "Warning: Failed to set up Vercel env, but continuing..."
66+ fi
67+
68+
69+ vercel build --prod --token ${{ secrets.VERCEL_TOKEN }} --yes
70+ vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} > deployment-url.txt
71+ vercel alias `cat deployment-url.txt` pr-${{ github.event.pull_request.number }}-cms --token ${{ secrets.VERCEL_TOKEN }}
72+
73+ echo "DEPLOYMENT_URL=$(cat deployment-url.txt)" >> $GITHUB_ENV
74+
75+ - name : Upload Deployment Artifacts
76+ uses : actions/upload-artifact@v4
77+ with :
78+ name : deployment-url
79+ path : |
80+ deployment-url.txt
81+
6082
6183 - name : Update deployment status
6284 uses : bobheadxi/deployments@v1
6688 token : ${{ secrets.GITHUB_TOKEN }}
6789 status : ${{ job.status }}
6890 deployment_id : ${{ steps.deployment.outputs.deployment_id }}
69- logs : ${{ steps.deploy-netlify.outputs.netlify_logs_url }}
70- env_url : ${{ steps.deploy-netlify.outputs.netlify_preview_url }}
91+ env_url : https://pr-${{ github.event.pull_request.number }}-cms.vercel.app
92+ env : ${{ steps.deployment.outputs.env }}
93+
94+
95+ Prisma-Migrations :
96+ needs : [Deploy-PR-Preview]
97+ runs-on : ubuntu-latest
98+
99+ steps :
100+ - name : Checkout code
101+ uses : actions/checkout@v4
102+
103+ - name : Check for migration changes
104+ id : check-migrations
105+ run : |
106+ echo "Checking for changes in prisma/migrations folder..."
107+ git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
108+ if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -q '^prisma/migrations/'; then
109+ echo "Migrations have changed"
110+ echo "migrations_changed=true" >> $GITHUB_OUTPUT
111+ else
112+ echo "No migration changes detected"
113+ echo "migrations_changed=false" >> $GITHUB_OUTPUT
114+
115+ - name : Install pnpm
116+ if : steps.check-migrations.outputs.migrations_changed == 'true'
117+ uses : pnpm/action-setup@v4
118+ with :
119+ version : 10
120+
121+ - name : Install dependencies and build
122+ if : steps.check-migrations.outputs.migrations_changed == 'true'
123+ run : |
124+ pnpm i -g vercel
125+ pnpm install
126+
127+ - name : Setup Node
128+ if : steps.check-migrations.outputs.migrations_changed == 'true'
129+ uses : actions/setup-node@v4
130+ with :
131+ node-version : 20
132+ cache : ' pnpm'
133+
134+ - name : Apply all pending migrations
135+ if : steps.check-migrations.outputs.migrations_changed == 'true'
136+ env :
137+ DATABASE_URL : ${{ secrets.DB_URL }}
138+ run : |
139+ echo "Applying migrations"
140+ pnpm prisma generate
141+ echo "Deploying migrations"
142+ pnpm prisma migrate deploy > migrate.log
143+ echo "Resetting migrations"
144+ pnpm prisma migrate reset --force > reset.log
145+ echo "Migrations applied"
0 commit comments