Repository navigation
180 lines (152 loc) · 5.22 KB
/
Copy pathdeploy-website.yml
File metadata and controls
180 lines (152 loc) · 5.22 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
169
170
171
172
173
174
175
176
177
178
179
name: Deploy Website to Cloudflare Pages
on:
push:
branches:
- main
paths:
# NOTE: Update this path to match your WEBSITE_DIR (e.g., 'website/**')
- 'website/**'
- '.github/workflows/deploy-website.yml'
pull_request:
branches:
- main
paths:
# NOTE: Update this path to match your WEBSITE_DIR (e.g., 'website/**')
- 'website/**'
workflow_dispatch:
concurrency:
group: deploy-website-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Project Configuration - Update these values for your project
PROJECT_NAME: 'vsync'
SITE_DOMAIN: 'vsync.xiaominglab.com'
WEBSITE_DIR: 'website'
BUILD_OUTPUT_DIR: 'website/out'
BUILD_COMMAND: 'pnpm build:website'
# Comment marker (used to update existing PR comment instead of spamming)
PREVIEW_COMMENT_MARKER: '<!-- CF_PAGES_PREVIEW_COMMENT -->'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
- name: Build website
run: ${{ env.BUILD_COMMAND }}
env:
NEXT_PUBLIC_SITE_URL: https://${{ env.SITE_DOMAIN }}
NEXT_PUBLIC_GIT_SHA: ${{ github.sha }}
SKIP_ENV_VALIDATION: true
- name: Upload build artifact
uses: actions/upload-artifact@v6
with:
name: website-build
path: ${{ env.BUILD_OUTPUT_DIR }}
retention-days: 1
deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
deployments: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
install-dependencies: 'false'
setup-cache: 'false'
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: website-build
path: ${{ env.BUILD_OUTPUT_DIR }}
- name: Install wrangler
run: pnpm install -g wrangler
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
packageManager: pnpm
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ${{ env.BUILD_OUTPUT_DIR }} --project-name=${{ env.PROJECT_NAME }} --commit-dirty=true
preview:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request'
permissions:
contents: read
deployments: write
pull-requests: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
install-dependencies: 'false'
setup-cache: 'false'
- name: Download build artifact
uses: actions/download-artifact@v7
with:
name: website-build
path: ${{ env.BUILD_OUTPUT_DIR }}
- name: Install wrangler
run: pnpm install -g wrangler
- name: Deploy Preview to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
packageManager: pnpm
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ${{ env.BUILD_OUTPUT_DIR }} --project-name=${{ env.PROJECT_NAME }} --branch=${{ github.head_ref }} --commit-dirty=true
- name: Upsert PR comment with preview URL (no spam)
uses: actions/github-script@v8
env:
MARKER: ${{ env.PREVIEW_COMMENT_MARKER }}
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
# If your wrangler-action provides it, you can switch to this:
# ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
with:
script: |
const marker = process.env.MARKER;
const url = process.env.DEPLOYMENT_URL;
const body = `${marker}
## 🚀 Preview Deployment Ready!
Preview URL: ${url}
- Branch: \`${context.payload.pull_request.head.ref}\`
- Commit: \`${context.sha}\`
(This comment will be updated on new pushes.)
`;
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
// List recent comments and find the one with our marker
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find(c => (c.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,
});
}