Skip to content

Commit 1686123

Browse files
authored
ci(repo): add e2e-staging workflow for clerk_go deploy validation (#8051)
1 parent b7e6308 commit 1686123

2 files changed

Lines changed: 277 additions & 0 deletions

File tree

.changeset/floppy-rabbits-tease.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/e2e-staging.yml

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
name: E2E Staging
2+
3+
on:
4+
repository_dispatch:
5+
types: [staging-deploy]
6+
workflow_dispatch:
7+
inputs:
8+
ref:
9+
description: "Branch to test against"
10+
required: false
11+
default: "main"
12+
type: string
13+
clerk-go-commit-sha:
14+
description: "clerk_go commit SHA for status reporting"
15+
required: false
16+
type: string
17+
sdk-source:
18+
description: "SDK source: 'latest' uses published @latest from npm, 'ref' builds from the checked-out branch"
19+
required: false
20+
default: "latest"
21+
type: choice
22+
options:
23+
- latest
24+
- ref
25+
notify-slack:
26+
description: "Send Slack notification on failure"
27+
required: false
28+
default: true
29+
type: boolean
30+
31+
permissions:
32+
contents: read
33+
actions: write
34+
35+
concurrency:
36+
group: ${{ github.workflow }}-${{ github.event.inputs.ref || github.event.client_payload.ref || 'main' }}
37+
cancel-in-progress: true
38+
39+
jobs:
40+
integration-tests:
41+
name: Integration Tests (${{ matrix.test-name }}, ${{ matrix.test-project }})
42+
runs-on: "blacksmith-8vcpu-ubuntu-2204"
43+
defaults:
44+
run:
45+
shell: bash
46+
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_LONG && fromJSON(vars.TIMEOUT_MINUTES_LONG) || 15 }}
47+
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
test-name:
52+
- "sessions:staging"
53+
- "handshake:staging"
54+
test-project: ["chrome"]
55+
56+
steps:
57+
- name: Normalize inputs
58+
id: inputs
59+
env:
60+
EVENT_NAME: ${{ github.event_name }}
61+
INPUT_REF: ${{ github.event.inputs.ref }}
62+
INPUT_COMMIT_SHA: ${{ github.event.inputs.clerk-go-commit-sha }}
63+
INPUT_NOTIFY_SLACK: ${{ github.event.inputs.notify-slack }}
64+
INPUT_SDK_SOURCE: ${{ github.event.inputs.sdk-source }}
65+
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
66+
PAYLOAD_COMMIT_SHA: ${{ github.event.client_payload.clerk-go-commit-sha }}
67+
PAYLOAD_NOTIFY_SLACK: ${{ github.event.client_payload.notify-slack }}
68+
PAYLOAD_SDK_SOURCE: ${{ github.event.client_payload.sdk-source }}
69+
run: |
70+
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
71+
echo "ref=${INPUT_REF:-main}" >> $GITHUB_OUTPUT
72+
echo "clerk-go-commit-sha=$INPUT_COMMIT_SHA" >> $GITHUB_OUTPUT
73+
echo "notify-slack=$INPUT_NOTIFY_SLACK" >> $GITHUB_OUTPUT
74+
echo "sdk-source=${INPUT_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
75+
else
76+
echo "ref=${PAYLOAD_REF:-main}" >> $GITHUB_OUTPUT
77+
echo "clerk-go-commit-sha=${PAYLOAD_COMMIT_SHA:-}" >> $GITHUB_OUTPUT
78+
echo "notify-slack=${PAYLOAD_NOTIFY_SLACK:-true}" >> $GITHUB_OUTPUT
79+
echo "sdk-source=${PAYLOAD_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
80+
fi
81+
82+
- name: Validate ref
83+
env:
84+
REF: ${{ steps.inputs.outputs.ref }}
85+
run: |
86+
if [[ ! "$REF" =~ ^(main|release/.*)$ ]]; then
87+
echo "::error::Ref '$REF' is not allowed. Only 'main' and 'release/*' branches are permitted."
88+
exit 1
89+
fi
90+
91+
- name: Checkout Repo
92+
uses: actions/checkout@v4
93+
with:
94+
ref: ${{ steps.inputs.outputs.ref }}
95+
fetch-depth: 1
96+
fetch-tags: false
97+
filter: "blob:none"
98+
show-progress: false
99+
100+
- name: Setup
101+
id: config
102+
uses: ./.github/actions/init-blacksmith
103+
with:
104+
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
105+
turbo-team: ${{ vars.TURBO_TEAM }}
106+
turbo-token: ${{ secrets.TURBO_TOKEN }}
107+
playwright-enabled: true
108+
109+
- name: Verify jq is installed
110+
run: |
111+
if ! command -v jq &> /dev/null; then
112+
echo "jq not found, installing..."
113+
sudo apt-get update && sudo apt-get install -y jq
114+
fi
115+
jq --version
116+
117+
# --- SDK from ref: build from source and publish to local registry ---
118+
- name: Build packages
119+
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
120+
run: pnpm turbo build $TURBO_ARGS --only
121+
122+
- name: Publish to local registry
123+
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
124+
run: pkglab pub --force
125+
126+
- name: Edit .npmrc [link-workspace-packages=false]
127+
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
128+
run: sed -i -E 's/link-workspace-packages=(deep|true)/link-workspace-packages=false/' .npmrc
129+
130+
- name: Install @clerk/clerk-js from local registry
131+
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
132+
working-directory: ${{ runner.temp }}
133+
run: |
134+
mkdir clerk-js && cd clerk-js
135+
pnpm init
136+
pkglab add @clerk/clerk-js
137+
138+
- name: Install @clerk/ui from local registry
139+
if: ${{ steps.inputs.outputs.sdk-source == 'ref' }}
140+
working-directory: ${{ runner.temp }}
141+
run: |
142+
mkdir clerk-ui && cd clerk-ui
143+
pnpm init
144+
pkglab add @clerk/ui
145+
146+
# --- SDK from npm: install @latest published versions ---
147+
- name: Install @clerk/clerk-js@latest from npm
148+
if: ${{ steps.inputs.outputs.sdk-source == 'latest' }}
149+
working-directory: ${{ runner.temp }}
150+
run: |
151+
mkdir clerk-js && cd clerk-js
152+
pnpm init
153+
pnpm add @clerk/clerk-js@latest
154+
155+
- name: Install @clerk/ui@latest from npm
156+
if: ${{ steps.inputs.outputs.sdk-source == 'latest' }}
157+
working-directory: ${{ runner.temp }}
158+
run: |
159+
mkdir clerk-ui && cd clerk-ui
160+
pnpm init
161+
pnpm add @clerk/ui@latest
162+
163+
- name: Write all ENV certificates to files in integration/certs
164+
uses: actions/github-script@v7
165+
env:
166+
INTEGRATION_CERTS: "${{ secrets.INTEGRATION_CERTS }}"
167+
INTEGRATION_ROOT_CA: "${{ secrets.INTEGRATION_ROOT_CA }}"
168+
with:
169+
script: |
170+
const fs = require('fs');
171+
const path = require('path');
172+
const rootCa = process.env.INTEGRATION_ROOT_CA;
173+
if (!rootCa) {
174+
core.setFailed('INTEGRATION_ROOT_CA secret is not set');
175+
return;
176+
}
177+
fs.writeFileSync(path.join(process.env.GITHUB_WORKSPACE, 'integration/certs', 'rootCA.pem'), rootCa);
178+
const certs = JSON.parse(process.env.INTEGRATION_CERTS);
179+
for (const [name, cert] of Object.entries(certs)) {
180+
fs.writeFileSync(path.join(process.env.GITHUB_WORKSPACE, 'integration/certs', name), cert);
181+
}
182+
183+
- name: Run Integration Tests
184+
id: integration-tests
185+
timeout-minutes: 25
186+
run: pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS
187+
env:
188+
E2E_DEBUG: "1"
189+
E2E_APP_CLERK_JS_DIR: ${{ runner.temp }}
190+
E2E_APP_CLERK_UI_DIR: ${{ runner.temp }}
191+
E2E_CLERK_JS_VERSION: "latest"
192+
E2E_CLERK_UI_VERSION: "latest"
193+
E2E_PROJECT: ${{ matrix.test-project }}
194+
INTEGRATION_INSTANCE_KEYS: ${{ secrets.INTEGRATION_INSTANCE_KEYS }}
195+
NODE_EXTRA_CA_CERTS: ${{ github.workspace }}/integration/certs/rootCA.pem
196+
197+
- name: Upload test-results
198+
if: ${{ cancelled() || failure() }}
199+
uses: actions/upload-artifact@v4
200+
with:
201+
name: playwright-traces-${{ github.run_id }}-${{ github.run_attempt }}-${{ replace(matrix.test-name, ':', '-') }}
202+
path: integration/test-results
203+
retention-days: 1
204+
205+
report:
206+
name: Report Results
207+
needs: [integration-tests]
208+
if: always()
209+
runs-on: "blacksmith-8vcpu-ubuntu-2204"
210+
defaults:
211+
run:
212+
shell: bash
213+
214+
steps:
215+
- name: Normalize inputs
216+
id: inputs
217+
env:
218+
EVENT_NAME: ${{ github.event_name }}
219+
INPUT_REF: ${{ github.event.inputs.ref }}
220+
INPUT_COMMIT_SHA: ${{ github.event.inputs.clerk-go-commit-sha }}
221+
INPUT_NOTIFY_SLACK: ${{ github.event.inputs.notify-slack }}
222+
INPUT_SDK_SOURCE: ${{ github.event.inputs.sdk-source }}
223+
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
224+
PAYLOAD_COMMIT_SHA: ${{ github.event.client_payload.clerk-go-commit-sha }}
225+
PAYLOAD_NOTIFY_SLACK: ${{ github.event.client_payload.notify-slack }}
226+
PAYLOAD_SDK_SOURCE: ${{ github.event.client_payload.sdk-source }}
227+
run: |
228+
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
229+
echo "ref=${INPUT_REF:-main}" >> $GITHUB_OUTPUT
230+
echo "clerk-go-commit-sha=$INPUT_COMMIT_SHA" >> $GITHUB_OUTPUT
231+
echo "notify-slack=$INPUT_NOTIFY_SLACK" >> $GITHUB_OUTPUT
232+
echo "sdk-source=${INPUT_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
233+
else
234+
echo "ref=${PAYLOAD_REF:-main}" >> $GITHUB_OUTPUT
235+
echo "clerk-go-commit-sha=${PAYLOAD_COMMIT_SHA:-}" >> $GITHUB_OUTPUT
236+
echo "notify-slack=${PAYLOAD_NOTIFY_SLACK:-true}" >> $GITHUB_OUTPUT
237+
echo "sdk-source=${PAYLOAD_SDK_SOURCE:-latest}" >> $GITHUB_OUTPUT
238+
fi
239+
240+
- name: Notify Slack on failure
241+
if: ${{ needs.integration-tests.result == 'failure' && steps.inputs.outputs.notify-slack == 'true' }}
242+
uses: slackapi/slack-github-action@v1.24.0
243+
with:
244+
payload: |
245+
{
246+
"blocks": [
247+
{
248+
"type": "section",
249+
"text": {
250+
"type": "mrkdwn",
251+
"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>"
252+
}
253+
}
254+
]
255+
}
256+
env:
257+
SLACK_WEBHOOK_URL: ${{ secrets.SDK_SLACKER_WEBHOOK_URL }}
258+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
259+
260+
# Uncomment when clerk_go side is ready
261+
# - name: Post commit status to clerk_go
262+
# if: ${{ steps.inputs.outputs.clerk-go-commit-sha != '' }}
263+
# uses: actions/github-script@v7
264+
# with:
265+
# github-token: ${{ secrets.CLERK_COOKIE_PAT }}
266+
# script: |
267+
# await github.rest.repos.createCommitStatus({
268+
# owner: 'clerk',
269+
# repo: 'clerk_go',
270+
# sha: '${{ steps.inputs.outputs.clerk-go-commit-sha }}',
271+
# state: '${{ needs.integration-tests.result == 'success' && 'success' || 'failure' }}',
272+
# target_url: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
273+
# context: 'e2e-staging / clerk-javascript',
274+
# description: 'JS SDK e2e tests against staging'
275+
# });

0 commit comments

Comments
 (0)