-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathdeploy-seed-design-docs-alpha-pages.yml
More file actions
168 lines (148 loc) · 5.57 KB
/
Copy pathdeploy-seed-design-docs-alpha-pages.yml
File metadata and controls
168 lines (148 loc) · 5.57 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
on:
push:
branches:
- "**"
- "!main"
- "!dev" # V3 deployment; remove this when V3 is stable
paths:
- "docs/**"
- "packages/css/**"
- "packages/react/**"
- "packages/stackflow/**"
- ".github/workflows/deploy-seed-design-docs-alpha-pages.yml"
- ".github/actions/setup/action.yml"
workflow_dispatch:
inputs:
skip-figma-cache:
description: "Skip Figma image cache (fetch fresh images)"
required: false
type: boolean
default: false
bypass-cache-node-ids:
description: "Comma-separated Figma node IDs to bypass cache for (fetch fresh)"
required: false
type: string
default: ""
permissions:
contents: read
pull-requests: write
env:
FIGMA_FILE_KEY: ${{ secrets.FIGMA_FILE_KEY }}
FIGMA_PERSONAL_ACCESS_TOKEN: ${{ secrets.FIGMA_PERSONAL_ACCESS_TOKEN }}
name: deploy-seed-design-docs-alpha-pages
jobs:
deploy:
name: deploy-seed-design-docs-alpha-pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Restore Figma image cache
if: ${{ !inputs.skip-figma-cache }}
uses: actions/cache/restore@v5
with:
path: docs/.cache/figma-image
key: ${{ runner.os }}-figma-images-${{ hashFiles('docs/.cache/figma-image/**') }}
restore-keys: |
${{ runner.os }}-figma-images-
- name: Restore Next.js cache
uses: actions/cache@v5
with:
path: docs/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock') }}-
- uses: ./.github/actions/setup
with:
build-packages: true
build-rootage: true
- name: Build Docs
working-directory: ./docs
env:
# docs uses Next static export, so NEXT_PUBLIC_* values must be present at build time.
FIGMA_CACHE_DISABLED: ${{ inputs.skip-figma-cache && '1' || '0' }}
FIGMA_BYPASS_CACHE_NODE_IDS: ${{ inputs.bypass-cache-node-ids }}
NEXT_PUBLIC_POSTHOG_KEY: ${{ secrets.NEXT_PUBLIC_POSTHOG_KEY }}
NEXT_PUBLIC_POSTHOG_HOST: ${{ secrets.NEXT_PUBLIC_POSTHOG_HOST }}
run: |
bun run build
- name: Save Figma image cache
uses: actions/cache/save@v5
with:
path: docs/.cache/figma-image
key: ${{ runner.os }}-figma-images-${{ hashFiles('docs/.cache/figma-image/**') }}
- name: Deploy docs at Cloudflare Pages in `seed-design-v3` project (Alpha)
id: deploy
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
wranglerVersion: "4.45.3"
command: pages deploy ./docs/out --project-name=seed-design-v3 --branch=${{ github.ref_name }}
- name: Find related PR
id: pr
uses: actions/github-script@v9
with:
script: |
const { owner, repo } = context.repo;
if (!context.ref.startsWith('refs/heads/')) {
core.setOutput('number', '');
return;
}
const branch = context.ref.replace('refs/heads/', '');
const pulls = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: `${owner}:${branch}`,
per_page: 1,
});
core.setOutput('number', pulls.data[0] ? String(pulls.data[0].number) : '');
- name: Upsert PR preview comment
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ steps.pr.outputs.number }}
PREVIEW_ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
PREVIEW_DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = Number(process.env.PR_NUMBER);
const marker = '<!-- seed-design-preview:docs-alpha -->';
const aliasUrl = (process.env.PREVIEW_ALIAS_URL || '').trim();
const deploymentUrl = (process.env.PREVIEW_DEPLOYMENT_URL || '').trim();
const body = [
marker,
'## Alpha Preview (Docs)',
'',
`- Branch Preview URL: ${aliasUrl || '(not available)'}`,
`- Preview URL: ${deploymentUrl || '(not available)'}`,
`- Commit: \`${context.sha.slice(0, 7)}\``,
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' &&
comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}