diff --git a/.github/workflows/release-on-version.yml b/.github/workflows/auto-release-pipeline.yml similarity index 54% rename from .github/workflows/release-on-version.yml rename to .github/workflows/auto-release-pipeline.yml index 2436da3c..8db44694 100644 --- a/.github/workflows/release-on-version.yml +++ b/.github/workflows/auto-release-pipeline.yml @@ -1,21 +1,19 @@ -name: Release on Version Change +name: Auto Release Pipeline on: push: branches: - main - paths: - - 'VERSION' permissions: contents: write packages: write jobs: - check-and-release: + release-pipeline: runs-on: ubuntu-latest - # 只处理由GitHub Actions提交的VERSION更新 - if: github.event.pusher.name == 'github-actions[bot]' + # 跳过由GitHub Actions创建的提交,避免死循环 + if: github.event.pusher.name != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]') steps: - name: Checkout code uses: actions/checkout@v4 @@ -23,29 +21,89 @@ jobs: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - - name: Verify only VERSION changed - id: verify + - name: Check if version bump is needed + id: check run: | - # 获取最后一次提交变更的文件 - CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD) - echo "Changed files: $CHANGED_FILES" + # 获取当前提交的文件变更 + CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD 2>/dev/null || git diff --name-only $(git rev-list --max-parents=0 HEAD)..HEAD) + echo "Changed files:" + echo "$CHANGED_FILES" - # 检查是否只有VERSION文件 - if [ "$CHANGED_FILES" = "VERSION" ]; then - echo "Only VERSION file changed, proceeding with release" - echo "should_release=true" >> $GITHUB_OUTPUT + # 检查是否只有无关文件(.md, docs/, .github/等) + SIGNIFICANT_CHANGES=false + while IFS= read -r file; do + # 跳过空行 + [ -z "$file" ] && continue - # 读取新版本号 - NEW_VERSION=$(cat VERSION | tr -d '[:space:]') - echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT - echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT + # 检查是否是需要忽略的文件 + if [[ ! "$file" =~ \.(md|txt)$ ]] && + [[ ! "$file" =~ ^docs/ ]] && + [[ ! "$file" =~ ^\.github/ ]] && + [[ "$file" != "VERSION" ]] && + [[ "$file" != ".gitignore" ]] && + [[ "$file" != "LICENSE" ]]; then + echo "Found significant change in: $file" + SIGNIFICANT_CHANGES=true + break + fi + done <<< "$CHANGED_FILES" + + if [ "$SIGNIFICANT_CHANGES" = true ]; then + echo "Significant changes detected, version bump needed" + echo "needs_bump=true" >> $GITHUB_OUTPUT else - echo "Other files changed besides VERSION, skipping release" - echo "should_release=false" >> $GITHUB_OUTPUT + echo "No significant changes, skipping version bump" + echo "needs_bump=false" >> $GITHUB_OUTPUT fi + - name: Get current version + if: steps.check.outputs.needs_bump == 'true' + id: get_version + run: | + # 获取最新的tag版本 + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Latest tag: $LATEST_TAG" + + # 从tag中提取版本号 + VERSION=${LATEST_TAG#v} + echo "Current version: $VERSION" + echo "current_version=$VERSION" >> $GITHUB_OUTPUT + + - name: Calculate next version + if: steps.check.outputs.needs_bump == 'true' + id: next_version + run: | + VERSION="${{ steps.get_version.outputs.current_version }}" + + # 分割版本号 + 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}" + + echo "New version: $NEW_VERSION" + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT + + - name: Update VERSION file + if: steps.check.outputs.needs_bump == 'true' + run: | + echo "${{ steps.next_version.outputs.new_version }}" > VERSION + + # 配置git + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # 提交VERSION文件 - 添加 [skip ci] 以避免再次触发 + git add VERSION + git commit -m "chore: sync VERSION file with release ${{ steps.next_version.outputs.new_tag }} [skip ci]" + - name: Install git-cliff - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == '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 @@ -53,11 +111,11 @@ jobs: sudo mv git-cliff-1.4.0/git-cliff /usr/local/bin/ - name: Generate changelog - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == 'true' id: changelog run: | # 获取上一个tag以来的更新日志 - LATEST_TAG=$(git describe --tags --abbrev=0 --exclude="${{ steps.verify.outputs.new_tag }}" 2>/dev/null || echo "") + LATEST_TAG=$(git describe --tags --abbrev=0 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 "- 代码优化和改进") @@ -69,25 +127,23 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Create and push tag - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == '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" + NEW_TAG="${{ steps.next_version.outputs.new_tag }}" git tag -a "$NEW_TAG" -m "Release $NEW_TAG" - git push origin "$NEW_TAG" + git push origin HEAD:main "$NEW_TAG" - name: Create GitHub Release - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == 'true' uses: softprops/action-gh-release@v1 with: - tag_name: ${{ steps.verify.outputs.new_tag }} - name: Release ${{ steps.verify.outputs.new_version }} + 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.verify.outputs.new_tag }} + 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 ``` @@ -104,15 +160,15 @@ jobs: # Docker构建步骤 - name: Set up QEMU - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == 'true' uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == 'true' uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == 'true' uses: docker/login-action@v3 with: registry: docker.io @@ -120,31 +176,31 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker image - if: steps.verify.outputs.should_release == 'true' + if: steps.check.outputs.needs_bump == '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:${{ steps.next_version.outputs.new_tag }} ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:latest - ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:${{ steps.verify.outputs.new_version }} + ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:${{ steps.next_version.outputs.new_version }} labels: | - org.opencontainers.image.version=${{ steps.verify.outputs.new_version }} + org.opencontainers.image.version=${{ steps.next_version.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 != '' + if: steps.check.outputs.needs_bump == '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 }}" + VERSION="${{ steps.next_version.outputs.new_version }}" + TAG="${{ steps.next_version.outputs.new_tag }}" REPO="${{ github.repository }}" # 获取更新内容并限制长度 diff --git a/.github/workflows/auto-version-bump.yml b/.github/workflows/auto-version-bump.yml deleted file mode 100644 index ea5a6834..00000000 --- a/.github/workflows/auto-version-bump.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: Auto Version Bump - -on: - push: - branches: - - main - -permissions: - contents: write - -jobs: - version-bump: - runs-on: ubuntu-latest - # 跳过由GitHub Actions创建的提交,避免死循环 - 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: Check if version bump is needed - id: check - run: | - # 获取当前提交的文件变更 - CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD 2>/dev/null || git diff --name-only $(git rev-list --max-parents=0 HEAD)..HEAD) - echo "Changed files:" - echo "$CHANGED_FILES" - - # 检查是否只有无关文件(.md, docs/, .github/等) - SIGNIFICANT_CHANGES=false - while IFS= read -r file; do - # 跳过空行 - [ -z "$file" ] && continue - - # 检查是否是需要忽略的文件 - if [[ ! "$file" =~ \.(md|txt)$ ]] && - [[ ! "$file" =~ ^docs/ ]] && - [[ ! "$file" =~ ^\.github/ ]] && - [[ "$file" != "VERSION" ]] && - [[ "$file" != ".gitignore" ]] && - [[ "$file" != "LICENSE" ]]; then - echo "Found significant change in: $file" - SIGNIFICANT_CHANGES=true - break - fi - done <<< "$CHANGED_FILES" - - if [ "$SIGNIFICANT_CHANGES" = true ]; then - echo "Significant changes detected, version bump needed" - echo "needs_bump=true" >> $GITHUB_OUTPUT - else - echo "No significant changes, skipping version bump" - echo "needs_bump=false" >> $GITHUB_OUTPUT - fi - - - name: Get current version - if: steps.check.outputs.needs_bump == 'true' - id: get_version - run: | - # 获取最新的tag版本 - LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") - echo "Latest tag: $LATEST_TAG" - - # 从tag中提取版本号 - VERSION=${LATEST_TAG#v} - echo "Current version: $VERSION" - echo "current_version=$VERSION" >> $GITHUB_OUTPUT - - - name: Calculate next version - if: steps.check.outputs.needs_bump == 'true' - id: next_version - run: | - VERSION="${{ steps.get_version.outputs.current_version }}" - - # 分割版本号 - 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}" - - echo "New version: $NEW_VERSION" - echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT - - - name: Update VERSION file - if: steps.check.outputs.needs_bump == 'true' - run: | - echo "${{ steps.next_version.outputs.new_version }}" > VERSION - - # 配置git - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - # 提交VERSION文件 - git add VERSION - git commit -m "chore: bump version to ${{ steps.next_version.outputs.new_version }}" - git push origin main \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 4d34f1a4..00000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,101 +0,0 @@ -name: Docker Build & Push - -on: - push: - tags: - - 'v*' - workflow_dispatch: - -env: - REGISTRY: docker.io - IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Docker Hub - if: github.event_name != 'pull_request' - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}},priority=1000 - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha,prefix=sha-,format=short - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - test: - needs: build - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' - permissions: - contents: read - security-events: write - - steps: - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - image-ref: ${{ env.IMAGE_NAME }}:latest - format: 'sarif' - output: 'trivy-results.sarif' - - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v3 - if: always() - with: - sarif_file: 'trivy-results.sarif' - - update-description: - needs: build - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Update Docker Hub Description - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service - readme-filepath: ./README.md - short-description: "Claude Code API Relay Service - 多账户管理的Claude API中转服务" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 603fee45..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Create Release - -on: - push: - tags: - - 'v*' - -permissions: - contents: write - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install git-cliff - 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 - id: changelog - run: | - CHANGELOG=$(git-cliff --config .github/cliff.toml --latest --strip header) - echo "content<> $GITHUB_OUTPUT - echo "$CHANGELOG" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Create Release - uses: softprops/action-gh-release@v1 - with: - body: | - ## 🐳 Docker 镜像 - - ```bash - docker pull ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:${{ github.ref_name }} - docker pull ${{ secrets.DOCKERHUB_USERNAME }}/claude-relay-service:latest - ``` - - ## 📦 主要更新 - - ${{ steps.changelog.outputs.content }} - - ## 📋 完整更新日志 - - 查看 [所有版本](https://github.com/${{ github.repository }}/releases) - - draft: false - prerelease: false - generate_release_notes: true \ No newline at end of file