-
Notifications
You must be signed in to change notification settings - Fork 282
133 lines (109 loc) · 4.85 KB
/
preview.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
name: Deploy Preview
run-name: Deploy Preview by ${{ github.actor }}
env:
COMMENT_HEADER: javascript-preview
on:
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
cancel-in-progress: true
jobs:
preview:
if: ${{ startsWith(github.event.comment.body, '!preview') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_CLERK_PROD_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_JS_PREVIEW_PROJECT_ID }}
permissions:
contents: write
pull-requests: write
steps:
- name: Limit action to Clerk members
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const isMember = await github.rest.orgs.checkMembershipForUser({
org: 'clerk',
username: context.actor
});
if (!isMember) {
core.setFailed(`@${actor} is not a member of the Clerk organization`);
}
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
- name: Setup
id: config
uses: ./.github/actions/init
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
registry-url: 'https://registry.npmjs.org'
- name: Build packages
run: npx turbo build $TURBO_ARGS
- name: Get date
run: |
echo "DATE=$(date -u +"%b %d, %Y %I:%M %p")" >> $GITHUB_ENV
- name: Install site in isolation
run: node scripts/install-site-in-isolation.mjs playground/nextjs
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel environment information
run: |
cd $FULL_TMP_FOLDER
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }}
- name: Copy clerk-js/dist into public/clerk-js of test site
run: |
cp -r $GITHUB_WORKSPACE/packages/clerk-js/dist $FULL_TMP_FOLDER/public/clerk-js
- name: Build with Vercel
run: |
cd $FULL_TMP_FOLDER
vercel build --yes
env:
NEXT_PUBLIC_CLERK_JS_URL: /clerk-js/clerk.browser.js
- name: Deploy to Vercel (prebuilt)
id: vercel-deploy
run: |
cd $FULL_TMP_FOLDER
vercel deploy --prebuilt --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --no-wait > deployment_url.txt
echo "url=$(cat deployment_url.txt)" >> $GITHUB_OUTPUT
- name: Create preview comment - Deploying
uses: marocchino/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.CLERK_COOKIE_PAT }}
number: ${{ github.event.issue.number }}
header: ${{ env.COMMENT_HEADER}}
message: |
Hey @${{ github.event.comment.user.login }}, your preview is currently deploying and should be available shortly.
| Status | Preview | Updated (UTC) |
| :-- | :-- | :-- |
| :cook: _Deploying..._ | [Inspect](${{ steps.vercel-deploy.outputs.url }}) | ${{ env.DATE }} |
- name: Get date
run: |
echo "DATE=$(date -u +"%b %d, %Y %I:%M %p")" >> $GITHUB_ENV
- name: Wait for deployment
id: vercel-wait-for-deploy
run: |
vercel inspect --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --wait ${{ steps.vercel-deploy.outputs.url }} --timeout 10m --scope clerk-production
vercel alias set ${{ steps.vercel-deploy.outputs.url }} javascript-preview-${{ github.event.issue.number }}.clerkpreview.com --token=${{ secrets.VERCEL_CLERK_COOKIE_TOKEN }} --scope clerk-production
echo "stable_url=https://javascript-preview-${{ github.event.issue.number }}.clerkpreview.com" >> $GITHUB_OUTPUT
- name: Create preview comment - Deployed
uses: marocchino/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.CLERK_COOKIE_PAT }}
number: ${{ github.event.issue.number }}
header: ${{ env.COMMENT_HEADER }}
message: |
Hey @${{ github.event.comment.user.login }}, your preview is available.
| Status | Preview | Updated (UTC) |
| :-- | :-- | :-- |
| :cookie: Deployed | [Visit preview](${{ steps.vercel-wait-for-deploy.outputs.stable_url }}) | ${{ env.DATE }} |
<!-- deployed:true -->