-
Notifications
You must be signed in to change notification settings - Fork 17
129 lines (105 loc) · 3.87 KB
/
Copy pathrelease.yml
File metadata and controls
129 lines (105 loc) · 3.87 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
name: 📦 Draft Release (Tag with v)
on:
push:
tags:
- "*v*"
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v6
- name: 安装 Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
- name: 编译 WebUI 并打包插件
shell: bash
run: |
set -euo pipefail
PACKAGE_NAME="astrbot_plugin_proactive_chat"
BUILD_ROOT="${RUNNER_TEMP}/plugin-build"
STAGE_DIR="${BUILD_ROOT}/${PACKAGE_NAME}"
ZIP_NAME="${PACKAGE_NAME}-${GITHUB_REF_NAME}.zip"
BUILD_JS_DIR="admin/.js-build"
BABEL_TOOLS_DIR="${RUNNER_TEMP}/babel-tools"
rm -rf "${BUILD_ROOT}"
mkdir -p "${STAGE_DIR}"
rsync -a \
--exclude '.git/' \
--exclude '.github/' \
--exclude '.idea/' \
--exclude '.vscode/' \
--exclude '.devin/' \
--exclude '.pytest_cache/' \
--exclude '.ruff_cache/' \
--exclude '.mypy_cache/' \
--exclude '.cache/' \
--exclude '.venv/' \
--exclude 'venv/' \
--exclude '__pycache__/' \
--exclude 'dist/' \
--exclude 'build/' \
--exclude '*.pyc' \
--exclude '*.pyo' \
--exclude '.DS_Store' \
./ "${STAGE_DIR}/"
pushd "${STAGE_DIR}"
if [[ ! -d "admin/js" ]]; then
echo "::error::未找到 admin/js,无法编译 WebUI"
exit 1
fi
if [[ ! -f "admin/index.html" ]]; then
echo "::error::未找到 admin/index.html,无法修正 WebUI 入口"
exit 1
fi
rm -rf "${BUILD_JS_DIR}"
mkdir -p "${BUILD_JS_DIR}"
rm -rf "${BABEL_TOOLS_DIR}"
mkdir -p "${BABEL_TOOLS_DIR}"
pushd "${BABEL_TOOLS_DIR}"
npm init -y >/dev/null 2>&1
npm install --no-save @babel/core @babel/cli @babel/preset-react
popd
NODE_PATH="${BABEL_TOOLS_DIR}/node_modules" \
"${BABEL_TOOLS_DIR}/node_modules/.bin/babel" admin/js \
--extensions ".js,.jsx" \
--out-dir "${BUILD_JS_DIR}" \
--presets @babel/preset-react \
--no-babelrc
rm -rf admin/js
mv "${BUILD_JS_DIR}" admin/js
sed -E -i 's|<script type="text/babel" src="js/([^"]*)\.jsx" defer></script>|<script src="js/\1.js" defer></script>|g' admin/index.html
sed -E -i 's|<script type="text/babel" src="js/([^"]*)\.js" defer></script>|<script src="js/\1.js" defer></script>|g' admin/index.html
sed -E -i '/@babel\/standalone|lib\/babel\.min\.js/d' admin/index.html
rm -f admin/lib/babel.min.js
if grep -q 'text/babel' admin/index.html; then
echo "::error::WebUI 编译后 index.html 仍包含 text/babel 引用"
exit 1
fi
if grep -q '@babel/standalone' admin/index.html; then
echo "::error::WebUI 编译后 index.html 仍包含 Babel Standalone 依赖"
exit 1
fi
if find admin/js -type f -name '*.jsx' | grep -q .; then
echo "::error::WebUI 编译后仍存在 .jsx 源文件"
exit 1
fi
popd
mkdir -p "${GITHUB_WORKSPACE}/dist"
cd "${BUILD_ROOT}"
zip -r "${GITHUB_WORKSPACE}/dist/${ZIP_NAME}" "${PACKAGE_NAME}"
- name: 上传打包产物
uses: actions/upload-artifact@v7
with:
name: plugin-zip-${{ github.ref_name }}
path: dist/*.zip
if-no-files-found: error
- name: 发布 Draft Release
uses: softprops/action-gh-release@v3
with:
draft: true
generate_release_notes: true
files: dist/*.zip