Skip to content

Commit 267d950

Browse files
LekoArtsbrkalow
andauthored
chore: Add "Deploy Preview" GitHub workflow (clerk#2079)
* chore(repo): Fix linting of scripts chore(repo): Add install site in isolation script chore(repo): Globally install secco chore(repo): Begin preview workflow chore(repo): Use actions/core chore(backend): Use cpy instead of rsync chore(repo): Update nextjs playground chore(repo): Add missing dep to nextjs playground chore(repo): Update lock file * chore(repo): Finish preview workflow * chore(repo): Add empty changeset * chore(*): Add debug thing to test * testing * testing * testing * testing * chore(repo): Reset testing stuff * chore(repo): Update lockfile * Update .github/workflows/preview.yml Co-authored-by: Bryce Kalow <bryce@clerk.dev> --------- Co-authored-by: Bryce Kalow <bryce@clerk.dev>
1 parent 3c42090 commit 267d950

13 files changed

+480
-9
lines changed

.changeset/cuddly-fireants-switch.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/preview.yml

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Deploy Preview
2+
run-name: Deploy Preview by ${{ github.actor }}
3+
4+
env:
5+
COMMENT_HEADER: javascript-preview
6+
7+
on:
8+
issue_comment:
9+
types: [created]
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
preview:
17+
if: ${{ startsWith(github.event.comment.body, '!preview') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
18+
runs-on: ${{ vars.RUNNER_NORMAL }}
19+
timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_NORMAL) }}
20+
21+
env:
22+
VERCEL_ORG_ID: ${{ secrets.VERCEL_CLERK_PROD_ORG_ID }}
23+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_JS_PREVIEW_PROJECT_ID }}
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
steps:
28+
- name: Limit action to Clerk members
29+
uses: actions/github-script@v6
30+
with:
31+
result-encoding: string
32+
retries: 3
33+
retry-exempt-status-codes: 400,401
34+
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
35+
script: |
36+
const isMember = await github.rest.orgs.checkMembershipForUser({
37+
org: 'clerk',
38+
username: context.actor
39+
});
40+
if (!isMember) {
41+
core.setFailed(`@${actor} is not a member of the Clerk organization`);
42+
}
43+
44+
- name: Checkout repo
45+
uses: actions/checkout@v4
46+
with:
47+
ref: refs/pull/${{ github.event.issue.number }}/head
48+
49+
- name: Setup
50+
id: config
51+
uses: ./.github/actions/init
52+
with:
53+
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
54+
turbo-team: ${{ vars.TURBO_TEAM }}
55+
turbo-token: ${{ secrets.TURBO_TOKEN }}
56+
registry-url: "https://registry.npmjs.org"
57+
58+
- name: Build packages
59+
run: npx turbo build $TURBO_ARGS --force
60+
61+
- name: Get date
62+
run: |
63+
echo "DATE=$(date -u +"%b %d, %Y %I:%M %p")" >> $GITHUB_ENV
64+
65+
- name: Install site in isolation
66+
run: node scripts/install-site-in-isolation.mjs playground/nextjs
67+
68+
- name: Install Vercel CLI
69+
run: npm install --global vercel@latest
70+
71+
- name: Pull Vercel environment information
72+
run: |
73+
cd $FULL_TMP_FOLDER
74+
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }}
75+
76+
- name: Copy clerk-js/dist into public/clerk-js of test site
77+
run: |
78+
cp -r $GITHUB_WORKSPACE/packages/clerk-js/dist $FULL_TMP_FOLDER/public/clerk-js
79+
80+
- name: Build with Vercel
81+
run: |
82+
cd $FULL_TMP_FOLDER
83+
vercel build --yes
84+
env:
85+
NEXT_PUBLIC_CLERK_JS: /clerk-js/clerk.browser.js
86+
87+
- name: Deploy to Vercel (prebuilt)
88+
id: vercel-deploy
89+
run: |
90+
cd $FULL_TMP_FOLDER
91+
vercel deploy --prebuilt --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --no-wait > deployment_url.txt
92+
echo "url=$(cat deployment_url.txt)" >> $GITHUB_OUTPUT
93+
94+
- name: Create preview comment - Deploying
95+
uses: marocchino/sticky-pull-request-comment@v2.8.0
96+
with:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
number: ${{ github.event.pull_request.number }}
99+
header: ${{ env.COMMENT_HEADER}}
100+
message: |
101+
Hey @${{ github.event.comment.user.login }}, your preview is currently deploying and should be available shortly.
102+
103+
| Status | Preview | Updated (UTC) |
104+
| :-- | :-- | :-- |
105+
| :cook: _Deploying..._ | [Inspect](${{ steps.vercel-deploy.outputs.url }}) | ${{ env.DATE }} |
106+
107+
- name: Get date
108+
run: |
109+
echo "DATE=$(date -u +"%b %d, %Y %I:%M %p")" >> $GITHUB_ENV
110+
111+
- name: Wait for deployment
112+
id: vercel-wait-for-deploy
113+
run: |
114+
vercel inspect --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --wait ${{ steps.vercel-deploy.outputs.url }} --timeout 10m --scope clerk-production
115+
vercel alias set ${{ steps.vercel-deploy.outputs.url }} javascript-preview-${{ github.event.pull_request.number }}.clerkpreview.com --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --scope clerk-production
116+
echo "stable_url=https://javascript-preview-${{ github.event.pull_request.number }}.clerkpreview.com" >> $GITHUB_OUTPUT
117+
118+
- name: Create preview comment - deployed
119+
uses: marocchino/sticky-pull-request-comment@v2.8.0
120+
with:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
number: ${{ github.event.pull_request.number }}
123+
header: ${{ env.COMMENT_HEADER }}
124+
message: |
125+
Hey @${{ github.event.comment.user.login }}, your preview is available.
126+
127+
| Status | Preview | Updated (UTC) |
128+
| :-- | :-- | :-- |
129+
| :cookie: Deployed | [Visit preview](${{ steps.vercel-wait-for-deploy.outputs.stable_url }}) | ${{ env.DATE }} |
130+
131+
<!-- deployed:true -->

0 commit comments

Comments
 (0)