1
- name : Pull Request build+deploy
1
+ name : Pull Request Preview Deployment
2
2
3
3
on :
4
4
pull_request :
5
5
types : ['opened', 'edited', 'synchronize']
6
6
branches :
7
- - ' **'
7
+ - ' **'
8
+
8
9
9
10
jobs :
10
- deploy :
11
- environment : branch-deploy
11
+
12
+ Deploy-PR-Preview :
13
+ # needs: [Continuous-Integration]
14
+ # environment: branch-deploy
12
15
name : Build and deploy
13
16
runs-on : ubuntu-latest
17
+
14
18
steps :
15
19
- name : Checkout code
16
20
uses : actions/checkout@v4
@@ -20,17 +24,13 @@ jobs:
20
24
with :
21
25
version : 10
22
26
23
-
24
- - name : Set up Docker
25
- uses : docker/setup-docker-action@v4
26
-
27
27
- name : Setup Node
28
28
uses : actions/setup-node@v4
29
29
with :
30
30
node-version : 20
31
31
cache : ' pnpm'
32
32
33
- - name : Setup deployment
33
+ - name : Initialize deployment status
34
34
uses : bobheadxi/deployments@v1
35
35
id : deployment
36
36
with :
@@ -39,24 +39,46 @@ jobs:
39
39
env : branch-deploy-${{ github.head_ref }}
40
40
ref : ${{ github.head_ref }}
41
41
42
- - name : Install dependencies
43
- run : ./setup.sh
44
-
45
- - name : Deploy to Netlify
46
-
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
+
56
47
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
+
60
82
61
83
- name : Update deployment status
62
84
uses : bobheadxi/deployments@v1
66
88
token : ${{ secrets.GITHUB_TOKEN }}
67
89
status : ${{ job.status }}
68
90
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
+ if git diff --quiet HEAD^ HEAD -- prisma/migrations; then
107
+ echo "migrations_changed=false" >> $GITHUB_OUTPUT
108
+ else
109
+ echo "migrations_changed=true" >> $GITHUB_OUTPUT
110
+ fi
111
+
112
+ - name : Install pnpm
113
+ if : steps.check-migrations.outputs.migrations_changed == 'true'
114
+ uses : pnpm/action-setup@v4
115
+ with :
116
+ version : 10
117
+
118
+ - name : Install dependencies and build
119
+ if : steps.check-migrations.outputs.migrations_changed == 'true'
120
+ run : |
121
+ pnpm i -g vercel
122
+ pnpm install
123
+
124
+ - name : Setup Node
125
+ if : steps.check-migrations.outputs.migrations_changed == 'true'
126
+ uses : actions/setup-node@v4
127
+ with :
128
+ node-version : 20
129
+ cache : ' pnpm'
130
+
131
+ - name : Apply all pending migrations
132
+ if : steps.check-migrations.outputs.migrations_changed == 'true'
133
+ env :
134
+ DATABASE_URL : ${{ secrets.DB_URL }}
135
+ run : |
136
+ echo "Applying migrations"
137
+ pnpm prisma generate
138
+ echo "Deploying migrations"
139
+ pnpm prisma migrate deploy > migrate.log
140
+ echo "Resetting migrations"
141
+ pnpm prisma migrate reset --force > reset.log
142
+ echo "Migrations applied"
0 commit comments