-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwm.sh
executable file
·410 lines (367 loc) · 8.24 KB
/
wm.sh
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#!/bin/bash
wowmateDir=$(pwd)
presignDir="services/upload/presign"
frontendDir="services/frontend"
goDirs=(
"services/common/golib"
"services/api/combatlogs/keys/_combatlog_uuid/player-damage-done/get"
"services/api/combatlogs/keys/_dungeon_id/get"
"services/api/combatlogs/keys/index/get"
"services/upload/convert/normalize"
"services/upload/convert"
"services/upload/query-timestream/keys"
"services/upload/query-timestream/player-damage-done"
"services/upload/insert/dynamodb/keys"
"services/upload/insert/dynamodb/player-damage-done"
"services/upload/insert/timestream/keys"
)
start-lambda() {
build_go
build_cdk
cdk_synth
sam local start-lambda \
--template cdk.out/wm.template.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
local-api() {
build_go
build_cdk
cdk_synth
sam local start-api \
--template cdk.out/wm.template.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
get-keys-per-dungeon() {
build_go
build_cdk
cdk_synth
echo '{"pathParameters": {"dungeon_id": "2291"}}' | \
sam local invoke ApiGetKeysPerDungeonLambda073DE524 \
--template cdk.out/wm-dev.template.json \
--event - \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
insert-keys-to-dynamodb() {
build_go
build_cdk
cdk_synth
sam local invoke InsertKeysToDynamodbLambda15825024 \
--template cdk.out/wm-dev.template.json \
--event misc/insertPlayerDamageDoneToDynamodbEvent.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
get-keys() {
build_go
build_cdk
cdk_synth
sam local invoke ApiGetKeysLambdaFDF1A526 \
--no-event \
--template cdk.out/wm-dev.template.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
get-player-damage-done() {
build_go
build_cdk
cdk_synth
echo '{"pathParameters": {"combatlog_uuid": "fff28fa9-10fb-4018-9486-c1a1f748862d"}}' | \
sam local invoke ApiGetPlayerDamageDoneLambda7F052E98 \
--template cdk.out/wm-dev.template.json \
--event - \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
insert-player-damage-done() {
build_go
build_cdk
cdk_synth
sam local invoke InsertPlayerDamageDoneToDynamodbLambda659E0DA7 \
--template cdk.out/wm-dev.template.json \
--event misc/insertPlayerDamageDoneToDynamodbEvent.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
query-player-damage-done() {
build_go
build_cdk
cdk_synth
sam local invoke QueryPlayerDamageDoneLambda98AFC037 \
--template cdk.out/wm-dev.template.json \
--event misc/queryTimestreamInput.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
convert() {
build_go
build_cdk
cdk_synth
sam local invoke ConvertLambda3540DCCB \
--template cdk.out/wm-dev.template.json \
--event misc/convertInput.json \
--profile default \
--env-vars=misc/env.json \
|| exit 1
}
cdk_synth() {
npx cdk synth "wm-dev" -q || exit 1
}
# comments the diff on the current PR
# source https://github.com/youyo/aws-cdk-github-actions/blob/master/entrypoint.sh#L63
# won't work locally, but it's not supposed to be.
cdk_diff_prod() {
output=$(cdk_diff "wm" 2>&1)
exitCode=${?}
echo ::set-output name=status_code::${exitCode}
echo "${output}"
commentStatus="Failed"
if [ "${exitCode}" == "0" ]; then
commentStatus="Success"
elif [ "${exitCode}" != "0" ]; then
echo "CDK diff for stack wm has failed. See above console output for more details."
exit 1
fi
commentWrapper="
\`\`\`
${output}
\`\`\`
"
payload=$(echo "${commentWrapper}" | jq -R --slurp '{body: .}')
commentsURL=$(cat "${GITHUB_EVENT_PATH}" | jq -r .pull_request.comments_url)
echo "${payload}" | curl -s -S -H "Authorization: token ${GITHUB_TOKEN}" --header "Content-Type: application/json" --data @- "${commentsURL}" > /dev/null
}
cdk_deploy() {
npx cdk deploy --require-approval=never "$1" || exit 1
}
cdk_diff() {
npx cdk diff "$1" || exit 1
}
update_go() {
for i in "${goDirs[@]}"
do
cd "$wowmateDir" || exit 1
cd "$i" || exit 1
go get -u || exit 1
go mod tidy || exit 1
done
echo "go updated"
}
update_cdk() {
cd "$wowmateDir" || exit 1
npm update || exit 1
echo "cdk updated"
}
update_frontend() {
# echo "start frontend update"
cd "$wowmateDir" || exit 1
cd $frontendDir || exit 1
yarn upgrade || exit 1
echo "frontend updated"
}
update_presign() {
# echo "start presign update"
cd "$wowmateDir" || exit 1
cd $presignDir || exit 1
npm update || exit 1
echo "presign updated"
}
install_go() {
for i in "${goDirs[@]}"
do
cd "$wowmateDir" || exit 1
cd "$i" || exit 1
go get || exit 1
done
echo "go installed"
}
install_cdk() {
cd "$wowmateDir" || exit 1
npm ci || exit 1
echo "cdk installed"
}
install_frontend() {
# echo "start frontend install"
cd "$wowmateDir" || exit 1
cd "$frontendDir" || exit 1
yarn install || exit 1
echo "frontend installed"
}
install_presign() {
# echo "start presign install"
cd "$wowmateDir" || exit 1
cd "$presignDir" || exit 1
npm ci || exit 1
echo "presign installed"
}
lint_go() {
go get -u github.com/kisielk/errcheck || exit 1
go get -u honnef.co/go/tools/cmd/staticcheck || exit 1
for i in "${goDirs[@]}"
do
cd "$wowmateDir" || exit 1
cd "$i" || exit 1
diff -u <(echo -n) <(gofmt -d .) || exit 1
go vet || exit 1
errcheck || exit 1
# TODO: fix all problems
staticcheck # || exit 1
go test . || exit 1
done
echo "compiled go"
}
build_go() {
for i in "${goDirs[@]}"
do
cd "$wowmateDir" || exit 1
cd "$i" || exit 1
# build all binaries into the dist folder
path=$(pwd)
go build -ldflags='-s -w' -o "${path/services/dist}"/main . || exit 1
done
echo "compiled go"
}
build_cdk() {
cd "$wowmateDir" || exit 1
echo "start typescript compile"
npx tsc || exit 1 #compile cdk typescript
}
build_frontend() {
cd "$wowmateDir" || exit 1
cd "$frontendDir" || exit 1
yarn build || exit 1
echo "frontend built"
}
main() {
if [ "$1" == "build" ]
then
if [ "$2" == "frontend" ]
then
build_frontend
elif [ "$2" == "go" ]
then
build_go
elif [ "$2" == "cdk" ]
then
build_cdk
else
build_cdk
build_go
build_frontend
fi
elif [ "$1" == "install" ]
then
if [ "$2" == "frontend" ]
then
install_frontend
elif [ "$2" == "presign" ]
then
install_presign
elif [ "$2" == "go" ]
then
install_go
elif [ "$2" == "cdk" ]
then
install_cdk
else
install_cdk
install_go
install_frontend
fi
elif [ "$1" == "update" ]
then
if [ "$2" == "frontend" ]
then
update_frontend
elif [ "$2" == "presign" ]
then
update_presign
elif [ "$2" == "go" ]
then
update_go
elif [ "$2" == "cdk" ]
then
update_cdk
else
update_cdk
update_go
update_frontend
fi
elif [ "$1" == "deploy" ]
then
if [ "$2" == "prod" ]
then
cdk_diff "wm"
cdk_deploy "wm"
elif [ "$2" == "dev" ]
then
cdk_diff "wm-dev"
cdk_deploy "wm-dev"
elif [ "$2" == "preprod" ]
then
cdk_diff "wm-preprod"
cdk_deploy "wm-preprod"
fi
elif [ "$1" == "diff" ]
then
if [ "$2" == "prod" ]
then
cdk_diff_prod
elif [ "$2" == "dev" ]
then
cdk_diff "wm-dev"
fi
elif [ "$1" == "synth" ]
then
cdk_synth
fi
if [ "$1" == "lint" ]
then
if [ "$2" == "go" ]
then
lint_go
fi
elif [ "$1" == "start-lambda" ]
then
start-lambda
elif [ "$1" == "local-api" ]
then
local-api
# invoking lambdas locally
elif [ "$1" == "invoke" ]
then
if [ "$2" == "convert" ]
then
convert
elif [ "$2" == "query-player-damage-done" ]
then
query-player-damage-done
elif [ "$2" == "get-keys-per-dungeon" ]
then
get-keys-per-dungeon
elif [ "$2" == "insert-keys-to-dynamodb" ]
then
insert-keys-to-dynamodb
elif [ "$2" == "get-keys" ]
then
get-keys
elif [ "$2" == "get-player-damage-done" ]
then
get-player-damage-done
elif [ "$2" == "insert-player-damage-done" ]
then
insert-player-damage-done
fi
fi
}
main "$@" || exit 1