-
Notifications
You must be signed in to change notification settings - Fork 1.9k
142 lines (115 loc) · 4.75 KB
/
cd_PR.yml
File metadata and controls
142 lines (115 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Pull Request Preview Deployment
on:
pull_request:
types: ['opened', 'edited', 'synchronize']
branches:
- '**'
jobs:
Deploy-PR-Preview:
# needs: [Continuous-Integration]
# environment: branch-deploy
name: Build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Initialize deployment status
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: branch-deploy-${{ github.head_ref }}
ref: ${{ github.head_ref }}
- name: Install dependencies and build
run: |
pnpm i -g vercel
pnpm install
env:
DATABASE_URL: ${{ secrets.DB_URL }}
- name: Deploy to vercel
env:
DB_URL: ${{ secrets.DB_URL }}
run: |
chmod +x ./scripts/set-vercel-env.sh
cp .env.example .env
sed -i '/^DATABASE_URL=/d' .env
echo "DATABASE_URL=${{ secrets.DB_URL }}" >> .env
vercel link --yes --project pr-${{ github.event.pull_request.number }}-cms --token ${{ secrets.VERCEL_TOKEN }}
sed -i '/^NEXTAUTH_URL=/d' .env
echo "NEXTAUTH_URL=https://pr-${{ github.event.pull_request.number }}-cms.vercel.app" >> .env
if ! vercel env ls --token ${{ secrets.VERCEL_TOKEN }} | grep "DATABASE_URL"; then
echo "Setting up Vercel env..."
./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..."
fi
vercel build --prod --token ${{ secrets.VERCEL_TOKEN }} --yes
vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} > deployment-url.txt
vercel alias `cat deployment-url.txt` pr-${{ github.event.pull_request.number }}-cms --token ${{ secrets.VERCEL_TOKEN }}
echo "DEPLOYMENT_URL=$(cat deployment-url.txt)" >> $GITHUB_ENV
- name: Upload Deployment Artifacts
uses: actions/upload-artifact@v4
with:
name: deployment-url
path: |
deployment-url.txt
- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: https://pr-${{ github.event.pull_request.number }}-cms.vercel.app
env: ${{ steps.deployment.outputs.env }}
Prisma-Migrations:
needs: [Deploy-PR-Preview]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for migration changes
id: check-migrations
run: |
if git diff --quiet HEAD^ HEAD -- prisma/migrations; then
echo "migrations_changed=false" >> $GITHUB_OUTPUT
else
echo "migrations_changed=true" >> $GITHUB_OUTPUT
fi
- name: Install pnpm
if: steps.check-migrations.outputs.migrations_changed == 'true'
uses: pnpm/action-setup@v4
with:
version: 10
- name: Install dependencies and build
if: steps.check-migrations.outputs.migrations_changed == 'true'
run: |
pnpm i -g vercel
pnpm install
- name: Setup Node
if: steps.check-migrations.outputs.migrations_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Apply all pending migrations
if: steps.check-migrations.outputs.migrations_changed == 'true'
env:
DATABASE_URL: ${{ secrets.DB_URL }}
run: |
echo "Applying migrations"
pnpm prisma generate
echo "Deploying migrations"
pnpm prisma migrate deploy > migrate.log
echo "Resetting migrations"
pnpm prisma migrate reset --force > reset.log
echo "Migrations applied"