-
Notifications
You must be signed in to change notification settings - Fork 2
308 lines (267 loc) · 11.2 KB
/
ci.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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# Workflow syntax reference:
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: CI
on:
# Deploys with overwrite as current package.json version to main deploy
# New versions are deployed with `deploy` build
push:
branches: [ main ]
pull_request:
branches: [ main ]
# release:
# types: [published]
env:
# This is used by the SharedProps to detect a PR build
PR_NUMBER: ${{ github.event.pull_request.number }}
APP_CONSTRUCT_FOLDER_NAME: microapps-app-release
APP_NAME: release
APP_PACKAGE_NAME: '@pwrdrvr/microapps-app-release'
ENV: prod
DEPLOYER_LAMBDA_NAME: microapps-core-ghpublic-deployer-prod
AWS_REGION: us-east-2
CDK_CONTEXT_ARGS: "--context @pwrdrvr/microapps:tableName=microapps-core-ghpublic-prod"
jobs:
version:
uses: ./.github/workflows/r_version.yml
with:
APP_PACKAGE_NAME: '@pwrdrvr/microapps-app-release'
build:
needs:
- version
uses: ./.github/workflows/r_build-app.yml
with:
APP_NAME: release
APP_PACKAGE_NAME: '@pwrdrvr/microapps-app-release'
APP_CONSTRUCT_FOLDER_NAME: microapps-app-release
packageVersion: ${{ needs.version.outputs.packageVersion }}
prSuffix: ${{ needs.version.outputs.prSuffix }}
build-storybook:
needs:
- version
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'BUILD-STORYBOOK'))
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Dump info from version reusable workflow
run: |
echo "packageVersion: ${{ needs.version.outputs.packageVersion }}"
echo "prSuffix: ${{ needs.version.outputs.prSuffix }}"
- name: Apply NPM Version to Everything
run: |
npm version ${{ needs.version.outputs.packageVersion }} \
--no-git-tag-version --allow-same-version
npm version ${{ needs.version.outputs.packageVersion }} \
--no-git-tag-version --allow-same-version --workspaces
- name: Build Story Book
run: |
npm run -w ${APP_PACKAGE_NAME} build:storybook
# Upload Artifact
- name: Zip Package
working-directory: packages/app/
run: zip -r storybook-static.zip storybook-static
- name: Upload Zip
uses: actions/upload-artifact@v3
with:
name: storybook_zip
path: packages/app/storybook-static.zip
deploy-storybook:
if: github.actor != 'dependabot[bot]'
needs:
- version
- build-storybook
concurrency:
group: deploy-storybook-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.pull_request.number) || github.head_ref }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
statuses: write
runs-on: ubuntu-latest
environment:
name: ghpublic
url: https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}-storybook/${{ needs.version.outputs.packageVersion }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Download Artifact - Story Book
uses: actions/download-artifact@v3
with:
name: storybook_zip
path: packages/app/
- name: Unzip Artifact - Story Book
working-directory: packages/app/
run: unzip storybook-static.zip
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-session-name: microapps-app-${{ env.APP_NAME }}-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Preflight Check Version - Story Book
run: |
npx microapps-publish preflight \
--app-name ${APP_NAME}-storybook \
--new-version ${{ needs.version.outputs.packageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--overwrite
- name: Publish MicroApps - Story Book
run: |
npx microapps-publish publish-static \
--app-name ${APP_NAME}-storybook \
--new-version ${{ needs.version.outputs.packageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--static-assets-path packages/app/storybook-static \
--default-file index.html \
--overwrite \
--no-cache
- name: App URL
uses: Sibz/github-status-action@v1
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Storybook URL'
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
target_url: https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}-storybook/${{ needs.version.outputs.packageVersion }}
deploy-ghpublic:
if: github.actor != 'dependabot[bot]'
needs:
- version
- build
concurrency:
group: deploy-app-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.pull_request.number) || github.head_ref }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
statuses: write
runs-on: ubuntu-latest
environment:
name: ghpublic
url: https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}?appver=${{ needs.version.outputs.packageVersion }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
# Fixes errors due to JSII tsconfig.json not ignoring libs
# node_modules/flatpickr/dist/types/instance.d.ts(37,21): error TS2304: Cannot find name 'Node'.
# Error: node_modules/flatpickr/dist/types/instance.d.ts(82,56): error TS2304: Cannot find name 'HTMLElementTagNameMap'.
# Error: node_modules/@types/carbon-components-react/lib/components/FileUploader/FileUploaderDropContainer.d.ts(46,80): error TS2304: Cannot find name 'File'.
# Error: node_modules/@types/overlayscrollbars/index.d.ts(348,19): error TS2304: Cannot find name 'NodeListOf'.
- name: Modify cdk-construct tsconfig.json
run: |
mv ./packages/cdk-construct/tsconfig.json ./packages/cdk-construct/tsconfig.jsii.json
jq ".compilerOptions += { \"skipLibCheck\": true }" ./packages/cdk-construct/tsconfig.jsii.json > ./packages/cdk-construct/tsconfig.json
# Applying the version allows us to use the version in the CDK construct
- name: Apply NPM Version to Everything
run: |
npm version ${{ needs.version.outputs.packageVersion }} \
--no-git-tag-version --allow-same-version
npm version ${{ needs.version.outputs.packageVersion }} \
--no-git-tag-version --allow-same-version --workspaces
- name: Build All TypeScript
run: npm run build
- name: Download Artifact - App
uses: actions/download-artifact@v3
with:
name: app_zip
path: packages/cdk-construct/lib/
- name: Unzip Artifact - App
working-directory: packages/cdk-construct/lib/
run: unzip -o nextjs.zip
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-session-name: microapps-app-${{ env.APP_NAME }}-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Preflight Check Version - App
run: |
npx microapps-publish preflight \
--app-name ${APP_NAME} \
--new-version ${{ needs.version.outputs.packageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--overwrite
- name: Set Hotswap Flag
run: |
if [ -n "${PR_NUMBER}" ]; then
echo "HOTSWAP_FLAG=--hotswap-fallback" >> $GITHUB_ENV
else
echo "HOTSWAP_FLAG=" >> $GITHUB_ENV
fi
- name: Deploy CDK Stack - App
run: |
npx cdk deploy ${CDK_CONTEXT_ARGS} ${HOTSWAP_FLAG} \
--require-approval never app
- name: Publish to MicroApps - App
run: |
npx microapps-publish publish \
--app-name ${APP_NAME} \
--type lambda-url \
--startup-type direct \
--new-version ${{ needs.version.outputs.packageVersion }} \
--deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} \
--app-lambda-name microapps-app-${APP_NAME}-${ENV}${{ needs.version.outputs.prSuffix }} \
--static-assets-path packages/cdk-construct/lib/${APP_CONSTRUCT_FOLDER_NAME}/static_files \
--overwrite
- name: App URL
uses: Sibz/github-status-action@v1
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'App URL'
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
target_url: https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}?appver=${{ needs.version.outputs.packageVersion }}
- name: Test App
run: |
echo Testing App HTML Loading
curl -H"accept: text/html" --fail https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}?appver=${{ needs.version.outputs.packageVersion }}
echo "\nTesting App Method Invocation"
curl -H"accept: application/json" --fail https://apps.ghpublic.pwrdrvr.com/${{ env.APP_NAME }}/${{ needs.version.outputs.packageVersion }}/api/refresh/${{ env.APP_NAME }}