mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
feat: 添加自动版本发布功能
- 新增 auto-release.yml 工作流,推送到 main 分支时自动递增版本号 - 自动创建 GitHub Release 和生成更新日志 - 添加 AUTO_RELEASE_GUIDE.md 详细使用指南 - 更新 WORKFLOW_USAGE.md 说明文档 现在每次推送到 main 分支都会自动: 1. 递增 patch 版本号(如 v1.0.1 → v1.0.2) 2. 创建新的 Git 标签和 GitHub Release 3. 生成更新日志并更新 CHANGELOG.md 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
132
.github/workflows/auto-release.yml
vendored
Normal file
132
.github/workflows/auto-release.yml
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
name: Auto Release on Push to Main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- '.github/**'
|
||||
- 'docs/**'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
auto-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get latest tag
|
||||
id: get_latest_tag
|
||||
run: |
|
||||
# 获取最新的版本标签
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
echo "Latest tag: $LATEST_TAG"
|
||||
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
# 提取版本号部分(去掉 v 前缀)
|
||||
VERSION=${LATEST_TAG#v}
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Calculate next version
|
||||
id: next_version
|
||||
run: |
|
||||
VERSION="${{ steps.get_latest_tag.outputs.version }}"
|
||||
|
||||
# 分割版本号为 major.minor.patch
|
||||
IFS='.' read -r -a version_parts <<< "$VERSION"
|
||||
MAJOR="${version_parts[0]:-0}"
|
||||
MINOR="${version_parts[1]:-0}"
|
||||
PATCH="${version_parts[2]:-0}"
|
||||
|
||||
# 递增 patch 版本号
|
||||
NEW_PATCH=$((PATCH + 1))
|
||||
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
|
||||
NEW_TAG="v${NEW_VERSION}"
|
||||
|
||||
echo "New version: $NEW_VERSION"
|
||||
echo "New tag: $NEW_TAG"
|
||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate changelog
|
||||
id: changelog
|
||||
uses: orhun/git-cliff-action@v3
|
||||
with:
|
||||
config: .github/cliff.toml
|
||||
args: --unreleased --strip header
|
||||
|
||||
- name: Check if there are changes to release
|
||||
id: check_changes
|
||||
run: |
|
||||
# 检查自上次标签以来是否有新的提交
|
||||
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
|
||||
if [ "$LATEST_TAG" = "v0.0.0" ]; then
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
CHANGES=$(git rev-list $LATEST_TAG..HEAD --count)
|
||||
if [ "$CHANGES" -gt 0 ]; then
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Create and push tag
|
||||
if: steps.check_changes.outputs.has_changes == 'true'
|
||||
run: |
|
||||
NEW_TAG="${{ steps.next_version.outputs.new_tag }}"
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
|
||||
git push origin "$NEW_TAG"
|
||||
|
||||
- name: Create Release
|
||||
if: steps.check_changes.outputs.has_changes == 'true'
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.next_version.outputs.new_tag }}
|
||||
name: Release ${{ steps.next_version.outputs.new_version }}
|
||||
body: |
|
||||
## 🐳 Docker 镜像
|
||||
|
||||
```bash
|
||||
docker pull ${{ secrets.DOCKERHUB_USERNAME || 'weishaw' }}/claude-relay-service:${{ steps.next_version.outputs.new_tag }}
|
||||
docker pull ${{ secrets.DOCKERHUB_USERNAME || 'weishaw' }}/claude-relay-service:latest
|
||||
```
|
||||
|
||||
## 📦 主要更新
|
||||
|
||||
${{ steps.changelog.outputs.content }}
|
||||
|
||||
## 📋 完整更新日志
|
||||
|
||||
查看 [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md)
|
||||
|
||||
---
|
||||
*此版本由 GitHub Actions 自动发布*
|
||||
draft: false
|
||||
prerelease: false
|
||||
generate_release_notes: true
|
||||
|
||||
- name: Update CHANGELOG.md
|
||||
if: steps.check_changes.outputs.has_changes == 'true'
|
||||
run: |
|
||||
# 生成完整的 CHANGELOG
|
||||
git cliff --config .github/cliff.toml --output CHANGELOG.md
|
||||
|
||||
# 提交 CHANGELOG 更新
|
||||
if git diff --quiet CHANGELOG.md; then
|
||||
echo "No changes to CHANGELOG.md"
|
||||
else
|
||||
git add CHANGELOG.md
|
||||
git commit -m "chore: update CHANGELOG.md for ${{ steps.next_version.outputs.new_tag }} [skip ci]"
|
||||
git push origin main
|
||||
fi
|
||||
Reference in New Issue
Block a user