-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
562 lines (521 loc) · 29.5 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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
name: 'Snap Publish'
description: 'Publish a Snap integration to AWS S3'
inputs:
repository:
description: 'Repository of Snap implementation to publish'
required: true
branch:
description: 'Repository branch (ref) to run action in (used for testing)'
required: false
secretKey:
description: 'Searchspring account secretKey. Can be obtained in the Searchspring Management Console. Required if package.json siteId is string format'
required: false
skipTests:
description: 'Skip running e2e tests'
required: false
default: false
skipLighthouse:
description: 'Skip running lighthouse tests'
required: false
default: false
skipPublish:
description: 'Skip publishing to cdn'
required: false
default: false
NODE_AUTH_TOKEN:
description: 'Node auth token'
required: false
aws-access-key-id:
description: 'AWS access Key'
required: false
aws-secret-access-key:
description: 'AWS secret Key'
required: false
aws-cloudfront-distribution-id:
description: 'AWS cloudfront distribution id'
required: false
aws-s3-bucket-name:
description: 'AWS S3 bucket name'
required: false
aws-region:
description: 'AWS region'
required: false
default: us-east-2
LHCI_GITHUB_APP_TOKEN:
description: 'Lighthouse App Key for PR status updates'
required: false
GITHUB_BOT_TOKEN:
description: 'Github user PAT token for posting lighthouse results in pull request comments and pushing tags'
required: false
secrets:
description: 'Secrets encoded via toJSON. Expected if project has multiple siteIds in package.json. Expects repository secret for each key (ie. `WEBSITE_SECRET_KEY_${siteId}`)'
required: false
skipInvalidation:
description: 'Skip Cloudfront invalidation'
required: false
default: false
testing:
description: 'Used for development testing purposes only!'
required: false
default: false
runs:
using: "composite"
steps:
- name: Checkout Repository
id: checkout-repo
uses: actions/checkout@v2
with:
token: ${{ github.ref_name == 'production' && inputs.GITHUB_BOT_TOKEN || github.token }}
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
path: repository
fetch-depth: 0
- name: Setup Node
id: setup-node
uses: actions/setup-node@v2
with:
node-version: 20
- name: Extract Variables
id: variables
shell: bash
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Extract Variables'
echo "Action trigger: ${{ github.event_name }}";
if [ "${{ inputs.branch }}" != "" ]; then
branch=`echo "${{ inputs.branch }}"`;
elif [ "${{ github.event_name }}" = "pull_request" ]; then
branch=`echo "${{ github.head_ref }}"`;
else
branch=`echo ${GITHUB_REF#refs/heads/}`;
fi;
echo "::set-output name=branch::$branch";
echo "Using branch: $branch";
# validate branch name here
if [[ $branch =~ ^[0-9]+\.[0-9]+\.[0-9]+-?[0-9]*$ ]]; then
echo "Branch name is reserved. Please do not use sem versioning for branch name.";
exit 1;
fi;
secrets=`echo '${{ inputs.secrets }}' | jq -c .`;
echo "::set-output name=secrets::$secrets";
echo "Using secrets: $secrets";
siteId_Type=`jq -r '.searchspring.siteId | type' < package.json`;
echo "::set-output name=siteId_Type::$siteId_Type";
packageJSONVersion=`jq -r '.searchspring.version' < package.json`;
echo "::set-output name=packageJSONVersion::$packageJSONVersion";
if [ $siteId_Type = 'string' ]; then \
echo "siteId is a string"; \
siteId=`jq -r '.searchspring.siteId' < package.json`; \
echo "::set-output name=siteId::$siteId"; \
echo "Using siteId: $siteId"; \
elif [ $siteId_Type = 'object' ]; then \
echo "siteId is an object"; \
siteIds=`jq -r '.searchspring.siteId | keys_unsorted | join(",")' < package.json`; \
echo "::set-output name=siteIds::$siteIds"; \
echo "Using siteIds: $siteIds"; \
siteNames=`jq -r '[.searchspring.siteId[].name] | join(",")' < package.json`; \
echo "::set-output name=siteNames::$siteNames"; \
echo "Using siteNames: $siteNames"; \
# also set siteId to the first siteId in object format
siteId=`jq -r '.searchspring.siteId | keys_unsorted | first' < package.json`; \
echo "::set-output name=siteId::$siteId"; \
echo "Using siteId: $siteId"; \
else \
echo "Cannot determine project siteId from package.json"; \
exit 1; \
fi;
pullRequestID=${{ github.event.pull_request.number }}
echo "::set-output name=pullRequestID::$pullRequestID"
echo "Using pullRequestID: $pullRequestID"
repository=`git config --get remote.origin.url | grep -Eo "[^\/]+$" | sed 's/\.git$//g'`
echo "::set-output name=repository::$repository"
echo "Using repository: $repository"
startTime=`date -u +%s`
echo "::set-output name=startTime::$startTime"
echo "Using startTime: $startTime"
awsCreds='${{ inputs.aws-access-key-id && inputs.aws-secret-access-key && inputs.aws-cloudfront-distribution-id && inputs.aws-s3-bucket-name }}'
echo "::set-output name=awsCreds::$awsCreds";
echo "Using awsCreds: $awsCreds"
isSelfHosted=${{ (startsWith(github.head_ref, 'updater/patch/') || startsWith(github.ref_name, 'updater/patch/') || startsWith(github.head_ref, 'updater/revert/') || startsWith(github.ref_name, 'updater/revert/') || (github.ref_name == github.event.repository.master_branch && (contains(github.event.head_commit.message,'from searchspring-implementations/updater/patch/') || contains(github.event.head_commit.message,'from searchspring-implementations/updater/revert/')))) && 'true' || 'false' }}
echo "::set-output name=isSelfHosted::$isSelfHosted";
echo "Using isSelfHosted: $isSelfHosted"
- name: Configure AWS credentials
id: configure-aws
if: ${{ steps.variables.outputs.awsCreds }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-region: ${{ inputs.aws-region }}
- name: Updater Start Metrics
id: start-metrics
if: ${{ steps.variables.outputs.isSelfHosted == 'true' }}
shell: bash
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
# Start time metric used in snapp-updater action status, Should only run on self-hosted
node scripts/metrics/updater.js \
--runAttempt "${{ github.run_attempt }}" \
--actor "${{ github.actor }}" \
--repository "${{ steps.variables.outputs.repository }}" \
--branch "${{ steps.variables.outputs.branch }}" \
--eventName "${{ github.event_name }}" \
--pullRequestID "${{ github.event.pull_request.number }}" \
--startTime "${{ steps.variables.outputs.startTime }}" \
--conclusion "" \
--duration "" \
--failedStep "" \
--commitMessage "$COMMIT_MESSAGE" \
--url "https://github.com/${{ github.repository_owner }}/${{ steps.variables.outputs.repository }}/actions/runs/${{ github.run_id }}" \
--secrets-ci '${{ steps.variables.outputs.secrets }}';
- name: Cache node_modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json', '**/package.json') }}
- name: Authenticate siteId and secretKey
id: authenticate
shell: bash
run: |
node scripts/utils/logStep.js --step 'Authenticate siteId and secretKey'
node scripts/smc/verify.js \
--siteId_Type "${{ steps.variables.outputs.siteId_Type }}" \
--siteId "${{ steps.variables.outputs.siteId }}" \
--repository "${{ steps.variables.outputs.repository }}" \
--secretKey "${{ inputs.secretKey }}" \
--siteIds "${{ steps.variables.outputs.siteIds }}" \
--siteNames "${{ steps.variables.outputs.siteNames }}" \
--secrets-ci '${{ steps.variables.outputs.secrets }}';
- name: Install Packages
id: install
shell: bash
working-directory: repository
env:
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
run: |
node ../scripts/utils/logStep.js --step 'Install Packages'
if [ '${{ steps.variables.outputs.isSelfHosted }}' == 'true' ]; then
# npm install instead of ci for updater runs - ci requires package.json and package-lock.json to be in sync
npm install --prefer-offline
else
if [ -f "package-lock.json" ]; then
npm ci --prefer-offline
else
npm install --prefer-offline
fi
fi;
- name: Build Bundle
id: build
shell: bash
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Build Bundle'
npm run build
if [ ! -f "dist/bundle.js" ]; then \
echo "Expected dist directory to contain bundle.js and universal.bundle.js"; \
echo "Missing dist/bundle.js"; \
exit 1; \
elif [ ! -f "dist/universal.bundle.js" ]; then \
echo "Expected dist directory to contain bundle.js and universal.bundle.js"; \
echo "Missing dist/universal.bundle.js"; \
exit 1; \
fi;
- name: Run Tests
id: test
if: github.event_name == 'push' && github.ref_name != 'production'
shell: bash
working-directory: repository
env:
CYPRESS_VERIFY_TIMEOUT: 60000
run: |
node ../scripts/utils/logStep.js --step 'Run Tests'
if [ ${{ inputs.skipTests }} = true ]; then
echo 'skipping tests due to skipTests flag';
else
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc;
npm run test;
fi;
- name: Snapfu Recs Sync
id: snapfu-recs-sync
shell: bash
if: steps.variables.outputs.branch == 'production' && steps.variables.outputs.isSelfHosted == 'false'
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Snapfu Recs Sync'
npm install -g snapfu
snapfu recs sync \
--secret-key "${{ inputs.secretKey }}" \
--secrets-ci '${{ steps.variables.outputs.secrets }}';
- name: Snapfu Badges Sync
id: snapfu-badges-sync
shell: bash
if: steps.variables.outputs.branch == 'production' && steps.variables.outputs.isSelfHosted == 'false'
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Snapfu Badges Sync'
snapfu badges sync \
--secret-key "${{ inputs.secretKey }}" \
--secrets-ci '${{ steps.variables.outputs.secrets }}';
- name: Lighthouse Tests
id: lighthouse
if: github.event_name == 'pull_request'
shell: bash
working-directory: repository
env:
LHCI_GITHUB_APP_TOKEN: ${{ inputs.LHCI_GITHUB_APP_TOKEN }}
run: |
node ../scripts/utils/logStep.js --step 'Lighthouse Tests'
if [ ${{ inputs.skipLighthouse }} = true ]; then \
echo 'skipping lighthouse tests'; \
elif [ -f "tests/lighthouse/lighthouserc.js" ]; then \
npm run lighthouse -- --throttling.cpuSlowdownMultiplier=2.2 && \
echo "::set-output name=scores::$(cat tests/lighthouse/runs/manifest.json | jq -c '.[] | select( .isRepresentativeRun | select('true') ) | .summary' | jq -r 'to_entries[] | "\(.key): \(.value | tonumber * 100 | floor )"' | tr '\n' ',' )" && \
echo "::set-output name=report::$(cat tests/lighthouse/runs/manifest.json | jq -c '.[] | select( .isRepresentativeRun | select('true') ) | .htmlPath')" || exit 1; \
else \
echo 'lighthouserc.js file not found in repository, skipping lighthouse tests'; \
fi
- name: Git Tag
id: tag
if: ${{ contains(steps.variables.outputs.packageJSONVersion, '.') && steps.variables.outputs.branch == 'production' && github.event_name == 'push' }}
shell: bash
working-directory: repository
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
node ../scripts/utils/logStep.js --step 'Git Tag'
git config user.name searchspring-machine
git config user.email [email protected]
if [ $(git tag -l "${{ steps.variables.outputs.packageJSONVersion }}") ]; then
# tag exist, use scripts/tag/increment.js to bump/add suffix version
echo "Tag ${{ steps.variables.outputs.packageJSONVersion }} already exists."
newTag=$(node ./../scripts/tag/increment.js --tags "$(git tag -l '${{ steps.variables.outputs.packageJSONVersion }}*')")
if [ "${{ steps.variables.outputs.packageJSONVersion }}" != "$newTag" ]; then
echo "Creating tag $newTag"
git tag -a "$newTag" -m "tagged from snap-action"
git push origin $newTag
tag=`echo "$newTag"`;
echo "::set-output name=tag::$tag";
fi
elif [ "${{ steps.variables.outputs.packageJSONVersion }}" != "" ]; then
# tag doesn't exist, create it from the package.json searchspring.version
git tag -a "${{ steps.variables.outputs.packageJSONVersion }}" -m "tagged from snap-action"
git push origin ${{ steps.variables.outputs.packageJSONVersion }}
tag=`echo "${{ steps.variables.outputs.packageJSONVersion }}"`;
echo "::set-output name=tag::$tag";
fi
if [ "${{ contains(github.event.head_commit.message,'from searchspring-implementations/updater/revert/') }}" == "true" ]; then
tagToDelete=$(node ./../scripts/tag/getTag.js --tags "$(git tag -l)" --commitMessage "$COMMIT_MESSAGE")
git push --delete origin $tagToDelete
fi
- name: PR Comment
id: pr-comment
if: steps.lighthouse.outputs.scores && steps.variables.outputs.isSelfHosted == 'false'
uses: actions/github-script@v5
with:
github-token: ${{ inputs.GITHUB_BOT_TOKEN || github.token }}
script: |
if (!${{ inputs.testing }}) {
github.rest.issues.createComment({
issue_number: ${{ steps.variables.outputs.pullRequestID || 0 }},
owner: context.repo.owner,
repo: context.repo.repo,
body: "Lighthouse <a target='_blank' rel='noopener' href='https://snapui.searchspring.io/${{ steps.variables.outputs.siteId }}/.lighthouse/${{ steps.variables.outputs.branch }}/" + ${{ steps.lighthouse.outputs.report || '""' }}.split('/').pop() + "'>Results</a>\n\n${{ steps.lighthouse.outputs.scores }}".split(',').join('\n')
});
} else {
console.log('skipping PR Comment due to testing')
}
- name: Lighthouse Metrics
id: lighthouse-metrics
if: ${{ steps.variables.outputs.awsCreds }}
shell: bash
run: |
node scripts/utils/logStep.js --step 'Lighthouse Metrics'
if [ ${{ inputs.skipLighthouse }} = false ]; then \
if [ "${{ github.event_name }}" = "pull_request" ]; then \
if [ -f "tests/lighthouse/lighthouserc.js" ]; then \
node scripts/metrics/lighthouse.js \
--siteId "${{ steps.variables.outputs.siteId }}" \
--branch "${{ steps.variables.outputs.branch }}" \
--repositoryOwner "${{ github.repository_owner }}" \
--repository "${{ steps.variables.outputs.repository }}" \
--issueNumber "${{ steps.variables.outputs.pullRequestID }}";
else \
echo 'lighthouserc.js file not found in repository, skipping lighthouse metrics'; \
fi; \
else \
echo "Skipping lighthouse metrics generation due to non pull_request event"; \
fi;
else \
echo "skipping lighthouse metrics generation due to skipLighthouse flag"; \
fi;
if [ -f metrics/SnapAction*.json ]; then \
aws s3 cp --region us-east-1 ./metrics/SnapAction*.json s3://datawarehouse-stage/team-metrics-import/; \
fi;
- name: Copy Files to S3
id: s3-upload
if: ${{ steps.variables.outputs.awsCreds }}
shell: bash
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Copy Files to S3'
if [ ${{ inputs.skipPublish }} = true ]; then
echo "skipping upload of 'dist' and 'public' directories to S3 due to skipPublish flag";
elif [ "${{ github.event_name }}" = "pull_request" ]; then \
echo "skipping upload of 'dist' and 'public' directories to S3 for pull_request action triggers"; \
if [ -f tests/lighthouse/runs/manifest.json ]; then aws s3 sync --cache-control max-age=1800 --acl public-read tests/lighthouse/runs s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/.lighthouse/${{ steps.variables.outputs.branch }}; fi; \
else \
if [ '${{ steps.variables.outputs.siteId_Type }}' = 'string' ]; then \
aws s3 sync --cache-control max-age=1800 --acl public-read dist s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/${{ steps.variables.outputs.branch }}
aws s3 sync --cache-control max-age=1800 --acl public-read public s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/${{ steps.variables.outputs.branch }}
if [ "${{ steps.tag.outputs.tag }}" != "" ]; then
aws s3 sync --cache-control max-age=1800 --acl public-read dist s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/${{ steps.tag.outputs.tag }}
aws s3 sync --cache-control max-age=1800 --acl public-read public s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/${{ steps.tag.outputs.tag }}
fi
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'object' ]; then
echo "${{ steps.variables.outputs.siteIds }}" | tr , '\n' | while read siteId
do
echo "Copying files to S3 for siteId $siteId"
aws s3 sync --cache-control max-age=1800 --acl public-read dist s3://${{ inputs.aws-s3-bucket-name }}/$siteId/${{ steps.variables.outputs.branch }}
aws s3 sync --cache-control max-age=1800 --acl public-read public s3://${{ inputs.aws-s3-bucket-name }}/$siteId/${{ steps.variables.outputs.branch }}
if [ "${{ steps.tag.outputs.tag }}" != "" ]; then
aws s3 sync --cache-control max-age=1800 --acl public-read dist s3://${{ inputs.aws-s3-bucket-name }}/$siteId/${{ steps.tag.outputs.tag }}
aws s3 sync --cache-control max-age=1800 --acl public-read public s3://${{ inputs.aws-s3-bucket-name }}/$siteId/${{ steps.tag.outputs.tag }}
fi
done;
fi;
fi;
- name: Invalidate Files
id: invalidation
if: ${{ steps.variables.outputs.awsCreds }}
shell: bash
working-directory: repository
env:
AWS_MAX_ATTEMPTS: 9
run: |
node ../scripts/utils/logStep.js --step 'Invalidate Files'
if [ ${{ inputs.skipInvalidation }} = true ]; then
echo "skipping invalidation due to skipInvalidation flag";
elif [ ${{ inputs.skipPublish }} = true ]; then
echo "skipping invalidation due to skipPublish flag";
elif [ "${{ github.event_name }}" = "pull_request" ]; then
echo "skipping invalidation for pull_request action triggers";
else
if [ ${{ steps.variables.outputs.branch }} = production ]; then
if [ "${{ steps.variables.outputs.isSelfHosted }}" = "true" ]; then
echo "Only invalidating bundle.js due to self-hosted"
if [ '${{ steps.variables.outputs.siteId_Type }}' = 'string' ]; then
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/${{ steps.variables.outputs.siteId }}/bundle.js"
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'object' ]; then
echo "${{ steps.variables.outputs.siteIds }}" | tr , '\n' | while read siteId
do
echo "Invalidating files for siteId $siteId"
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/$siteId/bundle.js"
done
fi
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'string' ]; then
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/${{ steps.variables.outputs.siteId }}/*"
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'object' ]; then
echo "${{ steps.variables.outputs.siteIds }}" | tr , '\n' | while read siteId
do
echo "Invalidating files for siteId $siteId"
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/$siteId/*"
sleep 3
done
fi
else
if [ "${{ steps.variables.outputs.isSelfHosted }}" = "true" ]; then
echo "Skipping invalidation for branch due to self-hosted"
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'string' ]; then
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/${{ steps.variables.outputs.siteId }}/${{ steps.variables.outputs.branch }}/*"
elif [ '${{ steps.variables.outputs.siteId_Type }}' = 'object' ]; then
echo "${{ steps.variables.outputs.siteIds }}" | tr , '\n' | while read siteId
do
echo "Invalidating files for siteId $siteId on branch ${{ steps.variables.outputs.branch }}"
aws cloudfront create-invalidation --distribution-id ${{ inputs.aws-cloudfront-distribution-id }} --paths "/$siteId/${{ steps.variables.outputs.branch }}/*"
sleep 3
done
fi
fi
fi;
- name: Commit package-lock.json
id: commit-package-lock
shell: bash
if: steps.variables.outputs.isSelfHosted == 'true' && github.event_name == 'push' && steps.variables.outputs.branch != 'production'
working-directory: repository
run: |
node ../scripts/utils/logStep.js --step 'Commit package-lock.json'
if [ -f "package-lock.json" ]; then
# "intent-to-add" to allow diff of untracked file
git config user.name searchspring-machine
git config user.email [email protected]
git add package-lock.json --intent-to-add
# if file changed, commit it to the branch
git diff --quiet -- package-lock.json || ( echo "Committing package-lock.json" && \
git add package-lock.json && \
git commit -m "commit package-lock.json from action" && \
git push -u origin ${{ steps.variables.outputs.branch }} )
fi
- name: Conclusion Metrics
id: metrics
shell: bash
if: always()
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
node scripts/utils/logSummary.js --steps '${{ toJSON(steps) }}'
duration="$(($(date -u +%s)-${{ steps.variables.outputs.startTime }}))"
if [ '${{ steps.variables.outputs.awsCreds }}' == '' ]; then
echo "Skipping final metric because one of the following inputs has not been provided: aws-access-key-id, aws-secret-access-key, aws-cloudfront-distribution-id, aws-s3-bucket-name"
else
patchId=$(node scripts/utils/patchId.js --branch "${{ steps.variables.outputs.branch }}" --commitMessage "$COMMIT_MESSAGE")
npx -y jjo \
timestamp=$(date -u +"%FT%TZ" | tr -d '\n') \
type=snap-action \
data=$(npx -y jjo \
conclusion=${{ github.action_status }} \
duration=$duration \
repository=${{ steps.variables.outputs.repository }} \
repositoryOwner=${{ github.repository_owner }} \
branch=${{ steps.variables.outputs.branch }} \
baseRef=${{ github.base_ref }} \
actor=${{ github.actor }} \
eventName=${{ github.event_name }} \
job=${{ github.job }} \
sha_before=${{ github.event.before }} \
sha_after=${{ github.event.after }} \
sha_pr_head=${{ github.event.pull_request.head.sha }} \
sha=${{ github.event.pull_request.base.sha }} \
pullRequestID=${{ github.event.pull_request.number }} \
patchId=$patchId \
url='https://github.com/${{ github.repository_owner }}/${{ steps.variables.outputs.repository }}/actions/runs/${{ github.run_id }}' \
runAttempt=${{ github.run_attempt }} \
failedStep='${{ steps.checkout-repo.conclusion == 'Failure' && 'checkout-repo' || steps.configure-aws.conclusion == 'Failure' && 'configure-aws' || steps.variables.conclusion == 'Failure' && 'variables' || steps.authenticate.conclusion == 'Failure' && 'authenticate' || steps.setup-node.conclusion == 'Failure' && 'setup-node' || steps.cache.conclusion == 'Failure' && 'cache' || steps.install.conclusion == 'Failure' && 'install' || steps.build.conclusion == 'Failure' && 'build' || steps.test.conclusion == 'Failure' && 'test' || steps.snapfu-recs-sync.conclusion == 'Failure' && 'snapfu-recs-sync' || steps.snapfu-badges-sync.conclusion == 'Failure' && 'snapfu-badges-sync' || steps.lighthouse.conclusion == 'Failure' && 'lighthouse' || steps.tag.conclusion == 'Failure' && 'tag' || steps.pr-comment.conclusion == 'Failure' && 'pr-comment' || steps.s3-upload.conclusion == 'Failure' && 's3-upload' || steps.lighthouse-metrics.conclusion == 'Failure' && 'lighthouse-metrics' || steps.invalidation.conclusion == 'Failure' && 'invalidation' || steps.metrics.conclusion == 'Failure' && 'metrics' || steps.start-metrics.conclusion == 'Failure' && 'start-metrics' || steps.commit-package-lock.conclusion == 'Failure' && 'commit-package-lock' || ''}}' \
) \
| tee ${{ steps.variables.outputs.repository }}-conclusion-${{ github.event_name }}-${{ steps.variables.outputs.packageJSONVersion }}.json SnapAction-${{ steps.variables.outputs.repository }}-${{ github.event_name }}-$(date -u +"%Y_%m_%d_%H%M").json && \
cat ./SnapAction*.json && \
aws s3 cp --region us-east-1 ./SnapAction*.json s3://datawarehouse-stage/team-metrics-import/
fi;
if [ '${{ steps.variables.outputs.isSelfHosted }}' == 'true' ]; then
# upload metric to s3 to be used in snapp-updater
aws s3 cp --acl public-read ./${{ steps.variables.outputs.repository }}-conclusion-${{ github.event_name }}-${{ steps.variables.outputs.packageJSONVersion }}.json s3://${{ inputs.aws-s3-bucket-name }}/${{ steps.variables.outputs.siteId }}/${{ steps.variables.outputs.branch }}/
# Conclusion metric used in snapp-updater action status, Should only run on self-hosted
node scripts/metrics/updater.js \
--runAttempt "${{ github.run_attempt }}" \
--actor "${{ github.actor }}" \
--repository "${{ steps.variables.outputs.repository }}" \
--branch "${{ steps.variables.outputs.branch }}" \
--eventName "${{ github.event_name }}" \
--pullRequestID "${{ github.event.pull_request.number }}" \
--startTime "" \
--conclusion "${{ github.action_status }}" \
--duration "$duration" \
--failedStep "${{ steps.checkout-repo.conclusion == 'Failure' && 'checkout-repo' || steps.configure-aws.conclusion == 'Failure' && 'configure-aws' || steps.variables.conclusion == 'Failure' && 'variables' || steps.authenticate.conclusion == 'Failure' && 'authenticate' || steps.setup-node.conclusion == 'Failure' && 'setup-node' || steps.cache.conclusion == 'Failure' && 'cache' || steps.install.conclusion == 'Failure' && 'install' || steps.build.conclusion == 'Failure' && 'build' || steps.test.conclusion == 'Failure' && 'test' || steps.snapfu-recs-sync.conclusion == 'Failure' && 'snapfu-recs-sync' || steps.snapfu-badges-sync.conclusion == 'Failure' && 'snapfu-badges-sync' || steps.lighthouse.conclusion == 'Failure' && 'lighthouse' || steps.tag.conclusion == 'Failure' && 'tag' || steps.pr-comment.conclusion == 'Failure' && 'pr-comment' || steps.s3-upload.conclusion == 'Failure' && 's3-upload' || steps.lighthouse-metrics.conclusion == 'Failure' && 'lighthouse-metrics' || steps.invalidation.conclusion == 'Failure' && 'invalidation' || steps.metrics.conclusion == 'Failure' && 'metrics' || steps.start-metrics.conclusion == 'Failure' && 'start-metrics' || steps.commit-package-lock.conclusion == 'Failure' && 'commit-package-lock' || ''}}" \
--commitMessage "$COMMIT_MESSAGE" \
--url "https://github.com/${{ github.repository_owner }}/${{ steps.variables.outputs.repository }}/actions/runs/${{ github.run_id }}" \
--secrets-ci '${{ steps.variables.outputs.secrets }}';
fi;