-
Notifications
You must be signed in to change notification settings - Fork 2
97 lines (82 loc) · 2.97 KB
/
build.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
name: Build Release Assets
on:
release:
types: [created]
jobs:
build-and-upload:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Build Frontend
run: |
cd front
# 跳过 postinstall 脚本
npm install --ignore-scripts
# 创建并配置环境文件
cp .env.example .env.production
sed -i 's#VITE_AXIOS_BASE_URL.*#VITE_AXIOS_BASE_URL = "https://cyiapi.lmyself.ggff.net"#' .env.production
# 显示配置文件内容以便验证
echo "Environment file content:"
cat .env.production
# 构建
npm run build
cd dist
zip -r ../../frontend.zip .
echo "✅ Frontend build completed"
- name: Build Worker
run: |
cd service
# 从示例文件创建 wrangler.toml
cp wrangler.toml.example wrangler.toml
# 修改配置文件,使用占位符
sed -i 's/database_name = ".*"/database_name = "YOUR_DATABASE_NAME"/' wrangler.toml
sed -i 's/database_id = ".*"/database_id = "YOUR_DATABASE_ID"/' wrangler.toml
sed -i 's/id = ".*"/id = "YOUR_KV_NAMESPACE_ID"/' wrangler.toml
sed -i 's/JWT_SECRET = ".*"/JWT_SECRET = "YOUR_JWT_SECRET"/' wrangler.toml
# 安装依赖并构建
npm install
npx wrangler deploy --dry-run --outdir=dist
mv dist/index.js ../worker.js
echo "✅ Worker build completed"
# 保存构建产物为 artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: release-assets
path: |
frontend.zip
worker.js
# 上传到版本发布
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
files: |
frontend.zip
worker.js
tag_name: ${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
# 使用 GitHub CLI 处理 latest release
- name: Update latest release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# 删除旧的 latest 标签(如果存在)
git push origin :refs/tags/latest || true
# 创建新的 latest 标签
git tag -f latest
git push -f origin latest
# 删除旧的 latest release(如果存在)
gh release delete latest --yes || true
# 创建新的 latest release
gh release create latest \
--title "Latest Release" \
--notes "This is always updated to the latest release. Current version: ${{ github.ref_name }}" \
frontend.zip worker.js \
--latest