Repository navigation
1606 lines (1434 loc) · 71 KB
/
Copy pathci.yml
File metadata and controls
1606 lines (1434 loc) · 71 KB
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Workflow references:
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CI
on:
push:
branches: [main]
paths:
- '**'
- '.github/actions/**'
- '.github/workflows/**'
- '!**/README.md'
- 'packages/**/README.md'
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
paths:
- '**'
- '.github/actions/**'
- '.github/workflows/**'
- '!**/README.md'
- 'packages/**/README.md'
permissions:
contents: read
env:
# This is used by the SharedProps to detect a PR build
PR_NUMBER: ${{ github.event.pull_request.number }}
# Set env to prod so we don't get an env suffix on the DNS names
NODE_ENV: ${{ secrets.NODE_ENV }}
DEMO_APP_NAME: demo-app
STATIC_APP_NAME: static-app
NEXTJS_DEMO_APP_NAME: nextjs-demo
RELEASE_APP_NAME: release
AWS_REGION: us-east-2
jobs:
install-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Read Node.js version
id: node-version
run: echo "version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
- uses: pwrdrvr/configure-nodejs@v1
with:
node-version: ${{ steps.node-version.outputs.version }}
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
build:
needs: [install-deps]
runs-on: ubuntu-latest
outputs:
prSuffix: ${{ steps.prSuffix.outputs.prSuffix }}
prSuffixPackageVersion: ${{ steps.prSuffix.outputs.prSuffixPackageVersion }}
releaseAppPackageVersion: ${{ steps.appVersions.outputs.releaseAppPackageVersion }}
nextjsDemoAppPackageVersion: ${{ steps.appVersions.outputs.nextjsDemoAppPackageVersion }}
steps:
- uses: actions/checkout@v5
- name: Compute PR Suffix
id: prSuffix
run: |
if [ -n "${PR_NUMBER}" ]; then
echo "prSuffix=-pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "prSuffixPackageVersion=-pr.${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "PR_SUFFIX=-pr-"${PR_NUMBER} >> $GITHUB_ENV
else
echo "prSuffix=" >> $GITHUB_OUTPUT
echo "prSuffixPackageVersion=" >> $GITHUB_OUTPUT
echo "PR_SUFFIX=" >> $GITHUB_ENV
fi
- name: Read Node.js version
id: node-version
run: echo "version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
- uses: pwrdrvr/configure-nodejs@v1
with:
node-version: ${{ steps.node-version.outputs.version }}
# We do this here so the `build-jsii` modules are installed too
# and become part of the cache - if we don't then
# their install will get skipped during `build-jsii` but they won't
# be present in the cache so the build will fail
# - name: Optionally Install CDK Construct Deps
# if: steps.cache-node-modules.outputs.cache-hit != 'true'
# working-directory: packages/microapps-cdk/
# run: pnpm install --frozen-lockfile --ignore-workspace
- name: Extract App NPM Versions
id: appVersions
run: |
# find . -type d -name microapps-app-nextjs-demo-cdk
echo 'NEXTJS_DEMO_APP_PACKAGE_VERSION='$(node -p -e "(require('./packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/package.json')).version") >> $GITHUB_ENV
echo 'RELEASE_APP_PACKAGE_VERSION='$(node -p -e "(require('./packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/package.json')).version") >> $GITHUB_ENV
echo "nextjsDemoAppPackageVersion=$(node -p -e "(require('./packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/package.json')).version")" >> $GITHUB_OUTPUT
echo "releaseAppPackageVersion=$(node -p -e "(require('./packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/package.json')).version")" >> $GITHUB_OUTPUT
- name: Versions
run: |
echo 'NEXTJS_DEMO_APP_PACKAGE_VERSION='${NEXTJS_DEMO_APP_PACKAGE_VERSION}
echo 'RELEASE_APP_PACKAGE_VERSION='${RELEASE_APP_PACKAGE_VERSION}
- name: Cache TypeScript Build Output
id: cache-typescript-build
uses: actions/cache@v5
with:
path: |
packages/**/dist
packages/microapps-cdk/lib
key: typescript-build-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'tsconfig.json', 'tsconfig.packages.json', 'packages/**/tsconfig.json', 'packages/**/*.ts') }}
- name: Optionally Build All TypeScript
if: steps.cache-typescript-build.outputs.cache-hit != 'true'
run: pnpm build
- name: Run Lint
run: pnpm lint
# - name: Run Node Tests
# env:
# NODE_ENV: test
# run: yarn test
test:
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v5
- name: Read Node.js version
id: node-version
run: echo "version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
- uses: pwrdrvr/configure-nodejs@v1
with:
node-version: ${{ steps.node-version.outputs.version }}
- name: Cache TypeScript Build Output
id: cache-typescript-build
uses: actions/cache@v5
with:
path: |
packages/**/dist
packages/microapps-cdk/lib
key: typescript-build-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'tsconfig.json', 'tsconfig.packages.json', 'packages/**/tsconfig.json', 'packages/**/*.ts') }}
# These take 2 minutes on GHA
# Locally they take 16 seconds (M2 Max)
# Possible speedup: may need to replace jest-dynalite and switch to each
# test (or at least suite) creating a uniquely named table in a shared
# local dynamodb instance.
- name: Run Node Tests
env:
NODE_ENV: test
run: pnpm test
decide-preview-scope:
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
pull-requests: read
outputs:
should_deploy_core: ${{ steps.decide.outputs.should_deploy_core }}
should_deploy_basic: ${{ steps.decide.outputs.should_deploy_basic }}
should_deploy_basic_prefix: ${{ steps.decide.outputs.should_deploy_basic_prefix }}
decision_reason_core: ${{ steps.decide.outputs.decision_reason_core }}
decision_reason_basic: ${{ steps.decide.outputs.decision_reason_basic }}
decision_reason_basic_prefix: ${{ steps.decide.outputs.decision_reason_basic_prefix }}
steps:
- uses: actions/checkout@v5
if: github.event_name == 'pull_request'
- name: Gather Changed Files
if: github.event_name == 'pull_request'
id: changed_files
uses: actions/github-script@v8
with:
script: |
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
});
return files.map((file) => file.filename);
- name: Read Existing PR Labels
if: github.event_name == 'pull_request'
id: existing_labels
uses: actions/github-script@v8
with:
script: |
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
});
return labels.map((label) => label.name);
- name: Classify Preview Deploy Scope
if: github.event_name == 'pull_request'
id: classify
env:
FILES_JSON: ${{ steps.changed_files.outputs.result }}
EXISTING_LABELS_JSON: ${{ steps.existing_labels.outputs.result }}
run: |
node scripts/github/preview-deploy-scope.mjs \
--files-json "$FILES_JSON" \
--existing-labels-json "$EXISTING_LABELS_JSON" \
--github-output "$GITHUB_OUTPUT"
- name: Decide Whether Preview Deploys Should Run
id: decide
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_ACTOR: ${{ github.actor }}
EXISTING_LABELS_JSON: ${{ steps.existing_labels.outputs.result || '[]' }}
RECOMMENDED_LABELS_JSON: ${{ steps.classify.outputs.recommended_labels_json || '[]' }}
run: |
node <<'NODE'
const fs = require('fs');
function parseStringArray(rawValue) {
if (!rawValue) {
return [];
}
const value = JSON.parse(rawValue);
return Array.isArray(value) ? value : [];
}
const actor = process.env.GITHUB_ACTOR;
const eventName = process.env.GITHUB_EVENT_NAME;
const existingLabels = new Set(parseStringArray(process.env.EXISTING_LABELS_JSON));
const recommendedLabels = new Set(parseStringArray(process.env.RECOMMENDED_LABELS_JSON));
function decide(labelName) {
const normalizedLabel = labelName.toLowerCase();
if (actor === 'dependabot[bot]') {
return { shouldDeploy: false, reason: `dependabot-no-${normalizedLabel}` };
}
if (eventName !== 'pull_request') {
return { shouldDeploy: true, reason: 'non-pr-event' };
}
if (recommendedLabels.has(labelName)) {
return { shouldDeploy: true, reason: `${normalizedLabel}-matched-files` };
}
if (existingLabels.has(labelName)) {
return { shouldDeploy: true, reason: `${normalizedLabel}-label-present` };
}
return { shouldDeploy: false, reason: `${normalizedLabel}-not-requested` };
}
const decisions = {
core: decide('DEPLOY-CORE'),
basic: decide('DEPLOY-BASIC'),
basicPrefix: decide('DEPLOY-BASIC-PREFIX'),
};
const lines = [
`should_deploy_core=${decisions.core.shouldDeploy ? 'true' : 'false'}`,
`should_deploy_basic=${decisions.basic.shouldDeploy ? 'true' : 'false'}`,
`should_deploy_basic_prefix=${decisions.basicPrefix.shouldDeploy ? 'true' : 'false'}`,
`decision_reason_core=${decisions.core.reason}`,
`decision_reason_basic=${decisions.basic.reason}`,
`decision_reason_basic_prefix=${decisions.basicPrefix.reason}`,
];
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${lines.join('\n')}\n`);
NODE
deploy-microapps-core-run:
name: deploy-microapps-core-run
needs:
- build
- decide-preview-scope
if: needs.decide-preview-scope.outputs.should_deploy_core == 'true'
concurrency:
group: deploy-microapps-core-${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: false
environment:
name: ${{ github.event_name == 'pull_request' && 'ghpublic-pr' || 'ghpublic' }}
url: https://${{ steps.getCDKExports.outputs.edgeDomain }}/${{ env.RELEASE_APP_NAME }}/
permissions:
contents: read
deployments: write
id-token: write
statuses: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Extract Current NPM Version
run: |
echo 'PACKAGE_VERSION_ORIG='$(node -p -e "require('./package.json').version") >> $GITHUB_ENV
- name: Compute NPM Version and App Lambda Name
run: |
echo 'PACKAGE_VERSION='${PACKAGE_VERSION_ORIG}${{ needs.build.outputs.prSuffixPackageVersion }} >> $GITHUB_ENV
- name: Set Prefix Path
run: |
echo 'PREFIX=' >> $GITHUB_ENV
echo 'PREFIX_U=' >> $GITHUB_ENV
- name: Read Node.js version
id: node-version
run: echo "version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
- uses: pwrdrvr/configure-nodejs@v1
with:
node-version: ${{ steps.node-version.outputs.version }}
- name: Resolve Packaged App Static Asset Paths
shell: bash
run: |
node <<'NODE' >> "$GITHUB_ENV"
const path = require('path');
const assetPackages = [
['NEXTJS_DEMO_STATIC_ASSETS_PATH', '@pwrdrvr/microapps-app-nextjs-demo-cdk', 'lib/microapps-app-nextjs-demo/static_files'],
['RELEASE_APP_STATIC_ASSETS_PATH', '@pwrdrvr/microapps-app-release-cdk', 'lib/microapps-app-release/static_files'],
];
for (const [envName, pkgName, relativePath] of assetPackages) {
const packageJsonPath = require.resolve(`${pkgName}/package.json`, {
paths: [path.resolve('packages/cdk')],
});
console.log(`${envName}=${path.join(path.dirname(packageJsonPath), relativePath)}`);
}
NODE
- name: Build All TypeScript
run: pnpm build
- name: Build Edge-to-Origin for Local Deploy
run: pnpm esbuild:edge-to-origin
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Stitch Version and Prefix into Simple Demo App and Static App
run: |
npx replace-in-file "/\/0\.0\.0/g" ${PREFIX}/${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.static-app-replace.config.js --isRegex
- name: Stitch Prefix into Nextjs Demo App
run: |
if [ -n "${PREFIX}" ] ; then
npx replace-in-file "/\/${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX}/${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex
npx replace-in-file "/\/u002F${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX_U}/u002F${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex
fi
- name: Stitch Prefix into Release App
run: |
if [ -n "${PREFIX}" ] ; then
npx replace-in-file "/\/${RELEASE_APP_NAME}/g" ${PREFIX}/${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex
npx replace-in-file "/\/u002F${RELEASE_APP_NAME}/g" ${PREFIX_U}/u002F${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex
fi
- name: Synth CDK Stack
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
run: |
npx cdk synth --context @pwrdrvr/microapps:deployDemoApp=true \
--context @pwrdrvr/microapps:deployNexjsDemoApp=true \
--context @pwrdrvr/microapps:deployReleaseApp=true \
--require-approval never microapps-core
- name: Zip Package
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
working-directory: .
run: zip -r cdk-out.zip cdk.out
- name: Upload Zip
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
uses: actions/upload-artifact@v6
with:
name: cdk_out_microapps-core
path: cdk-out.zip
- name: Diff CDK Stack
run: |
npx cdk diff --context @pwrdrvr/microapps:deployDemoApp=true \
--context @pwrdrvr/microapps:deployNexjsDemoApp=true \
--context @pwrdrvr/microapps:deployReleaseApp=true \
--require-approval never microapps-core
- name: Set Hotswap Flag on PRs
run: |
if [ -n "${PR_NUMBER}" ]; then
echo "HOTSWAP_FLAG=" >> $GITHUB_ENV
else
echo "HOTSWAP_FLAG=" >> $GITHUB_ENV
fi
- name: Deploy CDK Stack
env:
AWS_ACCOUNT_ID_CHILD: ${{ secrets.AWS_ACCOUNT_ID_CHILD }}
run: |
npx cdk deploy \
${HOTSWAP_FLAG} \
--context @pwrdrvr/microapps:deployDemoApp=true \
--context @pwrdrvr/microapps:deployNexjsDemoApp=true \
--context @pwrdrvr/microapps:deployReleaseApp=true \
--require-approval never microapps-core
- name: Get CDK Exports
id: getCDKExports
run: |
echo "prefix=${PREFIX}" >> $GITHUB_OUTPUT
echo "edgeDomain="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --output text) >> $GITHUB_OUTPUT
echo "EDGE_DOMAIN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --output text) >> $GITHUB_ENV
echo "EDGE_TO_ORIGIN_ROLE_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-role-role-arn\`].Value" --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
- name: Echo Exports
run: |
env | grep EDGE_
env | grep DEPLOYER_
env | grep DEMO_APP_
env | grep NEXTJS_DEMO_APP_
env | grep RELEASE_APP_
- name: Publish URL App to MicroApps
run: |
npx pwrdrvr publish \
--app-name blog \
--type url \
--new-version ${PACKAGE_VERSION} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--url https://www.pwrdrvr.com \
--overwrite
- name: Publish Static App to Child MicroApps
run: |
npx pwrdrvr publish-static \
--app-name ${STATIC_APP_NAME} \
--new-version 0.0.0 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_ARN} \
--static-assets-path packages/static-app/src \
--default-file index.html \
--overwrite
- name: Publish Demo App to MicroApps
run: |
npx pwrdrvr publish \
--app-name ${DEMO_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version 0.0.0 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name ${DEMO_APP_LAMBDA_NAME} \
--static-assets-path packages/demo-app/static_files \
--default-file index.html \
--overwrite
- name: Demo App URL
uses: actions/github-script@v8
with:
script: |
await github.rest.repos.createCommitStatus({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}',
sha: '${{github.event.pull_request.head.sha || github.sha}}',
context: 'Demo App URL on microapps-core',
state: 'success',
description: 'Passed',
target_url: `https://${{ steps.getCDKExports.outputs.edgeDomain }}/${{ env.DEMO_APP_NAME }}/?appver=0.0.0`
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test Demo App
run: |
echo Testing App Frame Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/0.0.0/index.html
echo Testing App Method Invocation
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/0.0.0/serverIncrement?currValue=1"
echo Testing App Method Invocation on _next/data Route
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/_next/data/0.0.0/serverIncrement?currValue=1"
- name: Publish Demo App to MicroApps - To Delete
run: |
npx pwrdrvr publish \
--app-name ${DEMO_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version 0.0.0-delete.1 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name ${DEMO_APP_LAMBDA_NAME} \
--static-assets-path packages/demo-app/static_files \
--default-file index.html \
--overwrite \
--no-cache
- name: Delete Demo App - To Delete
run: |
npx pwrdrvr delete \
--app-name ${DEMO_APP_NAME} \
--new-version 0.0.0-delete.1 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME}
- name: Publish Demo App to MicroApps - Root App
run: |
npx pwrdrvr publish \
--app-name '[root]' \
--type lambda-url \
--startup-type direct \
--new-version 0.0.0 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name ${DEMO_APP_LAMBDA_NAME} \
--static-assets-path packages/demo-app/static_files \
--default-file index.html \
--overwrite
- name: Demo App URL - Root App
uses: actions/github-script@v8
with:
script: |
await github.rest.repos.createCommitStatus({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}',
sha: '${{github.event.pull_request.head.sha || github.sha}}',
context: 'Demo App (Root App) URL on microapps-core',
state: 'success',
description: 'Passed',
target_url: `https://${{ steps.getCDKExports.outputs.edgeDomain }}/?appver=${{ env.PACKAGE_VERSION }}`
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test Demo App - Root App
run: |
echo Testing App Frame Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/0.0.0/index.html
echo Testing App Method Invocation
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/0.0.0/serverIncrement?currValue=1"
echo Testing App Method Invocation on _next/data Route
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/_next/data/0.0.0/serverIncrement?currValue=1"
- name: Publish Nextjs Demo App to MicroApps
run: |
npx pwrdrvr publish \
--app-name ${NEXTJS_DEMO_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version ${{ needs.build.outputs.nextjsDemoAppPackageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name ${NEXTJS_DEMO_APP_LAMBDA_VERSION_ARN} \
--static-assets-path ${NEXTJS_DEMO_STATIC_ASSETS_PATH} \
--overwrite
- name: Nextjs Demo App URL
uses: actions/github-script@v8
with:
script: |
await github.rest.repos.createCommitStatus({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}',
sha: '${{github.event.pull_request.head.sha || github.sha}}',
context: 'Nextjs Demo App URL on microapps-core',
state: 'success',
description: 'Passed',
target_url: `https://${{ steps.getCDKExports.outputs.edgeDomain }}/${{ env.NEXTJS_DEMO_APP_NAME }}?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }}`
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test Nextjs Demo App
run: |
echo Testing App Page Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }}
echo Testing Post Page Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/posts/pre-rendering?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }}
- name: Publish Release App to MicroApps
run: |
npx pwrdrvr publish \
--app-name ${RELEASE_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version ${{ needs.build.outputs.releaseAppPackageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name ${RELEASE_APP_LAMBDA_VERSION_ARN} \
--static-assets-path ${RELEASE_APP_STATIC_ASSETS_PATH} \
--overwrite
- name: Release App URL
uses: actions/github-script@v8
with:
script: |
await github.rest.repos.createCommitStatus({
owner: '${{ github.repository_owner }}',
repo: '${{ github.event.repository.name }}',
sha: '${{github.event.pull_request.head.sha || github.sha}}',
context: 'Release App URL on microapps-core',
state: 'success',
description: 'Passed',
target_url: `https://${{ steps.getCDKExports.outputs.edgeDomain }}/${{ env.RELEASE_APP_NAME }}?appver=${{ needs.build.outputs.releaseAppPackageVersion }}`
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test Release App
run: |
echo Testing App Frame Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}?appver=${{ needs.build.outputs.releaseAppPackageVersion }}
echo Testing App Method Invocation
# Exercise the 0.7.0 API without changing a default version.
response=$(curl --silent --show-error --write-out '\n%{http_code}' \
-H"accept: application/json" -H"content-type: application/json" \
--data '{}' \
https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}/${{ needs.build.outputs.releaseAppPackageVersion }}/api/default-version)
expected=$'{"error":"appName and semVer are required."}\n400'
if [ "$response" != "$expected" ]; then
printf 'Unexpected release API response:\n%s\n' "$response"
exit 1
fi
- name: Change to Child Account
uses: aws-actions/configure-aws-credentials@v6
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_CHILD }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Deploy Child CDK Stack
env:
PARENT_DEPLOYER_LAMBDA_ARN: ${{ env.DEPLOYER_LAMBDA_ARN }}
run: |
npx cdk deploy \
${HOTSWAP_FLAG} \
--require-approval never microapps-core-child
- name: Get Child CDK Exports
id: getChildCDKExports
run: |
echo "CHILD_DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-core-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
- name: Echo Exports
run: |
env | grep CHILD_
- name: Change Back to Parent AWS Account
uses: aws-actions/configure-aws-credentials@v6
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Allow Child Deployer to Invoke Parent Deployer
env:
PARENT_DEPLOYER_LAMBDA_ARN: ${{ env.DEPLOYER_LAMBDA_ARN }}
AWS_ACCOUNT_ID_CHILD: ${{ secrets.AWS_ACCOUNT_ID_CHILD }}
run: |
npx cdk deploy \
--require-approval never microapps-core-child-priv
- name: Change Back to Child Account
uses: aws-actions/configure-aws-credentials@v6
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_CHILD }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Publish Demo App to Child MicroApps - To Delete
run: |
npx pwrdrvr publish \
--app-name ${DEMO_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version 0.0.0-childDelete.1 \
--deployer-lambda-name ${CHILD_DEPLOYER_LAMBDA_ARN} \
--app-lambda-name ${CHILD_DEMO_APP_LAMBDA_NAME} \
--static-assets-path packages/demo-app/static_files \
--default-file index.html \
--overwrite
- name: Delete Demo App from Child MicroApps - To Delete
run: |
npx pwrdrvr delete \
--app-name ${DEMO_APP_NAME} \
--new-version 0.0.0-childDelete.1 \
--deployer-lambda-name ${CHILD_DEPLOYER_LAMBDA_ARN}
- name: Publish Demo App to Child MicroApps
run: |
npx pwrdrvr publish \
--app-name ${DEMO_APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version 0.0.0-child.1 \
--deployer-lambda-name ${CHILD_DEPLOYER_LAMBDA_ARN} \
--app-lambda-name ${CHILD_DEMO_APP_LAMBDA_NAME} \
--static-assets-path packages/demo-app/static_files \
--default-file index.html \
--overwrite
- name: Test Demo App - Child
run: |
echo Testing App Frame Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/0.0.0-child.1/index.html
echo Testing App Method Invocation
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/0.0.0-child.1/serverIncrement?currValue=1"
echo Testing App Method Invocation on _next/data Route
curl -H"accept: application/json" --fail "https://${EDGE_DOMAIN}${PREFIX}/${DEMO_APP_NAME}/_next/data/0.0.0-child.1/serverIncrement?currValue=1"
- name: Run Integration Tests
env:
BASE_URL: https://${{ env.EDGE_DOMAIN }}${{ env.PREFIX }}/
DEMO_AND_ROOT_APP_VER: '0.0.0'
NEXTJS_DEMO_APP_VER: '${{ needs.build.outputs.nextjsDemoAppPackageVersion }}'
DEPLOY_NAME: microapps-core
run: |
pnpm test:integration
- name: Publish Transient PR Preview Deployment
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v8
env:
DEPLOY_NAME: microapps-core
PREVIEW_URL: https://${{ steps.getCDKExports.outputs.edgeDomain }}/${{ env.RELEASE_APP_NAME }}/
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const headSha = context.payload.pull_request.head.sha;
const prNumber = context.payload.pull_request.number;
const deployName = process.env.DEPLOY_NAME;
const previewUrl = process.env.PREVIEW_URL;
const logUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`;
const deployments = await github.paginate(github.rest.repos.listDeployments, {
owner,
repo,
environment: 'ghpublic-pr',
per_page: 100,
});
const existing = deployments.find((deployment) => {
return (
deployment.task === 'preview-transient' &&
deployment.sha === headSha &&
deployment.payload?.deployName === deployName
);
});
const deployment =
existing ??
(
await github.rest.repos.createDeployment({
owner,
repo,
ref: headSha,
task: 'preview-transient',
environment: 'ghpublic-pr',
description: `Transient preview deployment for PR #${prNumber} (${deployName})`,
auto_merge: false,
required_contexts: [],
production_environment: false,
transient_environment: true,
payload: {
deployName,
prNumber,
},
})
).data;
await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.id,
state: 'success',
description: 'PR preview deployed successfully.',
log_url: logUrl,
environment_url: previewUrl,
auto_inactive: false,
});
deploy-microapps-core-noop:
name: deploy-microapps-core-noop
needs:
- decide-preview-scope
if: needs.decide-preview-scope.outputs.should_deploy_core != 'true'
runs-on: ubuntu-latest
permissions: {}
steps:
- name: No Core Preview Deploy Required
run: |
echo "Skipping microapps-core preview deploy."
echo "Reason: ${{ needs.decide-preview-scope.outputs.decision_reason_core }}"
deploy-microapps-core:
name: deploy-microapps-core
needs:
- decide-preview-scope
- deploy-microapps-core-run
- deploy-microapps-core-noop
if: always()
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Validate Core Deploy Outcome
run: |
SHOULD_DEPLOY='${{ needs.decide-preview-scope.outputs.should_deploy_core }}'
DECIDE_RESULT='${{ needs.decide-preview-scope.result }}'
RUN_RESULT='${{ needs.deploy-microapps-core-run.result }}'
NOOP_RESULT='${{ needs.deploy-microapps-core-noop.result }}'
echo "should_deploy_core=$SHOULD_DEPLOY"
echo "decide_result=$DECIDE_RESULT"
echo "run_result=$RUN_RESULT"
echo "noop_result=$NOOP_RESULT"
if [ "$DECIDE_RESULT" != "success" ]; then
echo "Core deploy decision job did not succeed."
exit 1
fi
if [ "$SHOULD_DEPLOY" = "true" ]; then
if [ "$RUN_RESULT" != "success" ]; then
echo "Core deploy was required but did not succeed."
exit 1
fi
if [ "$NOOP_RESULT" != "skipped" ]; then
echo "No-op branch should have been skipped when deploy was required."
exit 1
fi
else
if [ "$NOOP_RESULT" != "success" ]; then
echo "Core deploy no-op branch did not succeed."
exit 1
fi
if [ "$RUN_RESULT" != "skipped" ]; then
echo "Real core deploy branch should have been skipped when deploy was not required."
exit 1
fi
fi
deploy-optional-preview:
if: github.actor != 'dependabot[bot]' && (github.event_name != 'pull_request' || needs.decide-preview-scope.outputs.should_deploy_basic == 'true' || needs.decide-preview-scope.outputs.should_deploy_basic_prefix == 'true')
strategy:
matrix:
deployName:
- microapps-basic
- microapps-basic-prefix
exclude:
- deployName: ${{ (github.event_name != 'pull_request' || needs.decide-preview-scope.outputs.should_deploy_basic == 'true') && 'dummy' || 'microapps-basic' }}
- deployName: ${{ (github.event_name != 'pull_request' || needs.decide-preview-scope.outputs.should_deploy_basic_prefix == 'true') && 'dummy' || 'microapps-basic-prefix' }}
name: deploy-${{ matrix.deployName }}
concurrency:
group: deploy-${{ matrix.deployName }}-${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: false
needs:
- build
- decide-preview-scope
environment:
name: ${{ github.event_name == 'pull_request' && 'ghpublic-pr' || 'ghpublic' }}
url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.RELEASE_APP_NAME }}/
permissions:
contents: read
deployments: write
id-token: write
statuses: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Extract Current NPM Version
run: |
echo 'PACKAGE_VERSION_ORIG='$(node -p -e "require('./package.json').version") >> $GITHUB_ENV
- name: Compute NPM Version and App Lambda Name
run: |
echo 'PACKAGE_VERSION='${PACKAGE_VERSION_ORIG}${{ needs.build.outputs.prSuffixPackageVersion }} >> $GITHUB_ENV
- name: Set Prefix Path
run: |
if [ "${{ matrix.deployName }}" == "microapps-basic-prefix" ]; then
echo 'PREFIX=/prefix' >> $GITHUB_ENV
echo 'PREFIX_U=/u002Fprefix' >> $GITHUB_ENV
else
echo 'PREFIX=' >> $GITHUB_ENV
echo 'PREFIX_U=' >> $GITHUB_ENV
fi
- name: Read Node.js version
id: node-version
run: echo "version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
- uses: pwrdrvr/configure-nodejs@v1
with:
node-version: ${{ steps.node-version.outputs.version }}
- name: Resolve Packaged App Static Asset Paths
shell: bash
run: |
node <<'NODE' >> "$GITHUB_ENV"
const path = require('path');
const assetPackages = [
['NEXTJS_DEMO_STATIC_ASSETS_PATH', '@pwrdrvr/microapps-app-nextjs-demo-cdk', 'lib/microapps-app-nextjs-demo/static_files'],
['RELEASE_APP_STATIC_ASSETS_PATH', '@pwrdrvr/microapps-app-release-cdk', 'lib/microapps-app-release/static_files'],
];
for (const [envName, pkgName, relativePath] of assetPackages) {
const packageJsonPath = require.resolve(`${pkgName}/package.json`, {
paths: [path.resolve('packages/cdk')],
});
console.log(`${envName}=${path.join(path.dirname(packageJsonPath), relativePath)}`);
}
NODE
# - name: Cache TypeScript Build Output
# id: cache-typescript-build
# uses: actions/cache@v5
# with:
# path: |
# packages/**/dist
# packages/microapps-cdk/lib
# key: typescript-build-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'tsconfig.json', 'tsconfig.packages.json', 'packages/**/tsconfig.json', 'packages/**/*.ts') }}
- name: Build All TypeScript
# if: steps.cache-typescript-build.outputs.cache-hit != 'true'
run: pnpm build
- name: Build Edge-to-Origin for Local Deploy
run: pnpm esbuild:edge-to-origin
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Stitch Version and Prefix into Simple Demo App and Static App
run: |
npx replace-in-file "/\/0\.0\.0/g" ${PREFIX}/${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.static-app-replace.config.js --isRegex
- name: Stitch Prefix into Nextjs Demo App
run: |
if [ -n "${PREFIX}" ] ; then
npx replace-in-file "/\/${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX}/${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex
npx replace-in-file "/\/u002F${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX_U}/u002F${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex
fi
- name: Stitch Prefix into Release App
run: |
if [ -n "${PREFIX}" ] ; then
npx replace-in-file "/\/${RELEASE_APP_NAME}/g" ${PREFIX}/${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex
npx replace-in-file "/\/u002F${RELEASE_APP_NAME}/g" ${PREFIX_U}/u002F${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex
fi
#
# Synth and upload if BUILD-CDK-ZIP label is present
#
- name: Synth CDK Stack