-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.yml
469 lines (440 loc) · 17.6 KB
/
action.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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
name: 'Deploy Cloud Commerce to Firebase'
description: 'A GitHub Action to deploy https://github.com/ecomplus/cloud-commerce store to Firebase'
inputs:
github-token:
description: 'The `GITHUB_TOKEN` secret'
required: true
github-persistent-token:
description: 'Long life token for GitHub API'
firebase-service-account:
description: 'Firebase service account JSON'
required: true
ecom-authentication-id:
description: 'E-Com Plus store authentication ID'
required: true
ecom-api-key:
description: 'E-Com Plus store API key'
required: true
ecom-store-id:
description: 'Store ID if not defined in config.json'
deploy-codebase:
description: 'Specific Firebase Functions codebase for partial deploy'
mail-sender:
description: 'Emails: sender email (default from settings contact email)'
mail-sender-name:
description: 'Emails: sender name (default is store name)'
mail-reply-to:
description: 'Emails: Reply email'
smtp-host:
description: 'Emails: SMTP hostname'
smtp-port:
description: 'Emails: SMTP port number'
smtp-user:
description: 'Emails: SMTP username'
smtp-pass:
description: 'Emails: SMTP password'
passport-unverified-auth:
description: 'Set `true` to pass simpler customer login without email verification'
bunnynet-api-key:
description: 'bunny.net API key (additional CDN layer)'
sendgrid-api-key:
description: 'App: SendGrid API key'
tinyerp-token:
description: 'App: Tiny ERP API token'
galaxpay-partner-id:
description: 'App: Optional Galax Pay partner ID'
galaxpay-partner-hash:
description: 'App: Optional Galax Pay partner hash'
datafrete-operator-token:
description: 'App: Random token (https://randomkeygen.com/) to validate Datafrete webhooks'
mercadopago-token:
description: 'App: Mercadopago API access token'
frenet-token:
description: 'App: Frenet API token'
galaxpay-id:
description: 'App: Galax Pay ID'
galaxpay-hash:
description: 'App: Galax Pay hash'
ga-measurement-id:
description: 'App: Google Analytics API measurement id'
ga-api-secret:
description: 'App: Google Analytics API secret'
infinitepay-id:
description: 'App: InifinitePay client ID'
infinitepay-secret:
description: 'App: InifinitePay client secret'
fb-pixel-id:
description: 'App: Facebook pixel ID'
fb-graph-token:
description: 'App: Facebook Graph token'
jadlog-contract-token:
description: 'App: Jadlog contract token'
pagarme-encrypt-key:
description: 'App: Pagar.me encryption Key'
pagarme-token:
description: 'App: Pagar.me API token'
pagarme-partner-id:
description: 'App: Pagar.me partner ID'
paghiper-token:
description: 'App: PagHiper API token'
pix-credentials:
description: 'App: Pix credentials'
flashcourier-contract:
description: 'App: Flash Courier contract'
webhooks-token:
description: 'App: Webhooks token'
mandae-token:
description: 'App: Mandaê token'
correios-user:
description: 'App: Correios username'
correios-access-code:
description: 'App: Correios access code'
correios-postcard-number:
description: 'App: Optional Correios postcard number'
pagarmev5-api-token:
description: 'App: Pagar.me API V5 token'
pagarmev5-public-key:
description: 'App: Pagar.me API V5 public key'
tiktok-pixel-id:
description: 'App: Tiktok pixel ID'
tiktok-access-token:
description: 'App: Tiktok access token'
custom-dotenv:
description: 'Raw `.env` file content to set additional env vars'
outputs: {}
runs:
using: "composite"
steps:
- shell: bash
run: echo "year=$(date +'%Y')" >> $GITHUB_ENV
- if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: ouzi-dev/[email protected]
continue-on-error: true
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: actions/cache@v4
id: npm-cache-root
with:
path: node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
- if: steps.npm-cache-root.outputs.cache-hit != 'true'
shell: bash
run: npm ci --omit=dev --ignore-scripts
- name: Get npm global directories
id: npm-paths
shell: bash
run: |
lib_path=$(npm list -g | head -1)
echo "LIB_PATH=$lib_path" >> $GITHUB_OUTPUT
echo "BIN_PATH=${lib_path/\/lib//bin}" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: npm-g-cache
with:
path: |
${{ steps.npm-paths.outputs.LIB_PATH }}
${{ steps.npm-paths.outputs.BIN_PATH }}
~/.npm-global/bin
key: ${{ runner.os }}-npm-g-firebase-tools-13.28.0
- if: github.event_name == 'push' && steps.npm-g-cache.outputs.cache-hit != 'true'
shell: bash
run: npm i --location=global [email protected]
- if: github.event_name == 'push'
uses: dorny/[email protected]
id: changes
with:
filters: |
many:
- 'functions/many/**'
withApps:
- 'functions/with-apps/**'
ssr:
- 'functions/ssr/**'
- if: github.event_name == 'push'
name: Check functions codebase to deploy
shell: bash
env:
DEPLOY_CODEBASE: ${{ inputs.deploy-codebase }}
CHS_MANY: ${{ steps.changes.outputs.many }}
CHS_WITH_APPS: ${{ steps.changes.outputs.withApps }}
CHS_SSR: ${{ steps.changes.outputs.ssr }}
run: |
if [ -z "$DEPLOY_CODEBASE" ]; then
if [ $CHS_SSR == 'true' ]; then
if [ $CHS_MANY != 'true' ] && [ $CHS_WITH_APPS != 'true' ]; then
deploy_codebase="ssr"
fi
elif [ $CHS_MANY == 'true' ] && [ $CHS_WITH_APPS != 'true' ]; then
deploy_codebase="many"
elif [ $CHS_MANY != 'true' ] && [ $CHS_WITH_APPS == 'true' ]; then
deploy_codebase="with-apps"
fi
else
deploy_codebase=$DEPLOY_CODEBASE
fi
echo "deploy_codebase=$deploy_codebase" >> $GITHUB_ENV
- if: github.event_name == 'pull_request'
shell: bash
run: echo "deploy_codebase=ssr" >> $GITHUB_ENV
- if: env.deploy_codebase == '' || env.deploy_codebase == 'many'
uses: actions/cache@v4
id: npm-cache-many
with:
path: functions/many/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('functions/many/package-lock.json') }}
- if: env.deploy_codebase == '' || env.deploy_codebase == 'ssr'
uses: actions/cache@v4
id: npm-cache-ssr
with:
path: functions/ssr/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('functions/ssr/package-lock.json') }}
- if: env.deploy_codebase == '' || env.deploy_codebase == 'ssr'
uses: actions/cache@v4
with:
path: functions/ssr/.cache
key: ${{ runner.os }}-${{ env.year }}-sf-${{ hashFiles('functions/ssr/public/**/*') }}
- if: env.deploy_codebase == '' || env.deploy_codebase == 'with-apps'
uses: actions/cache@v4
id: npm-cache-with-apps
with:
path: functions/with-apps/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('functions/with-apps/package-lock.json') }}
- if: |
(env.deploy_codebase == '' || env.deploy_codebase == 'many')
&& steps.npm-cache-many.outputs.cache-hit != 'true'
name: Install codebase "many" dependencies
shell: bash
working-directory: functions/many
run: npm ci
- if: |
(env.deploy_codebase == '' || env.deploy_codebase == 'ssr')
&& steps.npm-cache-ssr.outputs.cache-hit != 'true'
name: Install codebase "ssr" dependencies
shell: bash
working-directory: functions/ssr
run: npm ci
- if: |
(env.deploy_codebase == '' || env.deploy_codebase == 'with-apps')
&& steps.npm-cache-with-apps.outputs.cache-hit != 'true'
name: Install codebase "with-apps" dependencies
shell: bash
working-directory: functions/with-apps
run: npm ci
- name: Set ecom_store_id and git_branch env
shell: bash
working-directory: functions
env:
ECOM_STORE_ID: ${{ inputs.ecom-store-id }}
run: |
echo "ecom_store_id=${ECOM_STORE_ID:-$(cat config.json | jq -r '.storeId')}" >> $GITHUB_ENV
echo "git_branch=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV
- if: github.event_name == 'push'
name: Deploy to Firebase live
shell: bash
env:
ECOM_STORE_ID: ${{ env.ecom_store_id }}
GIT_BRANCH: ${{ env.git_branch }}
DEPLOY_CODEBASE: ${{ env.deploy_codebase }}
GITHUB_REPO: ${{ github.event.repository.full_name }}
GITHUB_TOKEN: ${{ inputs.github-persistent-token || inputs.github-token }}
FIREBASE_SERVICE_ACCOUNT: ${{ inputs.firebase-service-account }}
ECOM_AUTHENTICATION_ID: ${{ inputs.ecom-authentication-id }}
ECOM_API_KEY: ${{ inputs.ecom-api-key }}
MAIL_SENDER: ${{ inputs.mail-sender }}
MAIL_SENDER_NAME: ${{ inputs.mail-sender-name }}
MAIL_REPLY_TO: ${{ inputs.mail-reply-to }}
SMTP_HOST: ${{ inputs.smtp-host }}
SMTP_PORT: ${{ inputs.smtp-port }}
SMTP_USER: ${{ inputs.smtp-user }}
SMTP_PASS: ${{ inputs.smtp-pass }}
PASSPORT_UNVERIFIED_AUTH: ${{ inputs.passport-unverified-auth }}
BUNNYNET_API_KEY: ${{ inputs.bunnynet-api-key }}
SENDGRID_API_KEY: ${{ inputs.sendgrid-api-key }}
TINYERP_TOKEN: ${{ inputs.tinyerp-token }}
GALAXPAY_PARTNER_ID: ${{ inputs.galaxpay-partner-id }}
GALAXPAY_PARTNER_HASH: ${{ inputs.galaxpay-partner-hash }}
DATAFRETE_OPERATOR_TOKEN: ${{ inputs.datafrete-operator-token }}
MERCADOPAGO_TOKEN: ${{ inputs.mercadopago-token }}
FRENET_TOKEN: ${{ inputs.frenet-token }}
GALAXPAY_ID: ${{ inputs.galaxpay-id }}
GALAXPAY_HASH: ${{ inputs.galaxpay-hash }}
GA_MEASUREMENT_ID: ${{ inputs.ga-measurement-id }}
GA_API_SECRET: ${{ inputs.ga-api-secret }}
FB_PIXEL_ID: ${{ inputs.fb-pixel-id }}
FB_GRAPH_TOKEN: ${{ inputs.fb-graph-token }}
JADLOG_CONTRACT_TOKEN: ${{ inputs.jadlog-contract-token }}
PAGARME_ENCRYPT_KEY: ${{ inputs.pagarme-encrypt-key }}
PAGARME_TOKEN: ${{ inputs.pagarme-token }}
PAGARME_PARTNER_ID: ${{ inputs.pagarme-partner-id }}
PAGHIPER_TOKEN: ${{ inputs.paghiper-token }}
PIX_CREDENTIALS: ${{ inputs.pix-credentials }}
FLASHCOURIER_CONTRACT: ${{ inputs.flashcourier-contract }}
WEBHOOKS_TOKEN: ${{ inputs.webhooks-token }}
MANDAE_TOKEN: ${{ inputs.mandae-token }}
CORREIOS_USER: ${{ inputs.correios-user }}
CORREIOS_ACCESS_CODE: ${{ inputs.correios-access-code }}
CORREIOS_POSTCARD: ${{ inputs.correios-postcard-number }}
PAGARMEV5_API_TOKEN: ${{ inputs.pagarmev5-api-token }}
PAGARMEV5_PUBLIC_KEY: ${{ inputs.pagarmev5-public-key }}
TIKTOK_ACCESS_TOKEN: ${{ inputs.tiktok-access-token }}
TIKTOK_PIXEL_ID: ${{ inputs.tiktok-pixel-id }}
CUSTOM_DOTENV: ${{ inputs.custom-dotenv }}
run: |
export GAC_FILENAME=".gac-$RANDOM.json"
echo $FIREBASE_SERVICE_ACCOUNT > $GAC_FILENAME
printf "DEPLOY_RAND=$RANDOM$RANDOM
ECOM_AUTHENTICATION_ID=$ECOM_AUTHENTICATION_ID
ECOM_API_KEY=$ECOM_API_KEY
ECOM_STORE_ID=$ECOM_STORE_ID
GIT_BRANCH=$GIT_BRANCH
GITHUB_REPO=$GITHUB_REPO
GITHUB_TOKEN=$GITHUB_TOKEN
DEPLOY_CODEBASE=$DEPLOY_CODEBASE
MAIL_SENDER=$MAIL_SENDER
MAIL_SENDER_NAME=$MAIL_SENDER_NAME
MAIL_REPLY_TO=$MAIL_REPLY_TO
SMTP_HOST=$SMTP_HOST
SMTP_PORT=$SMTP_PORT
SMTP_USER=$SMTP_USER
SMTP_PASS=$SMTP_PASS
PASSPORT_UNVERIFIED_AUTH=$PASSPORT_UNVERIFIED_AUTH
BUNNYNET_API_KEY=$BUNNYNET_API_KEY
SENDGRID_API_KEY=$SENDGRID_API_KEY
TINYERP_TOKEN=$TINYERP_TOKEN
GALAXPAY_PARTNER_ID=$GALAXPAY_PARTNER_ID
GALAXPAY_PARTNER_HASH=$GALAXPAY_PARTNER_HASH
DATAFRETE_OPERATOR_TOKEN=$DATAFRETE_OPERATOR_TOKEN
MERCADOPAGO_TOKEN=$MERCADOPAGO_TOKEN
FRENET_TOKEN=$FRENET_TOKEN
GALAXPAY_ID=$GALAXPAY_ID
GALAXPAY_HASH=$GALAXPAY_HASH
GA_MEASUREMENT_ID=$GA_MEASUREMENT_ID
GA_API_SECRET=$GA_API_SECRET
FB_PIXEL_ID=$FB_PIXEL_ID
FB_GRAPH_TOKEN=$FB_GRAPH_TOKEN
JADLOG_CONTRACT_TOKEN=$JADLOG_CONTRACT_TOKEN
PAGARME_ENCRYPT_KEY=$PAGARME_ENCRYP_KEY
PAGARME_TOKEN=$PAGARME_TOKEN
PAGARME_PARTNER_ID=$PAGARME_PARTNER_ID
PAGHIPER_TOKEN=$PAGHIPER_TOKEN
PIX_CREDENTIALS=$PIX_CREDENTIALS
FLASHCOURIER_CONTRACT=$FLASHCOURIER_CONTRACT
WEBHOOKS_TOKEN=$WEBHOOKS_TOKEN
MANDAE_TOKEN=$MANDAE_TOKEN
CORREIOS_USER=$CORREIOS_USER
CORREIOS_ACCESS_CODE=$CORREIOS_ACCESS_CODE
CORREIOS_POSTCARD=$CORREIOS_POSTCARD
PAGARMEV5_API_TOKEN=$PAGARMEV5_API_TOKEN
PAGARMEV5_PUBLIC_KEY=$PAGARMEV5_PUBLIC_KEY
TIKTOK_ACCESS_TOKEN=$TIKTOK_ACCESS_TOKEN
TIKTOK_PIXEL_ID=$TIKTOK_PIXEL_ID
" > functions/.env
if [[ -n "$CUSTOM_DOTENV" ]]; then
echo "$CUSTOM_DOTENV" >> functions/.env
fi
if [ -z "$DEPLOY_CODEBASE" ]; then
BUNNYNET_API_KEY=$BUNNYNET_API_KEY \
GOOGLE_APPLICATION_CREDENTIALS=$GAC_FILENAME \
npm run deploy
else
if [ $DEPLOY_CODEBASE == "ssr" ]; then
BUNNYNET_API_KEY=$BUNNYNET_API_KEY \
GOOGLE_APPLICATION_CREDENTIALS=$GAC_FILENAME \
npm run deploy -- --only functions:$DEPLOY_CODEBASE,hosting
else
GOOGLE_APPLICATION_CREDENTIALS=$GAC_FILENAME \
npm run deploy -- --only functions:$DEPLOY_CODEBASE
fi
fi
- if: github.event_name == 'push' && contains(github.event.head_commit.message, '[run:')
name: Run script from `@cloudcommerce/cli/ci/`
shell: bash
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
ECOM_STORE_ID: ${{ env.ecom_store_id }}
GIT_BRANCH: ${{ env.git_branch }}
FIREBASE_SERVICE_ACCOUNT: ${{ inputs.firebase-service-account }}
BUNNYNET_API_KEY: ${{ inputs.bunnynet-api-key }}
run: |
if [ -n "$BUNNYNET_API_KEY" ]; then
script_name="${COMMIT_MSG#*\[run:}"
script_name="${script_name%%\]*}"
project_id=$(echo "$FIREBASE_SERVICE_ACCOUNT" | jq -r .project_id 2>/dev/null)
domain=$(cat functions/ssr/content/settings.json | jq -r '.domain')
bash $GITHUB_ACTION_PATH/packages/cli/ci/$script_name.sh $project_id $domain
fi
- if: github.event_name == 'pull_request' && github.event.action != 'closed'
name: Build storefront static
shell: bash
env:
ECOM_STORE_ID: ${{ env.ecom_store_id }}
run: |
printf "DEPLOY_RAND=$RANDOM$RANDOM
ECOM_STORE_ID=$ECOM_STORE_ID
" > functions/ssr/.env
if [ ! -f ".firebaserc" ]; then
echo '{ "projects": { "default": "ecom2-demo" } }' > .firebaserc
fi
npm --prefix "functions/ssr/" run build:static && npx cloudcommerce prepare
- if: |
github.event_name == 'pull_request' && github.event.action != 'closed'
&& env.git_branch != 'main'
name: Deploy Firebase Hosting PR preview
id: deploy-preview
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ inputs.github-token }}
firebaseServiceAccount: ${{ inputs.firebase-service-account }}
channelId: ${{ (startsWith(env.git_branch, 'main-') && env.git_branch) || null }}
expires: ${{ (startsWith(env.git_branch, 'main-') && '30d') || null }}
- if: |
github.event_name == 'pull_request' && github.event.action != 'closed'
&& env.git_branch != 'main'
uses: ouzi-dev/[email protected]
continue-on-error: true
with:
status: ${{ (steps.deploy-preview.outputs.details_url && 'success') || 'failure' }}
url: ${{ steps.deploy-preview.outputs.details_url }}
description: "Deploy preview URL"
- if: |
github.event_name == 'pull_request' && github.event.action != 'closed'
&& env.git_branch == 'main'
uses: ouzi-dev/[email protected]
continue-on-error: true
with:
status: cancelled
- if: |
github.event_name == 'pull_request' && github.event.action != 'closed'
&& startsWith(env.git_branch, 'main-')
name: Prepare bunny.net CDN for A/B testing
shell: bash
env:
ECOM_STORE_ID: ${{ env.ecom_store_id }}
GIT_BRANCH: ${{ env.git_branch }}
BUNNYNET_API_KEY: ${{ inputs.bunnynet-api-key }}
CHANNEL_URL: ${{ steps.deploy-preview.outputs.details_url }}
run: |
if [ -n "$BUNNYNET_API_KEY" ]; then
domain=$(cat functions/ssr/content/settings.json | jq -r '.domain')
if [ -n "$domain" ]; then
bash $GITHUB_ACTION_PATH/packages/cli/ci/bunny-prepare-ab.sh 1 $domain $CHANNEL_URL
fi
fi
- if: |
github.event_name == 'pull_request' && github.event.action == 'closed'
&& startsWith(env.git_branch, 'main-')
name: Clear A/B testing config on bunny.net CDN
shell: bash
env:
ECOM_STORE_ID: ${{ env.ecom_store_id }}
GIT_BRANCH: ${{ env.git_branch }}
BUNNYNET_API_KEY: ${{ inputs.bunnynet-api-key }}
run: |
if [ -n "$BUNNYNET_API_KEY" ]; then
domain=$(cat functions/ssr/content/settings.json | jq -r '.domain')
if [ -n "$domain" ]; then
bash $GITHUB_ACTION_PATH/packages/cli/ci/bunny-remove-ab.sh 1 $domain
fi
fi