-
Notifications
You must be signed in to change notification settings - Fork 81
221 lines (194 loc) · 7.19 KB
/
Copy pathrelease.yml
File metadata and controls
221 lines (194 loc) · 7.19 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
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: 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
env:
VERSION: ${{ steps.get_version.outputs.version }}
REPOSITORY: ${{ github.repository }}
run: |
set -euo pipefail
chmod +x tools/generate_release_changelog.sh
PREVIOUS=""
if git rev-parse "${VERSION}^{commit}" >/dev/null 2>&1; then
PREVIOUS=$(git describe --tags --abbrev=0 "${VERSION}^" 2>/dev/null || true)
fi
if [ -z "${PREVIOUS}" ]; then
PREVIOUS=$(git tag -l 'v*' --sort=-version:refname | grep -Fxv "${VERSION}" | head -n1 || true)
fi
CHANGELOG=$(./tools/generate_release_changelog.sh "${PREVIOUS}" "${VERSION}" "${REPOSITORY}")
{
echo 'changelog<<EOF'
echo "${CHANGELOG}"
echo EOF
} >> "$GITHUB_OUTPUT"
- 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
附件 **`dist.zip`**(WebUI `${{ needs.build-webui-dist.outputs.webui_git_ref }}` / console `${{ needs.build-webui-dist.outputs.webui_console_version }}`)。启动后通常自动部署;手动解压到 **`data/pallas_webui`** 见 [pallas_webui 插件说明](https://github.com/${{ github.repository }}/blob/${{ steps.get_version.outputs.version }}/docs/plugins/pallas_webui/README.md#配置)。
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