feat(.github): 感谢 @lxfight,参考 https://github.com/lxfight/astrbot_plugin_mnemosyne 的 actions 实现自动发版和 Issue 模板

This commit is contained in:
SXP-Simon
2025-11-18 22:45:27 +08:00
parent 160fee61c6
commit cba8db126e
5 changed files with 384 additions and 1 deletions
+127
View File
@@ -0,0 +1,127 @@
# GitHub Actions 工作流说明
## 自动发布工作流 (auto-release.yml)
### 功能概述
此工作流会自动检测 `metadata.yaml` 文件中的 `version` 字段变化,当检测到版本号更新时,自动创建一个新的 GitHub Release。
### 触发条件
- 当向 `main` 分支推送提交时
- 且该提交修改了 `metadata.yaml` 文件
### 工作流程
1. **检查版本变化**
- 提取当前 `metadata.yaml` 中的版本号
- 对比上一次提交的版本号
- 判断版本是否发生变化
2. **生成变更日志**
- 如果版本已更新,自动生成变更日志
- 根据提交信息的前缀自动分类:
- `feat:` / `feature:` → ✨ Feature(新功能)
- `fix:` → 🐛 Fix(修复)
- `docs:` → 📚 Docs(文档)
- `refactor:` / `style:` / `perf:` / `test:` / `chore:` → 🔧 其他改进
- 其他 → 📌 普通提交
3. **创建 Release**
- 使用新版本号作为标签名
- 附带自动生成的变更日志
- 提供版本对比链接
### 使用方法
1. **更新版本号**
编辑 `metadata.yaml` 文件,修改 `version` 字段:
```yaml
version: v0.5.3 # 从 v0.5.2 更新到 v0.5.3
```
2. **提交并推送**
```bash
git add metadata.yaml
git commit -m "chore: bump version to v0.5.3"
git push origin main
```
3. **自动发布**
工作流会自动触发并创建 Release,无需手动操作。
### 最佳实践
#### 提交信息格式
为了获得更好的变更日志,建议使用语义化的提交信息格式:
```
<type>: <description>
[optional body]
```
**类型示例:**
- `feat:` 添加新功能
- `fix:` 修复 bug
- `docs:` 文档更新
- `refactor:` 代码重构
- `perf:` 性能优化
- `test:` 测试相关
- `chore:` 构建/工具/依赖更新
**示例:**
```bash
git commit -m "feat: 添加向量搜索功能"
git commit -m "fix: 修复内存泄漏问题"
git commit -m "docs: 更新 API 文档"
```
#### 版本号规范
建议遵循语义化版本控制 (Semantic Versioning)
- `vX.Y.Z` 格式
- `X`:主版本号(重大变更)
- `Y`:次版本号(新功能)
- `Z`:修订号(bug 修复)
**示例:**
- `v0.5.2` → `v0.5.3`bug 修复)
- `v0.5.3` → `v0.6.0`(新功能)
- `v0.6.0` → `v1.0.0`(重大变更)
### 权限要求
工作流需要以下权限:
- `contents: write` - 用于创建 Release 和标签
这些权限已在工作流文件中配置,GitHub Actions 会自动提供。
### 注意事项
1. 确保每次更新版本号时,版本号是递增的
2. 避免在同一次提交中多次修改版本号
3. 如果 Release 创建失败,检查:
- 该版本标签是否已存在
- 仓库是否启用了 GitHub Actions
- 权限设置是否正确
### 查看工作流运行状态
在 GitHub 仓库页面:
1. 点击 "Actions" 标签
2. 查看 "Auto Release on Version Update" 工作流
3. 点击具体的运行记录查看详细日志
### 手动触发(可选)
如需手动创建 Release,可以:
1. 在 GitHub 仓库页面点击 "Releases"
2. 点击 "Draft a new release"
3. 手动填写版本信息和变更日志
但推荐使用自动化工作流以保持一致性。
+122
View File
@@ -0,0 +1,122 @@
name: Auto Release on Version Update
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'metadata.yaml'
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check.outputs.changed }}
new_version: ${{ steps.check.outputs.version }}
old_version: ${{ steps.check.outputs.old_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check version change
id: check
run: |
# 获取当前版本
CURRENT_VERSION=$(grep '^version:' metadata.yaml | awk '{print $2}')
echo "Current version: $CURRENT_VERSION"
# 获取上一次提交的版本
git checkout HEAD~1 -- metadata.yaml 2>/dev/null || echo "First commit"
if [ -f metadata.yaml ]; then
PREVIOUS_VERSION=$(grep '^version:' metadata.yaml | awk '{print $2}')
git checkout HEAD -- metadata.yaml
else
PREVIOUS_VERSION="none"
fi
echo "Previous version: $PREVIOUS_VERSION"
# 比较版本
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "old_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "No version change detected"
fi
create-release:
needs: check-version
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
NEW_VERSION="${{ needs.check-version.outputs.new_version }}"
OLD_VERSION="${{ needs.check-version.outputs.old_version }}"
echo "## 🎉 Release $NEW_VERSION" > changelog.md
echo "" >> changelog.md
# 如果有上一个版本标签,生成两个版本之间的提交日志
if git rev-parse "$OLD_VERSION" >/dev/null 2>&1; then
echo "### 📝 Changes since $OLD_VERSION" >> changelog.md
echo "" >> changelog.md
# 获取提交信息并分类
git log "$OLD_VERSION..HEAD" --pretty=format:"%s|||%h|||%an" --no-merges | while IFS='|||' read -r subject hash author; do
# 根据提交信息的前缀进行分类
if echo "$subject" | grep -qiE "^(feat|feature):"; then
echo "- ✨ **Feature**: ${subject#*: } (${hash})" >> changelog.md
elif echo "$subject" | grep -qiE "^fix:"; then
echo "- 🐛 **Fix**: ${subject#*: } (${hash})" >> changelog.md
elif echo "$subject" | grep -qiE "^docs:"; then
echo "- 📚 **Docs**: ${subject#*: } (${hash})" >> changelog.md
elif echo "$subject" | grep -qiE "^(refactor|style|perf|test|chore):"; then
prefix=$(echo "$subject" | cut -d: -f1)
echo "- 🔧 **${prefix^}**: ${subject#*: } (${hash})" >> changelog.md
else
echo "- 📌 $subject (${hash})" >> changelog.md
fi
done
else
echo "### 📝 Changes" >> changelog.md
echo "" >> changelog.md
echo "Initial release or no previous version tag found." >> changelog.md
echo "" >> changelog.md
echo "#### Recent commits:" >> changelog.md
git log -10 --pretty=format:"- %s (%h)" --no-merges >> changelog.md
fi
echo "" >> changelog.md
echo "---" >> changelog.md
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$OLD_VERSION...$NEW_VERSION" >> changelog.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-version.outputs.new_version }}
name: Release ${{ needs.check-version.outputs.new_version }}
body_path: changelog.md
draft: false
prerelease: false
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify release created
run: |
echo "✅ Release ${{ needs.check-version.outputs.new_version }} has been created successfully!"
echo "🔗 View release at: https://github.com/${{ github.repository }}/releases/tag/${{ needs.check-version.outputs.new_version }}"