-
Notifications
You must be signed in to change notification settings - Fork 12
302 lines (302 loc) · 12 KB
/
app-deploy.yml
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
name: App Deploy
on:
push:
branches: [main, stage, feature/*]
pull_request:
branches: [main, feature/*]
merge_group:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
affected:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20]
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ matrix.node-version }}-
- name: NPM Install
run: npm install --silent
- uses: nrwl/nx-set-shas@v4
- id: set-matrix
name: set matrix app to affected array
run: |
echo "matrix=$(npx ts-node tools/scripts/deploy-apps.ts --projects apps/* --exclude api-*)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
deploy-preview:
name: Deploy Preview and Test
needs: affected
# if branch is not main or is a pull request
if: |
needs.affected.outputs.matrix != '[]' &&
needs.affected.outputs.matrix != '' && (
github.ref != 'refs/heads/main' || github.event_name == 'pull_request'
)
strategy:
fail-fast: false
matrix:
app: ${{fromJson(needs.affected.outputs.matrix)}}
github-ref-name: ['${{ github.ref_name }}']
github-event-name: ['${{ github.event_name }}']
node-version: [20]
exclude:
# handled by production job below
- app: journeys
github-ref-name: stage
github-event-name: push
# handled by production job below
- app: short-links
github-ref-name: stage
github-event-name: push
# handled by ecs-frontend-deploy-stage
- app: journeys-admin
github-ref-name: stage
github-event-name: push
runs-on: ubuntu-latest
outputs:
url: ${{ steps.deployment-url.outputs.deployment-url }}
permissions:
pull-requests: write
deployments: write
contents: write
steps:
- name: start deployment
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: Preview - ${{ matrix.app }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ matrix.node-version }}-
- name: NPM Install
run: npm install --silent
- uses: nrwl/nx-set-shas@v4
- name: vercel deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
ARCLIGHT_VERCEL_PROJECT_ID: ${{ secrets.ARCLIGHT_VERCEL_PROJECT_ID }}
DOCS_VERCEL_PROJECT_ID: ${{ secrets.DOCS_VERCEL_PROJECT_ID }}
JOURNEYS_VERCEL_PROJECT_ID: ${{ secrets.JOURNEYS_STAGE_VERCEL_PROJECT_ID }}
JOURNEYS_ADMIN_VERCEL_PROJECT_ID: ${{ secrets.JOURNEYS_ADMIN_VERCEL_PROJECT_ID }}
SHORT_LINKS_VERCEL_PROJECT_ID: ${{ secrets.SHORT_LINKS_STAGE_VERCEL_PROJECT_ID }}
VIDEOS_ADMIN_VERCEL_PROJECT_ID: ${{ secrets.VIDEOS_ADMIN_VERCEL_PROJECT_ID }}
WATCH_VERCEL_PROJECT_ID: ${{ secrets.WATCH_VERCEL_PROJECT_ID }}
NEXT_PUBLIC_VERCEL_ENV: ${{ github.event_name == 'push' && github.ref == 'refs/heads/stage' && 'stage' || 'preview' }}
NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
# use run-namy to avoid case where deploy command doesn't exist for a project
run: npx nx run-many --target=deploy --projects=${{ matrix.app }}
- name: upload sourcemaps to datadog
env:
GIT_COMMIT_SHA: ${{ github.sha }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
run: npx nx run-many --target=upload-sourcemaps --projects=${{ matrix.app }}
- name: vercel set alias
if: ${{ github.event_name == 'pull_request' }}
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
# use run-namy to avoid case where deploy command doesn't exist for a project
run: npx nx run-many --target=vercel-alias --projects=${{ matrix.app }}
- name: Generate GitHub deployment comment
id: deployment-url
env:
APP: ${{ matrix.app }}
run: ./tools/scripts/generate-deployment-comment.sh
- id: get-comment-body
run: |
body="$(cat .github/deployment_comment.md)"
delimiter="$(openssl rand -hex 8)"
echo "body<<$delimiter" >> $GITHUB_OUTPUT
echo "$body" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- uses: mshick/add-pr-comment@v2
if: ${{ github.event_name == 'pull_request' }}
name: add deployment comment to pull request
with:
message: ${{ steps.get-comment-body.outputs.body }}
message-id: ${{ matrix.app }}
- name: add deployment comment to commit
if: ${{ github.event_name != 'pull_request' }}
uses: peter-evans/commit-comment@v3
with:
body: ${{ steps.get-comment-body.outputs.body }}
- name: update deployment status
uses: chrnorm/deployment-status@v2
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
state: ${{ job.status }}
environment-url: ${{ steps.deployment-url.outputs.deployment-url }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Store Playwright's Version
run: |
PLAYWRIGHT_VERSION=$(npm run playwright -v)
echo "Playwright's Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright Browsers for Playwright's Version
id: cache-playwright-browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}
- run: npx playwright install --with-deps
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true'
- run: npx playwright install-deps
if: steps.cache-playwright-browsers.outputs.cache-hit == 'true'
- name: Run Playwright tests
run: npx nx run ${{ matrix.app }}-e2e:e2e
env:
DEPLOYMENT_URL: ${{ steps.deployment-url.outputs.deployment-url }}
PLAYWRIGHT_EMAIL: ${{ secrets.PLAYWRIGHT_EMAIL }}
PLAYWRIGHT_PASSWORD: ${{ secrets.PLAYWRIGHT_PASSWORD }}
PLAYWRIGHT_USER: ${{ secrets.PLAYWRIGHT_USER }}
PLAYWRIGHT_TEAM_NAME: ${{ secrets.PLAYWRIGHT_TEAM_NAME }}
EXAMPLE_EMAIL_TOKEN: ${{ secrets.EXAMPLE_EMAIL_TOKEN }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.app }}-playwright-report
path: |
playwright-report/
retention-days: 30
deploy-status:
runs-on: ubuntu-latest
needs: [affected, deploy-preview]
if: ${{ always() && github.event_name == 'pull_request' }}
steps:
- name: Successful deploy
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Failing deploy
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
deploy-production:
name: Deploy Production
# if push to main or stage
if: |
needs.affected.outputs.matrix != '[]' &&
needs.affected.outputs.matrix != '' &&
github.event_name == 'push' &&
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stage')
needs: affected
strategy:
fail-fast: false
matrix:
app: ${{fromJson(needs.affected.outputs.matrix)}}
github-ref-name: ['${{ github.ref_name }}']
node-version: [20]
exclude:
# handled by ecs-frontend-deploy-prod
- app: journeys-admin
# handled by deploy-preview job above
- github-ref-name: stage
include:
- app: journeys
github-ref-name: stage
- app: short-links
github-ref-name: stage
runs-on: ubuntu-latest
permissions:
deployments: write
contents: write
outputs:
url: ${{ steps.deployment-url.outputs.deployment-url }}
steps:
- name: start deployment
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: Production - ${{ matrix.app }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
restore-keys: node-modules-${{ matrix.node-version }}-
- name: NPM Install
run: npm install --silent
- uses: nrwl/nx-set-shas@v4
- name: vercel deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
ARCLIGHT_VERCEL_PROJECT_ID: ${{ secrets.ARCLIGHT_VERCEL_PROJECT_ID }}
DOCS_VERCEL_PROJECT_ID: ${{ secrets.DOCS_VERCEL_PROJECT_ID }}
JOURNEYS_VERCEL_PROJECT_ID: ${{ github.ref == 'refs/heads/stage' && secrets.JOURNEYS_STAGE_VERCEL_PROJECT_ID || secrets.JOURNEYS_VERCEL_PROJECT_ID }}
JOURNEYS_ADMIN_VERCEL_PROJECT_ID: ${{ secrets.JOURNEYS_ADMIN_VERCEL_PROJECT_ID }}
SHORT_LINKS_VERCEL_PROJECT_ID: ${{ github.ref == 'refs/heads/stage' && secrets.SHORT_LINKS_STAGE_VERCEL_PROJECT_ID || secrets.SHORT_LINKS_VERCEL_PROJECT_ID }}
VIDEOS_ADMIN_VERCEL_PROJECT_ID: ${{ secrets.VIDEOS_ADMIN_VERCEL_PROJECT_ID }}
WATCH_VERCEL_PROJECT_ID: ${{ secrets.WATCH_VERCEL_PROJECT_ID }}
NEXT_PUBLIC_VERCEL_ENV: prod
NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
# use run-namy to avoid case where deploy command doesn't exist for a project
run: npx nx run-many --target=deploy --projects=${{ matrix.app }} --prod
- name: upload sourcemaps to datadog
env:
GIT_COMMIT_SHA: ${{ github.sha }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
run: npx nx run-many --target=upload-sourcemaps --projects=${{ matrix.app }}
- name: Generate GitHub comment
id: deployment-url
env:
APP: ${{ matrix.app }}
run: ./tools/scripts/generate-deployment-comment.sh
- id: get-comment-body
run: |
body="$(cat .github/deployment_comment.md)"
delimiter="$(openssl rand -hex 8)"
echo "body<<$delimiter" >> $GITHUB_OUTPUT
echo "$body" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- name: add deployment comment to commit
if: ${{ github.event_name != 'pull_request' }}
uses: peter-evans/commit-comment@v3
with:
body: ${{ steps.get-comment-body.outputs.body }}
- name: update deployment status
uses: chrnorm/deployment-status@v2
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
state: ${{ job.status }}
environment-url: ${{ steps.deployment-url.outputs.deployment-url }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}