-
Notifications
You must be signed in to change notification settings - Fork 3
283 lines (251 loc) · 11.6 KB
/
deploy-playground-and-test.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
name: Deploy Playground Apps to Vercel and Test on React
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
BRANCH_NAME_RAW: ${{ github.head_ref || github.ref_name }}
on:
pull_request:
push:
branches:
- develop
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-force-1
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: Install Dependencies
run: |
npm i
npm install lerna
npm install [email protected]
npm list
- name: Check ESLint Errors
run: npm run lint
- name: Check Prettier Formatting
run: npm run prettier:check
- name: Build SDKs
run: |
npm run build
npm run build:bundler:local
- name: Normalize branch name
run: |
echo "BRANCH_NAME=$(echo $BRANCH_NAME_RAW | tr '/_' '-')" >> "$GITHUB_ENV"
shell: bash
- name: Deploy react playground to Vercel
run: |
npx vercel link --yes --project react-playground --scope corbado -t $VERCEL_TOKEN
npx vercel pull -t $VERCEL_TOKEN
npx vercel build -t $VERCEL_TOKEN
url="$(npx vercel deploy --prebuilt -t ${{ secrets.VERCEL_TOKEN }})"
npx vercel alias -S corbado -t ${{ secrets.VERCEL_TOKEN }} "$url" $BRANCH_NAME.react.playground.corbado.io
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_REACT_PLAYGROUND }}
- name: Deploy connect next playground to Vercel
run: |
npx vercel link --yes --project connect-next-playground --scope corbado -t $VERCEL_TOKEN
npx vercel pull --environment=preview -t $VERCEL_TOKEN
npx vercel build -t $VERCEL_TOKEN
url="$(npx vercel deploy --prebuilt -t ${{ secrets.VERCEL_TOKEN }})"
npx vercel alias -S corbado -t ${{ secrets.VERCEL_TOKEN }} "$url" $BRANCH_NAME.connect-next.playground.corbado.io
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_CONNECT_NEXT_PLAYGROUND }}
- name: Deploy web-js playground to Vercel
run: |
npx vercel link --yes --project web-js-playground --scope corbado -t $VERCEL_TOKEN
npx vercel pull -t $VERCEL_TOKEN
npx vercel build -t $VERCEL_TOKEN
url="$(npx vercel deploy --prebuilt -t ${{ secrets.VERCEL_TOKEN }})"
npx vercel alias -S corbado -t ${{ secrets.VERCEL_TOKEN }} "$url" $BRANCH_NAME.web-js.playground.corbado.io
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB_JS_PLAYGROUND }}
- name: Deploy web-js-script playground to Vercel
run: |
npx vercel link --yes --project web-js-script-playground --scope corbado -t $VERCEL_TOKEN
npx vercel pull -t $VERCEL_TOKEN
npx vercel build -t $VERCEL_TOKEN
url="$(npx vercel deploy --prebuilt -t ${{ secrets.VERCEL_TOKEN }})"
npx vercel alias -S corbado -t ${{ secrets.VERCEL_TOKEN }} "$url" $BRANCH_NAME.web-js-script.playground.corbado.io
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB_JS_SCRIPT_PLAYGROUND }}
test:
needs: deploy
timeout-minutes: 60
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
- name: Get installed Playwright version
id: playwright-version
run: echo "::set-output name=version::$(yarn why --json @playwright/test | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://')"
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: |
cd packages/tests-e2e
npm list
- name: Install Dependencies
run: |
cd packages/tests-e2e
npm install
sudo apt-get update
sudo apt-get install -y libxml2-utils
- uses: actions/cache@v3
id: playwright-cache
with:
path: '~/.cache/ms-playwright'
key: '${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}'
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright's dependencies
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: |
cd packages/tests-e2e
npx playwright install --with-deps
- name: Create a log stream on AWS CloudWatch
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
TIMESTAMP=$(date +%s000)
echo "LOG_STREAM_NAME=javascript-$TIMESTAMP" >> $GITHUB_ENV
aws logs create-log-stream --log-group-name "test-results-board" --log-stream-name "javascript-$TIMESTAMP"
- name: Run Complete tests for react
run: |
cd packages/tests-e2e
BRANCH_NAME=$(echo $BRANCH_NAME_RAW | tr '/_' '-')
export PLAYWRIGHT_TEST_URL="https://$BRANCH_NAME.react.playground.corbado.io"
set +e
npx playwright test --config=playwright.config.complete.ts
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "COMPLETE_REACT_FAILED=true" >> $GITHUB_ENV
fi
env:
PLAYWRIGHT_NUM_CORES: 4
PLAYWRIGHT_JWT_TOKEN: ${{ secrets.PLAYWRIGHT_JWT_TOKEN }}
PLAYWRIGHT_GOOGLE_EMAIL: ${{ secrets.PLAYWRIGHT_GOOGLE_EMAIL }}
PLAYWRIGHT_GOOGLE_PASSWORD: ${{ secrets.PLAYWRIGHT_GOOGLE_PASSWORD }}
PLAYWRIGHT_GOOGLE_TOTP_SECRET: ${{ secrets.PLAYWRIGHT_GOOGLE_TOTP_SECRET }}
GITHUB_RUN_ID: ${{ github.run_id }}
SLACK_BOT_USER_OAUTH_TOKEN: ${{ secrets.SLACK_BOT_USER_OAUTH_TOKEN }}
GITHUB_BRANCH_NAME: ${{ github.ref_name }}
continue-on-error: true
- uses: actions/upload-artifact@v4
with:
name: playwright-report-complete-react
path: packages/tests-e2e/playwright-report/
retention-days: 30
- name: Send logs to AWS CloudWatch
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
cd packages/tests-e2e
TESTS=$(xmllint --xpath 'string(/testsuites/@tests)' test-results/results.xml)
FAILURES=$(xmllint --xpath 'string(/testsuites/@failures)' test-results/results.xml)
SKIPPED=$(xmllint --xpath 'string(/testsuites/@skipped)' test-results/results.xml)
ERRORS=$(xmllint --xpath 'string(/testsuites/@errors)' test-results/results.xml)
TIME=$(xmllint --xpath 'string(/testsuites/@time)' test-results/results.xml)
PASSED=$((TESTS - FAILURES - ERRORS - SKIPPED))
FAILED=$((FAILURES + ERRORS))
TIMESTAMP=$(date +%s000)
LOG_EVENT_JSON="[{\"timestamp\":$TIMESTAMP,\"message\":\"{\\\"application\\\":\\\"complete\\\",\\\"platform\\\":\\\"react\\\",\\\"run_type\\\":\\\"commitly\\\",\\\"execution_time\\\":$TIME,\\\"passed\\\":$PASSED,\\\"failed\\\":$FAILED,\\\"link\\\":\\\"https://github.com/corbado/javascript/actions/runs/${GITHUB_RUN_ID}\\\"}\"}]"
aws logs put-log-events --log-group-name "test-results-board" --log-stream-name "$LOG_STREAM_NAME" --log-events "$LOG_EVENT_JSON"
- name: Run Connect tests for react
run: |
cd packages/tests-e2e
BRANCH_NAME=$(echo $BRANCH_NAME_RAW | tr '/_' '-')
export PLAYWRIGHT_TEST_URL="https://$BRANCH_NAME.connect-next.playground.corbado.io"
set +e
npx playwright test --config=playwright.config.connect.ts
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "CONNECT_REACT_FAILED=true" >> $GITHUB_ENV
fi
env:
PLAYWRIGHT_NUM_CORES: 4
BACKEND_API_BASIC_AUTH: ${{ secrets.BACKEND_API_BASIC_AUTH }}
PLAYWRIGHT_CONNECT_PROJECT_ID: ${{ secrets.PLAYWRIGHT_CONNECT_PROJECT_ID }}
PLAYWRIGHT_NGROK_AUTH_TOKEN: ${{ secrets.PLAYWRIGHT_NGROK_AUTH_TOKEN }}
GITHUB_RUN_ID: ${{ github.run_id }}
SLACK_BOT_USER_OAUTH_TOKEN: ${{ secrets.SLACK_BOT_USER_OAUTH_TOKEN }}
GITHUB_BRANCH_NAME: ${{ env.BRANCH_NAME_RAW }}
continue-on-error: true
- uses: actions/upload-artifact@v4
with:
name: playwright-report-connect-react
path: packages/tests-e2e/playwright-report/
retention-days: 30
- name: Send logs to AWS CloudWatch
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
cd packages/tests-e2e
TESTS=$(xmllint --xpath 'string(/testsuites/@tests)' test-results/results.xml)
FAILURES=$(xmllint --xpath 'string(/testsuites/@failures)' test-results/results.xml)
SKIPPED=$(xmllint --xpath 'string(/testsuites/@skipped)' test-results/results.xml)
ERRORS=$(xmllint --xpath 'string(/testsuites/@errors)' test-results/results.xml)
TIME=$(xmllint --xpath 'string(/testsuites/@time)' test-results/results.xml)
PASSED=$((TESTS - FAILURES - ERRORS - SKIPPED))
FAILED=$((FAILURES + ERRORS))
TIMESTAMP=$(date +%s000)
LOG_EVENT_JSON="[{\"timestamp\":$TIMESTAMP,\"message\":\"{\\\"application\\\":\\\"connect\\\",\\\"platform\\\":\\\"react\\\",\\\"run_type\\\":\\\"commitly\\\",\\\"execution_time\\\":$TIME,\\\"passed\\\":$PASSED,\\\"failed\\\":$FAILED,\\\"link\\\":\\\"https://github.com/corbado/javascript/actions/runs/${GITHUB_RUN_ID}\\\"}\"}]"
aws logs put-log-events --log-group-name "test-results-board" --log-stream-name "$LOG_STREAM_NAME" --log-events "$LOG_EVENT_JSON"
- name: Aggregate results
run: |
FAILED_STEPS=""
if [ "${COMPLETE_REACT_FAILED}" = "true" ]; then
FAILED_STEPS="${FAILED_STEPS} Complete-React"
fi
if [ "${COMPLETE_WEBJS_FAILED}" = "true" ]; then
FAILED_STEPS="${FAILED_STEPS} Complete-WebJs"
fi
if [ "${COMPLETE_WEBJSSCRIPT_FAILED}" = "true" ]; then
FAILED_STEPS="${FAILED_STEPS} Complete-WebJsScript"
fi
if [ "${CONNECT_REACT_FAILED}" = "true" ]; then
FAILED_STEPS="${FAILED_STEPS} Connect-React"
fi
if [ -n "$FAILED_STEPS" ]; then
echo "The following test steps have failed: $FAILED_STEPS"
exit 1
else
echo "All tests passed."
fi