mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:40:25 +00:00
- 删除旧的auto-release.yml工作流,避免循环触发问题 - 新增auto-version-bump.yml:自动同步VERSION文件与release版本 - 新增release-on-version.yml:基于VERSION文件变更自动创建release - 更新docker-publish.yml:简化触发条件,仅在tag推送时构建 - 添加RELEASE_PROCESS.md文档:详细说明新的发布流程 - 修复web管理界面:解决OAuth账户token刷新和代理配置相关问题 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
185 lines
7.0 KiB
YAML
185 lines
7.0 KiB
YAML
name: Release on Version Change
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'VERSION'
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
jobs:
|
|
check-and-release:
|
|
runs-on: ubuntu-latest
|
|
# 只处理由GitHub Actions提交的VERSION更新
|
|
if: github.event.pusher.name == 'github-actions[bot]'
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Verify only VERSION changed
|
|
id: verify
|
|
run: |
|
|
# 获取最后一次提交变更的文件
|
|
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD)
|
|
echo "Changed files: $CHANGED_FILES"
|
|
|
|
# 检查是否只有VERSION文件
|
|
if [ "$CHANGED_FILES" = "VERSION" ]; then
|
|
echo "Only VERSION file changed, proceeding with release"
|
|
echo "should_release=true" >> $GITHUB_OUTPUT
|
|
|
|
# 读取新版本号
|
|
NEW_VERSION=$(cat VERSION | tr -d '[:space:]')
|
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "Other files changed besides VERSION, skipping release"
|
|
echo "should_release=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Install git-cliff
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
run: |
|
|
wget -q https://github.com/orhun/git-cliff/releases/download/v1.4.0/git-cliff-1.4.0-x86_64-unknown-linux-gnu.tar.gz
|
|
tar -xzf git-cliff-1.4.0-x86_64-unknown-linux-gnu.tar.gz
|
|
chmod +x git-cliff-1.4.0/git-cliff
|
|
sudo mv git-cliff-1.4.0/git-cliff /usr/local/bin/
|
|
|
|
- name: Generate changelog
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
id: changelog
|
|
run: |
|
|
# 获取上一个tag以来的更新日志
|
|
LATEST_TAG=$(git describe --tags --abbrev=0 --exclude="${{ steps.verify.outputs.new_tag }}" 2>/dev/null || echo "")
|
|
if [ -n "$LATEST_TAG" ]; then
|
|
# 排除VERSION文件的提交
|
|
CHANGELOG=$(git-cliff --config .github/cliff.toml $LATEST_TAG..HEAD --strip header | grep -v "bump version" | sed '/^$/d' || echo "- 代码优化和改进")
|
|
else
|
|
CHANGELOG=$(git-cliff --config .github/cliff.toml --strip header || echo "- 初始版本发布")
|
|
fi
|
|
echo "content<<EOF" >> $GITHUB_OUTPUT
|
|
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
|
echo "EOF" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create and push tag
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
run: |
|
|
NEW_TAG="${{ steps.verify.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 GitHub Release
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
tag_name: ${{ steps.verify.outputs.new_tag }}
|
|
name: Release ${{ steps.verify.outputs.new_version }}
|
|
body: |
|
|
## 🐳 Docker 镜像
|
|
|
|
```bash
|
|
docker pull ${{ secrets.DOCKERHUB_USERNAME || 'weishaw' }}/claude-relay-service:${{ steps.verify.outputs.new_tag }}
|
|
docker pull ${{ secrets.DOCKERHUB_USERNAME || 'weishaw' }}/claude-relay-service:latest
|
|
```
|
|
|
|
## 📦 主要更新
|
|
|
|
${{ steps.changelog.outputs.content }}
|
|
|
|
## 📋 完整更新日志
|
|
|
|
查看 [所有版本](https://github.com/${{ github.repository }}/releases)
|
|
draft: false
|
|
prerelease: false
|
|
generate_release_notes: true
|
|
|
|
# Docker构建步骤
|
|
- name: Set up QEMU
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Docker Hub
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build and push Docker image
|
|
if: steps.verify.outputs.should_release == 'true'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:${{ steps.verify.outputs.new_tag }}
|
|
${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:latest
|
|
${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:${{ steps.verify.outputs.new_version }}
|
|
labels: |
|
|
org.opencontainers.image.version=${{ steps.verify.outputs.new_version }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Send Telegram Notification
|
|
if: steps.verify.outputs.should_release == 'true' && env.TELEGRAM_BOT_TOKEN != '' && env.TELEGRAM_CHAT_ID != ''
|
|
env:
|
|
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
continue-on-error: true
|
|
run: |
|
|
VERSION="${{ steps.verify.outputs.new_version }}"
|
|
TAG="${{ steps.verify.outputs.new_tag }}"
|
|
REPO="${{ github.repository }}"
|
|
|
|
# 获取更新内容并限制长度
|
|
CHANGELOG="${{ steps.changelog.outputs.content }}"
|
|
CHANGELOG_TRUNCATED=$(echo "$CHANGELOG" | head -c 1000)
|
|
if [ ${#CHANGELOG} -gt 1000 ]; then
|
|
CHANGELOG_TRUNCATED="${CHANGELOG_TRUNCATED}..."
|
|
fi
|
|
|
|
# 构建消息内容
|
|
MESSAGE="🚀 *Claude Relay Service 新版本发布!*"$'\n'$'\n'
|
|
MESSAGE+="📦 版本号: \`${VERSION}\`"$'\n'$'\n'
|
|
MESSAGE+="📝 *更新内容:*"$'\n'
|
|
MESSAGE+="${CHANGELOG_TRUNCATED}"$'\n'$'\n'
|
|
MESSAGE+="🐳 *Docker 部署:*"$'\n'
|
|
MESSAGE+="\`\`\`bash"$'\n'
|
|
MESSAGE+="docker pull weishaw/claude-relay-service:${TAG}"$'\n'
|
|
MESSAGE+="docker pull weishaw/claude-relay-service:latest"$'\n'
|
|
MESSAGE+="\`\`\`"$'\n'$'\n'
|
|
MESSAGE+="🔗 *相关链接:*"$'\n'
|
|
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG})"$'\n'
|
|
MESSAGE+="• [完整更新日志](https://github.com/${REPO}/releases)"$'\n'
|
|
MESSAGE+="• [Docker Hub](https://hub.docker.com/r/weishaw/claude-relay-service)"$'\n'$'\n'
|
|
MESSAGE+="#ClaudeRelay #Update #v${VERSION//./_}"
|
|
|
|
# 使用 jq 构建 JSON 并发送
|
|
jq -n \
|
|
--arg chat_id "${TELEGRAM_CHAT_ID}" \
|
|
--arg text "${MESSAGE}" \
|
|
'{
|
|
chat_id: $chat_id,
|
|
text: $text,
|
|
parse_mode: "Markdown",
|
|
disable_web_page_preview: false
|
|
}' | \
|
|
curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
|
-H "Content-Type: application/json" \
|
|
-d @- |