-
Notifications
You must be signed in to change notification settings - Fork 5
123 lines (100 loc) · 3.94 KB
/
preview-deploy.yml
File metadata and controls
123 lines (100 loc) · 3.94 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
name: Preview Deployment
on:
pull_request:
types: [opened, synchronize]
paths:
- 'docs-site/**'
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: true
type: string
concurrency:
group: preview-deploy-${{ github.ref }}
cancel-in-progress: true
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VITE_AUTH0_DOMAIN: ${{ secrets.VITE_AUTH0_DOMAIN }}
VITE_AUTH0_CLIENT_ID: ${{ secrets.VITE_AUTH0_CLIENT_ID }}
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false)
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Setup pnpm
uses: pnpm/action-setup@36de12bed180fa130ed56a35e7344f2fa7a820ab # v4
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4
with:
node-version: '22'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Clear pnpm cache and reinstall (to ensure React version consistency)
run: |
pnpm store prune
pnpm install --force
- name: Build all packages
run: pnpm build
- name: Generate API documentation
run: pnpm docs:api
- name: Install Vercel CLI
run: npm install --global vercel@50.40.0
- name: Deploy to Vercel
id: vercel-deploy
run: |
# Create a completely isolated deployment directory
mkdir -p /tmp/static-deploy
# Copy the built static files
cp -r docs-site/dist/* /tmp/static-deploy/
# Copy the API serverless functions
cp -r docs-site/api /tmp/static-deploy/
# Create a vercel.json with API functions and rewrites (no build needed - already built)
echo '{"buildCommand":"","installCommand":"","rewrites":[{"source":"/r/:path*","destination":"/api/r?file=:path*"},{"source":"/(.*)","destination":"/index.html"}]}' > /tmp/static-deploy/vercel.json
vercel --version
DEPLOYMENT_URL=$(vercel deploy /tmp/static-deploy --token="$VERCEL_TOKEN" --yes --scope="$VERCEL_ORG_ID")
echo "preview-url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
- name: Comment PR
if: github.event_name == 'pull_request'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Preview deployment')
);
const body = `## 🚀 Preview deployment
**Branch:** \`${context.ref.replace('refs/heads/', '')}\`
**Commit:** ${context.sha.substring(0, 7)}
📝 **Preview URL:** ${{ steps.vercel-deploy.outputs.preview-url }}
---
*Updated at ${new Date().toISOString()}*`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}