-
Notifications
You must be signed in to change notification settings - Fork 444
363 lines (332 loc) · 13.9 KB
/
e2e-staging.yml
File metadata and controls
363 lines (332 loc) · 13.9 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
name: E2E Staging
on:
repository_dispatch:
types: [staging-deploy]
workflow_dispatch:
inputs:
ref:
description: 'Branch to test against'
required: false
default: 'main'
type: string
clerk-go-commit-sha:
description: 'clerk_go commit SHA for status reporting'
required: false
type: string
sdk-source:
description: "SDK source: 'latest' uses published @latest from npm, 'ref' builds from the checked-out branch"
required: false
default: 'latest'
type: choice
options:
- latest
- ref
notify-slack:
description: 'Send Slack notification on failure'
required: false
default: true
type: boolean
permissions:
contents: read
actions: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.ref || github.event.client_payload.ref || 'main' }}
cancel-in-progress: true
jobs:
permissions-check:
name: Check Permissions
if: ${{ github.event_name != 'repository_dispatch' }}
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
steps:
- name: Check org membership
uses: actions/github-script@v7
with:
script: |
const org = context.repo.owner;
const username = process.env.GITHUB_TRIGGERING_ACTOR || context.actor;
try {
const { status } = await github.rest.orgs.checkMembershipForUser({
org,
username,
});
if (status !== 204) {
core.setFailed(`User '${username}' is not a member of the '${org}' organization.`);
}
} catch (error) {
if (error?.status === 404) {
core.setFailed(`User '${username}' is not a member of the '${org}' organization.`);
} else {
core.setFailed(
`Org membership check failed for '${username}' in '${org}' (status: ${error?.status ?? 'unknown'}): ${error?.message ?? 'unknown error'}`
);
}
}
validate-instances:
name: Validate Staging Instances
needs: [permissions-check]
if: ${{ always() && (needs.permissions-check.result == 'success' || needs.permissions-check.result == 'skipped') }}
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
steps:
- name: Normalize inputs
id: inputs
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_REF: ${{ github.event.inputs.ref }}
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
echo "ref=${INPUT_REF:-main}" >> $GITHUB_OUTPUT
else
echo "ref=${PAYLOAD_REF:-main}" >> $GITHUB_OUTPUT
fi
- name: Validate ref
env:
REF: ${{ steps.inputs.outputs.ref }}
run: |
if [[ ! "$REF" =~ ^(main|release/.*)$ ]]; then
echo "::error::Ref '$REF' is not allowed. Only 'main' and 'release/*' branches are permitted."
exit 1
fi
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: ${{ steps.inputs.outputs.ref }}
sparse-checkout: scripts/validate-staging-instances.mjs
fetch-depth: 1
- name: Validate staging instance settings
run: node scripts/validate-staging-instances.mjs
env:
INTEGRATION_INSTANCE_KEYS: ${{ secrets.INTEGRATION_INSTANCE_KEYS }}
INTEGRATION_STAGING_INSTANCE_KEYS: ${{ secrets.INTEGRATION_STAGING_INSTANCE_KEYS }}
integration-tests:
name: Integration Tests (${{ matrix.test-name }}, ${{ matrix.test-project }})
needs: [permissions-check]
if: ${{ always() && (needs.permissions-check.result == 'success' || needs.permissions-check.result == 'skipped') }}
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
defaults:
run:
shell: bash
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_LONG && fromJSON(vars.TIMEOUT_MINUTES_LONG) || 15 }}
strategy:
fail-fast: false
max-parallel: 3
matrix:
test-name:
- 'sessions:staging'
- 'handshake:staging'
- 'generic'
- 'cache-components'
- 'express'
- 'hono'
- 'quickstart'
- 'react-router'
- 'tanstack-react-start'
test-project: ['chrome']
steps:
- name: Normalize inputs
id: inputs
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_REF: ${{ github.event.inputs.ref }}
INPUT_COMMIT_SHA: ${{ github.event.inputs.clerk-go-commit-sha }}
INPUT_NOTIFY_SLACK: ${{ github.event.inputs.notify-slack }}
INPUT_SDK_SOURCE: ${{ github.event.inputs.sdk-source }}
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
PAYLOAD_COMMIT_SHA: ${{ github.event.client_payload.clerk-go-commit-sha }}
PAYLOAD_NOTIFY_SLACK: ${{ github.event.client_payload.notify-slack }}
PAYLOAD_SDK_SOURCE: ${{ github.event.client_payload.sdk-source }}
TEST_NAME: ${{ matrix.test-name }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
echo "ref=${INPUT_REF:-main}" >> $GITHUB_OUTPUT
echo "clerk-go-commit-sha=$INPUT_COMMIT_SHA" >> $GITHUB_OUTPUT
echo "notify-slack=$INPUT_NOTIFY_SLACK" >> $GITHUB_OUTPUT
echo "sdk-source=${INPUT_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
else
echo "ref=${PAYLOAD_REF:-main}" >> $GITHUB_OUTPUT
echo "clerk-go-commit-sha=${PAYLOAD_COMMIT_SHA:-}" >> $GITHUB_OUTPUT
echo "notify-slack=${PAYLOAD_NOTIFY_SLACK:-true}" >> $GITHUB_OUTPUT
echo "sdk-source=${PAYLOAD_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
fi
echo "artifact-suffix=${TEST_NAME//:/-}" >> $GITHUB_OUTPUT
- name: Validate ref
env:
REF: ${{ steps.inputs.outputs.ref }}
run: |
if [[ ! "$REF" =~ ^(main|release/.*)$ ]]; then
echo "::error::Ref '$REF' is not allowed. Only 'main' and 'release/*' branches are permitted."
exit 1
fi
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: ${{ steps.inputs.outputs.ref }}
fetch-depth: 1
fetch-tags: false
filter: 'blob:none'
show-progress: false
- name: Setup
id: config
uses: ./.github/actions/init-blacksmith
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
playwright-enabled: true
- name: Verify jq is installed
run: |
if ! command -v jq &> /dev/null; then
echo "jq not found, installing..."
sudo apt-get update && sudo apt-get install -y jq
fi
jq --version
- name: Build packages
run: pnpm turbo build $TURBO_ARGS --only
# --- SDK from ref: publish to local registry ---
- name: Publish to local registry
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
run: pkglab pub --force
- name: Edit .npmrc [link-workspace-packages=false]
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
run: sed -i -E 's/link-workspace-packages=(deep|true)/link-workspace-packages=false/' .npmrc
- name: Install @clerk/clerk-js from local registry
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
working-directory: ${{ runner.temp }}
run: |
mkdir clerk-js && cd clerk-js
pnpm init
pkglab add @clerk/clerk-js
- name: Install @clerk/ui from local registry
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
working-directory: ${{ runner.temp }}
run: |
mkdir clerk-ui && cd clerk-ui
pnpm init
pkglab add @clerk/ui
# --- SDK from npm: install @latest published versions ---
- name: Install @clerk/clerk-js@latest from npm
if: ${{ steps.inputs.outputs.sdk-source == 'latest' }}
working-directory: ${{ runner.temp }}
run: |
mkdir clerk-js && cd clerk-js
pnpm init
pnpm add @clerk/clerk-js@latest
- name: Install @clerk/ui@latest from npm
if: ${{ steps.inputs.outputs.sdk-source == 'latest' }}
working-directory: ${{ runner.temp }}
run: |
mkdir clerk-ui && cd clerk-ui
pnpm init
pnpm add @clerk/ui@latest
- name: Write all ENV certificates to files in integration/certs
uses: actions/github-script@v7
env:
INTEGRATION_CERTS: '${{ secrets.INTEGRATION_CERTS }}'
INTEGRATION_ROOT_CA: '${{ secrets.INTEGRATION_ROOT_CA }}'
with:
script: |
const fs = require('fs');
const path = require('path');
const rootCa = process.env.INTEGRATION_ROOT_CA;
if (!rootCa) {
core.setFailed('INTEGRATION_ROOT_CA secret is not set');
return;
}
fs.writeFileSync(path.join(process.env.GITHUB_WORKSPACE, 'integration/certs', 'rootCA.pem'), rootCa);
const certs = JSON.parse(process.env.INTEGRATION_CERTS);
for (const [name, cert] of Object.entries(certs)) {
fs.writeFileSync(path.join(process.env.GITHUB_WORKSPACE, 'integration/certs', name), cert);
}
- name: Run Integration Tests
id: integration-tests
timeout-minutes: 25
run: pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS
env:
E2E_DEBUG: '1'
E2E_STAGING: '1'
E2E_WORKERS: '2'
E2E_SDK_SOURCE: ${{ steps.inputs.outputs.sdk-source }}
E2E_APP_CLERK_JS_DIR: ${{ runner.temp }}
E2E_APP_CLERK_UI_DIR: ${{ runner.temp }}
E2E_CLERK_JS_VERSION: 'latest'
E2E_CLERK_UI_VERSION: 'latest'
E2E_PROJECT: ${{ matrix.test-project }}
INTEGRATION_INSTANCE_KEYS: ${{ secrets.INTEGRATION_INSTANCE_KEYS }}
INTEGRATION_STAGING_INSTANCE_KEYS: ${{ secrets.INTEGRATION_STAGING_INSTANCE_KEYS }}
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
NODE_EXTRA_CA_CERTS: ${{ github.workspace }}/integration/certs/rootCA.pem
- name: Upload test-results
if: ${{ cancelled() || failure() }}
uses: actions/upload-artifact@v4
with:
name: playwright-traces-${{ github.run_id }}-${{ github.run_attempt }}-${{ steps.inputs.outputs.artifact-suffix }}
path: test-results
retention-days: 1
report:
name: Report Results
needs: [integration-tests]
if: always()
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
defaults:
run:
shell: bash
steps:
- name: Normalize inputs
id: inputs
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_REF: ${{ github.event.inputs.ref }}
INPUT_COMMIT_SHA: ${{ github.event.inputs.clerk-go-commit-sha }}
INPUT_NOTIFY_SLACK: ${{ github.event.inputs.notify-slack }}
INPUT_SDK_SOURCE: ${{ github.event.inputs.sdk-source }}
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
PAYLOAD_COMMIT_SHA: ${{ github.event.client_payload.clerk-go-commit-sha }}
PAYLOAD_NOTIFY_SLACK: ${{ github.event.client_payload.notify-slack }}
PAYLOAD_SDK_SOURCE: ${{ github.event.client_payload.sdk-source }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
echo "ref=${INPUT_REF:-main}" >> $GITHUB_OUTPUT
echo "clerk-go-commit-sha=$INPUT_COMMIT_SHA" >> $GITHUB_OUTPUT
echo "notify-slack=$INPUT_NOTIFY_SLACK" >> $GITHUB_OUTPUT
echo "sdk-source=${INPUT_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
else
echo "ref=${PAYLOAD_REF:-main}" >> $GITHUB_OUTPUT
echo "clerk-go-commit-sha=${PAYLOAD_COMMIT_SHA:-}" >> $GITHUB_OUTPUT
echo "notify-slack=${PAYLOAD_NOTIFY_SLACK:-true}" >> $GITHUB_OUTPUT
echo "sdk-source=${PAYLOAD_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
fi
- name: Notify Slack on failure
if: ${{ needs.integration-tests.result == 'failure' && steps.inputs.outputs.notify-slack == 'true' }}
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*:red_circle: Staging E2E tests failed*\n*Repo:* `${{ github.repository }}`\n*Ref:* `${{ steps.inputs.outputs.ref }}`\n*SDK:* `${{ steps.inputs.outputs.sdk-source }}`\n*clerk_go commit:* `${{ steps.inputs.outputs.clerk-go-commit-sha || 'N/A' }}`\n*Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.STAGING_E2E_SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
# Uncomment when clerk_go side is ready
# - name: Post commit status to clerk_go
# if: ${{ steps.inputs.outputs.clerk-go-commit-sha != '' }}
# uses: actions/github-script@v7
# with:
# github-token: ${{ secrets.CLERK_COOKIE_PAT }}
# script: |
# await github.rest.repos.createCommitStatus({
# owner: 'clerk',
# repo: 'clerk_go',
# sha: '${{ steps.inputs.outputs.clerk-go-commit-sha }}',
# state: '${{ needs.integration-tests.result == 'success' && 'success' || 'failure' }}',
# target_url: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
# context: 'e2e-staging / clerk-javascript',
# description: 'JS SDK e2e tests against staging'
# });