-
Notifications
You must be signed in to change notification settings - Fork 0
302 lines (258 loc) · 10.5 KB
/
Copy pathcd.yml
File metadata and controls
302 lines (258 loc) · 10.5 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
name: CD - Build and Deploy
on:
push:
branches: [main]
tags:
- 'v*'
workflow_dispatch:
inputs:
channel:
description: 'Build channel'
required: false
default: 'beta'
type: choice
options:
- beta
- stable
# 设置 GITHUB_TOKEN 权限
permissions:
contents: write
pages: write
id-token: write
# 只允许一个并发部署
concurrency:
group: 'pages'
cancel-in-progress: false
env:
NODE_VERSION: '24'
PNPM_VERSION: '10'
jobs:
# ==================== 构建 ====================
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
channel: ${{ steps.channel.outputs.channel }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 需要完整历史来下载 release
- name: Determine channel
id: channel
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "channel=stable" >> $GITHUB_OUTPUT
echo "Channel: stable (tag trigger)"
elif [[ "${{ github.event.inputs.channel }}" == "stable" ]]; then
echo "channel=stable" >> $GITHUB_OUTPUT
echo "Channel: stable (manual trigger)"
else
echo "channel=beta" >> $GITHUB_OUTPUT
echo "Channel: beta"
fi
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Get version
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Type check
run: pnpm typecheck
- name: Run tests
run: pnpm test
# ===== 构建当前渠道的 Web 版本 =====
- name: Build Web version
run: |
SERVICE_IMPL=web pnpm build
mv dist dist-web
# ===== 构建 DWEB 版本 =====
- name: Build DWEB version
run: |
SERVICE_IMPL=dweb pnpm build
mv dist dist-dweb
- name: Install Plaoc CLI
run: npm install -g @aspect/plaoc-cli || echo "Plaoc CLI not available"
- name: Bundle DWEB with Plaoc
continue-on-error: true
run: |
if command -v plaoc &> /dev/null; then
plaoc bundle ./dist-dweb -c ./ -o ./dists
echo "Plaoc bundle completed"
else
echo "Plaoc CLI not installed, using raw dist-dweb"
mkdir -p dists
cp -r dist-dweb/* dists/
fi
# ===== 准备 VitePress 的 webapp 目录 =====
- name: Prepare webapp for VitePress
env:
CHANNEL: ${{ steps.channel.outputs.channel }}
GH_TOKEN: ${{ github.token }}
run: |
echo "Current channel: $CHANNEL"
# 当前构建的版本放到对应渠道目录
if [[ "$CHANNEL" == "stable" ]]; then
# stable 构建:当前版本放 webapp/,尝试下载 beta
mkdir -p docs/public/webapp
cp -r dist-web/* docs/public/webapp/
echo "Copied current build to docs/public/webapp/ (stable)"
# 尝试下载最新的 beta 版本(从 latest prerelease)
mkdir -p docs/public/webapp-beta
if gh release download --pattern 'bfmpay-web-beta.zip' --dir /tmp -R ${{ github.repository }} 2>/dev/null; then
unzip -q /tmp/bfmpay-web-beta.zip -d docs/public/webapp-beta/
echo "Downloaded beta version from release"
else
# 如果没有 beta release,使用当前构建
cp -r dist-web/* docs/public/webapp-beta/
echo "No beta release found, using current build for webapp-beta"
fi
else
# beta 构建:当前版本放 webapp-beta/,尝试下载 stable
mkdir -p docs/public/webapp-beta
cp -r dist-web/* docs/public/webapp-beta/
echo "Copied current build to docs/public/webapp-beta/ (beta)"
# 尝试下载最新的 stable 版本
mkdir -p docs/public/webapp
if gh release download --pattern 'bfmpay-web.zip' --dir /tmp -R ${{ github.repository }} 2>/dev/null; then
unzip -q /tmp/bfmpay-web.zip -d docs/public/webapp/
echo "Downloaded stable version from release"
else
# 如果没有 stable release,使用当前构建
cp -r dist-web/* docs/public/webapp/
echo "No stable release found, using current build for webapp"
fi
fi
# 显示准备好的目录
echo "=== webapp directory ==="
ls -la docs/public/webapp/ | head -5
echo "=== webapp-beta directory ==="
ls -la docs/public/webapp-beta/ | head -5
# ===== 构建 Storybook =====
- name: Build Storybook
run: pnpm build-storybook
- name: Prepare Storybook for VitePress
run: |
mkdir -p docs/public/storybook
cp -r storybook-static/* docs/public/storybook/
echo "Storybook copied to docs/public/storybook/"
# ===== 构建 VitePress 站点 =====
# Base path: 仓库变量 VITEPRESS_BASE,默认使用 /{repo_name}/
- name: Build VitePress site
env:
VITEPRESS_BASE: ${{ vars.VITEPRESS_BASE || format('/{0}/', github.event.repository.name) }}
run: |
echo "Building with VITEPRESS_BASE=$VITEPRESS_BASE"
pnpm docs:build
# ===== 准备 GitHub Pages =====
- name: Prepare GitHub Pages
run: |
# VitePress 输出目录
mkdir -p gh-pages
cp -r docs/.vitepress/dist/* gh-pages/
# 禁用 Jekyll
touch gh-pages/.nojekyll
echo "=== GitHub Pages structure ==="
find gh-pages -maxdepth 2 -type d
# ===== 创建 Release 产物 =====
- name: Create release artifacts
env:
CHANNEL: ${{ steps.channel.outputs.channel }}
run: |
mkdir -p release
VERSION="${{ steps.version.outputs.version }}"
if [[ "$CHANNEL" == "stable" ]]; then
# Stable: 创建不带 beta 后缀的文件
cd dist-web && zip -r ../release/bfmpay-web.zip . && cd ..
cp release/bfmpay-web.zip "release/bfmpay-web-${VERSION}.zip"
if [ -d "dists" ] && [ "$(ls -A dists)" ]; then
cd dists && zip -r ../release/bfmpay-dweb.zip . && cd ..
else
cd dist-dweb && zip -r ../release/bfmpay-dweb.zip . && cd ..
fi
cp release/bfmpay-dweb.zip "release/bfmpay-dweb-${VERSION}.zip"
else
# Beta: 创建带 beta 后缀的文件
cd dist-web && zip -r ../release/bfmpay-web-beta.zip . && cd ..
cp release/bfmpay-web-beta.zip "release/bfmpay-web-${VERSION}-beta.zip"
if [ -d "dists" ] && [ "$(ls -A dists)" ]; then
cd dists && zip -r ../release/bfmpay-dweb-beta.zip . && cd ..
else
cd dist-dweb && zip -r ../release/bfmpay-dweb-beta.zip . && cd ..
fi
cp release/bfmpay-dweb-beta.zip "release/bfmpay-dweb-${VERSION}-beta.zip"
fi
echo "=== Release artifacts ==="
ls -la release/
# ===== 上传构建产物 =====
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: gh-pages
- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ steps.channel.outputs.channel }}-${{ steps.version.outputs.version }}
path: release/
retention-days: 30
# ==================== 部署到 GitHub Pages ====================
deploy-pages:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# ==================== 创建 Release ====================
create-release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-${{ needs.build.outputs.channel }}-${{ needs.build.outputs.version }}
path: release/
- name: Create or Update Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.channel == 'stable' && format('v{0}', needs.build.outputs.version) || 'beta' }}
name: ${{ needs.build.outputs.channel == 'stable' && format('BFM Pay v{0}', needs.build.outputs.version) || 'BFM Pay Beta' }}
body: |
## BFM Pay ${{ needs.build.outputs.channel == 'stable' && format('v{0}', needs.build.outputs.version) || 'Beta' }}
### 下载
- **Web 版本**: `bfmpay-web${{ needs.build.outputs.channel == 'beta' && '-beta' || '' }}.zip`
- **DWEB 版本**: `bfmpay-dweb${{ needs.build.outputs.channel == 'beta' && '-beta' || '' }}.zip`
### 在线访问
- Web 应用 (stable): https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/webapp/
- Web 应用 (beta): https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/webapp-beta/
- 文档首页: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/
### DWEB 安装
在 DWEB 浏览器中打开以下链接安装:
```
dweb://install?url=https://github.com/${{ github.repository }}/releases/download/${{ needs.build.outputs.channel == 'stable' && format('v{0}', needs.build.outputs.version) || 'beta' }}/bfmpay-dweb${{ needs.build.outputs.channel == 'beta' && '-beta' || '' }}.zip
```
files: |
release/*
draft: false
prerelease: ${{ needs.build.outputs.channel == 'beta' }}
generate_release_notes: ${{ needs.build.outputs.channel == 'stable' }}