-
Notifications
You must be signed in to change notification settings - Fork 81
251 lines (214 loc) · 9.33 KB
/
Copy pathrelease.yml
File metadata and controls
251 lines (214 loc) · 9.33 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
name: Release
on:
push:
tags:
- v*
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v2.0.0-beta.1)'
required: true
type: string
webui_tag:
description: '可选:捆绑的 WebUI 仓库 tag(默认取当前 main 上可达的最新 v* tag)'
required: false
default: ''
type: string
jobs:
build-webui-dist:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
webui_console_version: ${{ steps.webui_ref.outputs.console_version }}
webui_git_ref: ${{ steps.webui_ref.outputs.resolved_ref }}
steps:
- name: Checkout WebUI repo
uses: actions/checkout@v6
with:
repository: PallasBot/Pallas-Bot-WebUI
ref: main
path: pallas-webui
fetch-depth: 0
fetch-tags: true
- name: Resolve WebUI release tag
id: webui_ref
working-directory: pallas-webui
env:
PIN_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.webui_tag || '' }}
run: |
set -euo pipefail
git fetch origin --tags --force
if [ -n "${PIN_TAG}" ]; then
git checkout "${PIN_TAG}"
echo "console_version=${PIN_TAG}" >> "$GITHUB_OUTPUT"
echo "resolved_ref=${PIN_TAG}" >> "$GITHUB_OUTPUT"
exit 0
fi
TAG=$(git tag -l 'v*' --merged HEAD --sort=-version:refname | head -n1)
if [ -z "${TAG}" ]; then
TAG=$(git tag -l 'v*' --sort=-version:refname | head -n1)
fi
if [ -n "${TAG}" ]; then
git checkout "${TAG}"
echo "console_version=${TAG}" >> "$GITHUB_OUTPUT"
echo "resolved_ref=${TAG}" >> "$GITHUB_OUTPUT"
else
echo "::warning::WebUI 仓库无 v* tag,使用 main;console 版本取自 package.json"
VER=$(node -p "require('./package.json').version")
echo "console_version=${VER}" >> "$GITHUB_OUTPUT"
echo "resolved_ref=main" >> "$GITHUB_OUTPUT"
fi
- name: Get version
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: pallas-webui/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: pallas-webui
# console-version.json:version = 上游 WebUI 发版 tag(或手动 PIN / 无 tag 时 package.json)。
- name: Build WebUI
working-directory: pallas-webui
env:
CONSOLE_VERSION: ${{ steps.webui_ref.outputs.console_version }}
run: |
export GIT_COMMIT="$(git rev-parse HEAD)"
export BUILD_TIME="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
npm run build:ci
# zip 根目录为 public/,在 Bot 侧解压到 data/pallas_webui 即得到 public/index.html(与插件默认路径一致)。
- name: Pack dist artifact
run: |
mkdir -p webui-zip-root/public
cp -a pallas-webui/dist/. webui-zip-root/public/
(cd webui-zip-root && zip -r ../dist.zip public)
- name: Upload WebUI artifact
uses: actions/upload-artifact@v4
with:
name: webui-dist-zip
path: dist.zip
create-release:
runs-on: ubuntu-latest
needs: build-webui-dist
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get version
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
id: changelog
run: |
# 生成详细的变更日志
if git describe --tags --abbrev=0 HEAD~1 >/dev/null 2>&1; then
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
# 按类型分组显示提交
echo "### 🚀 新功能" >> $GITHUB_OUTPUT
git log --pretty=format:"* %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" $PREVIOUS_TAG..HEAD --grep="^feat" >> $GITHUB_OUTPUT || echo "无" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🐛 错误修复" >> $GITHUB_OUTPUT
git log --pretty=format:"* %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" $PREVIOUS_TAG..HEAD --grep="^fix" >> $GITHUB_OUTPUT || echo "无" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 📚 文档更新" >> $GITHUB_OUTPUT
git log --pretty=format:"* %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" $PREVIOUS_TAG..HEAD --grep="^docs" >> $GITHUB_OUTPUT || echo "无" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### ⚡ 性能优化" >> $GITHUB_OUTPUT
git log --pretty=format:"* %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" $PREVIOUS_TAG..HEAD --grep="^perf" >> $GITHUB_OUTPUT || echo "无" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🔨 其他更改" >> $GITHUB_OUTPUT
git log --pretty=format:"* %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" $PREVIOUS_TAG..HEAD --invert-grep --grep="^feat\|^fix\|^docs\|^perf" >> $GITHUB_OUTPUT || echo "无" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**完整变更**: [\`$PREVIOUS_TAG...${{ steps.get_version.outputs.version }}\`](https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...${{ steps.get_version.outputs.version }})" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changelog=🎉 **首次发布**" >> $GITHUB_OUTPUT
fi
- name: Download WebUI artifact
uses: actions/download-artifact@v4
with:
name: webui-dist-zip
path: .
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: Release ${{ steps.get_version.outputs.version }}
body: |
## 更新内容
${{ steps.changelog.outputs.changelog }}
## Docker 镜像
```bash
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/pallas-bot:${{ steps.get_version.outputs.version }}
```
## WebUI 使用文档
- 主仓插件说明(自动下载/部署配置):[docs/plugins/pallas_webui/README.md](https://github.com/${{ github.repository }}/blob/${{ steps.get_version.outputs.version }}/docs/plugins/pallas_webui/README.md)
- 前端仓库说明(开发/发版/对接):[PallasBot/Pallas-Bot-WebUI README](https://github.com/PallasBot/Pallas-Bot-WebUI/blob/main/README.md)
## WebUI 使用说明
本 Release 附件中的静态资源基于 WebUI 仓库检出:**`${{ needs.build-webui-dist.outputs.webui_git_ref }}`**(`console-version.json` 中 `version`:**`${{ needs.build-webui-dist.outputs.webui_console_version }}`**)。
默认无需手动配置,首次启用时会自动下载并部署 WebUI 静态资源。
手动部署:下载附件 **`dist.zip`**,解压到 **`data/pallas_webui`**(得到 `data/pallas_webui/public/index.html` 等,无需改 zip 内目录名)。
files: |
dist.zip
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-tagged-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get version
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Build and push tagged image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
PALLAS_BOT_VERSION=${{ steps.get_version.outputs.version }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pallas-bot:${{ steps.get_version.outputs.version }}
${{ secrets.DOCKERHUB_USERNAME }}/pallas-bot:latest