Repository navigation
106 lines (97 loc) · 4.26 KB
/
Copy pathrelease-userscript.yml
File metadata and controls
106 lines (97 loc) · 4.26 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
# 打包用户脚本(含模型)并发布 GitHub Release
#
# 触发方式:
# 1. 手动:仓库 Actions 页 → "Release Userscript" → Run workflow(需选 v* tag ref)
# 2. 自动:推送 v* 标签(如 git tag v3.1.0 && git push origin v3.1.0)
#
# 分发主渠道是 jsDelivr CDN(@<tag> 路径)与脚本猫脚本市场;
# Release zip 是离线备份(脚本 + 模型)。
name: Release Userscript
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-release:
# 仅 tag 推送时构建(防 master push 误触发)
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
# 完整历史+全部 tag: release notes 需要 git log <prev_tag>..HEAD
fetch-depth: 0
- name: Read version from userscript
id: version
run: |
echo "version=$(grep -oP '(?<=@version)\s+\S+' userscript/captcha-autofill.user.js | awk '{print $1}')" >> "$GITHUB_OUTPUT"
- name: Validate JS syntax
run: node --check userscript/captcha-autofill.user.js
- name: Package userscript
run: |
mkdir -p package/userscript
cp userscript/captcha-autofill.user.js package/userscript/
cp userscript/model.onnx package/userscript/
cp userscript/captcha-autofill.user.js captcha-autofill.user.js
cp README.md package/
cp DATASETS.md package/ 2>/dev/null || true
cd package
zip -r "../captcha-autofill-userscript-v${{ steps.version.outputs.version }}.zip" .
- name: Build release notes
id: notes
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
PREV_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName' 2>/dev/null || true)
if [ -n "$PREV_TAG" ]; then
LOG=$(git log --format='%h %s' "$PREV_TAG"..HEAD)
else
LOG=$(git log --format='%h %s' -15)
fi
# 按 Conventional Commits 前缀分组(空组不输出)
NOTES="更新内容"
for key in feat fix perf refactor test docs; do
LINES=$(echo "$LOG" | grep -E "^[0-9a-f]+ $key(\(|:)" || true)
if [ -n "$LINES" ]; then
case "$key" in
feat) HEADER="### 🚀 新功能";;
fix) HEADER="### 🐛 修复";;
perf) HEADER="### ⚡ 性能";;
refactor) HEADER="### ♻️ 重构";;
test) HEADER="### 🧪 测试";;
docs) HEADER="### 📝 文档";;
esac
NOTES=$(printf '%s\n\n%s\n%s' "$NOTES" "$HEADER" "$LINES")
fi
done
# 其余(ci/chore 等)归入构建/维护
OTHER=$(echo "$LOG" | grep -vE "^[0-9a-f]+ (feat|fix|perf|refactor|test|docs)(\(|:)" || true)
if [ -n "$OTHER" ]; then
NOTES=$(printf '%s\n\n%s\n%s' "$NOTES" "### 🔧 构建/维护" "$OTHER")
fi
INSTALL=$(printf '## 安装说明\n\n1. 下载本 Release 资产 captcha-autofill-userscript-v%s.zip\n2. 方式一(推荐):脚本猫/Tampermonkey → 新建脚本 → 粘贴 userscript/captcha-autofill.user.js 全文保存\n3. 方式二:解压 zip 备用(模型本地化)\n\n> 模型也可由脚本自动从 jsDelivr CDN 下载(首次约 10MB,之后本地缓存)。' "$VERSION")
NOTES=$(printf '%s\n\n%s' "$NOTES" "$INSTALL")
{
echo "notes<<EOF_NOTES"
echo "$NOTES"
echo "EOF_NOTES"
} >> "$GITHUB_OUTPUT"
- name: Publish Release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ github.ref_name }}"
VERSION="${{ steps.version.outputs.version }}"
if gh release view "$TAG" >/dev/null 2>&1; then
gh release delete "$TAG" --yes
fi
gh release create "$TAG" \
"captcha-autofill-userscript-v${VERSION}.zip" \
"captcha-autofill.user.js" \
--title "验证码自动识别填充(用户脚本) v${VERSION}" \
--notes "${{ steps.notes.outputs.notes }}"