-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (224 loc) · 8.72 KB
/
ci-preview.yaml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
name: Preview CI
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
TURBO_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
NEXT_PUBLIC_SERVER_BASE_URL: ${{secrets.NEXT_PUBLIC_SERVER_BASE_URL }}
TEST_ACCESS_TOKEN: ${{secrets.TEST_ACCESS_TOKEN }}
TEST_REFRESH_TOKEN: ${{secrets.TEST_REFRESH_TOKEN }}
on:
push:
branches-ignore:
- main
jobs:
Setup:
runs-on: ubuntu-latest
outputs:
cache_status_bottle: ${{ steps.determine-status.outputs.cache_status_bottle }}
cache_status_demo: ${{ steps.determine-status.outputs.cache_status_demo }}
cache_status_web: ${{ steps.determine-status.outputs.cache_status_web }}
cache_status_e2e: ${{ steps.determine-status.outputs.cache_status_e2e }}
steps:
# checkout and install pnpm
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
# setup node
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
# install dependencies
- run: npx pnpm i -r
# set .env.local
- name: create dotenv
run: |
touch apps/bottle/.env.local
echo "TEST_ACCESS_TOKEN=${{ secrets.TEST_ACCESS_TOKEN }}" >> apps/bottle/.env.local
echo "TEST_REFRESH_TOKEN=${{ secrets.TEST_REFRESH_TOKEN }}" >> apps/bottle/.env.local
echo "NEXT_PUBLIC_SERVER_BASE_URL=${{ secrets.NEXT_PUBLIC_SERVER_BASE_URL }}" >> apps/bottle/.env.local
env:
NEXT_PUBLIC_SERVER_BASE_URL: ${{ secrets.NEXT_PUBLIC_SERVER_BASE_URL }}
# determine whether @bottlesteam/bottle, @bottlesteam/web is cached on remote
- name: Determine cache status for each services
id: determine-status
run: |
pnpx turbo run build --dry-run=json > result.json
cache_status_bottle=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/bottle#build") | .cache.status' result.json)
cache_status_demo=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/demo#build") | .cache.status' result.json)
cache_status_web=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/web#build") | .cache.status' result.json)
pnpx turbo run test:e2e --dry-run=json > result2.json
cache_status_e2e=$(jq -r '.tasks[] | select(.taskId == "@bottlesteam/e2e#test:e2e") | .cache.status' result2.json)
echo "cache_status_bottle=$cache_status_bottle" >> $GITHUB_OUTPUT
echo "cache_status_demo=$cache_status_demo" >> $GITHUB_OUTPUT
echo "cache_status_web=$cache_status_web" >> $GITHUB_OUTPUT
echo "cache_status_e2e=$cache_status_e2e" >> $GITHUB_OUTPUT
- name: Cache Status Print
run: |
echo "cache_status_bottle: ${{ steps.determine-status.outputs.cache_status_bottle }}"
echo "cache_status_demo: ${{ steps.determine-status.outputs.cache_status_demo }}"
echo "cache_status_web: ${{ steps.determine-status.outputs.cache_status_web }}"
echo "cache_status_e2e: ${{ steps.determine-status.outputs.cache_status_e2e }}"
# install playwright depedencies only if @bottlesteam/bottle is not cached
- run: pnpx playwright install --with-deps
if: steps.determine-status.outputs.cache_status_e2e == 'MISS'
# run turbo tasks
- run: pnpm run ci
Deploy_Bottle_to_Vercel:
# deploy Bottle to vercel
runs-on: ubuntu-latest
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }}
needs: Setup
if: needs.Setup.outputs.cache_status_bottle == 'MISS'
steps:
# checkout and install pnpm
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
# setup node
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Deploy to Vercel if needed
run: |
npm install --global vercel@latest
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel build --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel deploy --prebuilt --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
- name: Get Vercel Preview
uses: zentered/[email protected]
id: vercel_preview_url
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }}
with:
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }}
- name: Get URL
run: echo "https://${{ steps.vercel_preview_url.outputs.preview_url }}"
- name: Send Slack Notification
env:
DATA: |
{
"channel": "C07N47FH04Q",
"text": "<@U07L87GGHJS>
🍾 보틀 미리보기 배포 완료!
👉 https://${{ steps.vercel_preview_url.outputs.preview_url }}",
}
run: |
curl -X POST -H "Content-Type: application/json" \
-d "$DATA" \
${{ secrets.SLACK_WEBHOOK_URL }}
Deploy_Demo_to_Vercel:
# deploy Demo to vercel
runs-on: ubuntu-latest
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_Demo }}
needs: Setup
if: needs.Setup.outputs.cache_status_demo == 'MISS'
steps:
# checkout and install pnpm
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
# setup node
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Deploy to Vercel if needed
run: |
npm install --global vercel@latest
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel build --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel deploy --prebuilt --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
- name: Get Vercel Preview
uses: zentered/[email protected]
id: vercel_preview_url
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }}
with:
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID_BOTTLE }}
- name: Get URL
run: echo "https://${{ steps.vercel_preview_url.outputs.preview_url }}"
- name: Send Slack Notification
env:
DATA: |
{
"channel": "C07N47FH04Q",
"text": "<@U07L87GGHJS>
🍾 데모 미리보기 배포 완료!
👉 https://${{ steps.vercel_preview_url.outputs.preview_url }}",
}
run: |
curl -X POST -H "Content-Type: application/json" \
-d "$DATA" \
${{ secrets.SLACK_WEBHOOK_URL }}
Deploy_Web_to_Vercel:
# deploy Web to vercel
runs-on: ubuntu-latest
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB }}
needs: Setup
if: needs.Setup.outputs.cache_status_web == 'MISS'
steps:
# checkout and install pnpm
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
# setup node
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: cd apps/web
- name: Deploy to Vercel if needed
run: |
npm install --global vercel@latest
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel build --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
vercel deploy --prebuilt --token=${{ secrets.VERCEL_ACCESS_TOKEN }}
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- name: Get Vercel Preview
uses: zentered/[email protected]
id: vercel_preview_url_web
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_ACCESS_TOKEN }}
with:
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID_WEB }}
- name: Get URL
run: echo "https://${{ steps.vercel_preview_url_web.outputs.preview_url }}"
- name: Send Slack Notification
env:
DATA: |
{
"channel": "C07N47FH04Q",
"text": "<@U07L87GGHJS>
랜딩 페이지 미리보기 배포 완료!
👉 https://${{ steps.vercel_preview_url_web.outputs.preview_url }}",
}
run: |
curl -X POST -H "Content-Type: application/json" \
-d "$DATA" \
${{ secrets.SLACK_WEBHOOK_URL }}