diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 122e56b5..643cf95a 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -23,6 +23,34 @@ jobs: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} + - name: Sync VERSION file with latest release + run: | + # 获取所有标签并排序 + LATEST_TAG=$(git tag --sort=-version:refname | head -1 || echo "v0.0.0") + if [ "$LATEST_TAG" != "v0.0.0" ]; then + # 提取版本号(去掉 v 前缀) + LATEST_VERSION=${LATEST_TAG#v} + + # 读取当前 VERSION 文件 + CURRENT_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0") + + # 如果版本不一致,强制同步 + if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then + echo "Syncing VERSION file: $CURRENT_VERSION -> $LATEST_VERSION" + echo "$LATEST_VERSION" > VERSION + git add VERSION + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -m "chore: sync VERSION file with release $LATEST_TAG [skip ci]" || echo "No changes to commit" + git push origin main || echo "Nothing to push" + + # 更新本地仓库状态 + git pull origin main --rebase || echo "No changes to pull" + else + echo "VERSION file is already in sync: $CURRENT_VERSION" + fi + fi + - name: Get latest tag id: get_latest_tag run: | @@ -130,7 +158,7 @@ jobs: - name: Update VERSION file if: steps.check_changes.outputs.has_changes == 'true' run: | - # 更新 VERSION 文件 + # 强制更新 VERSION 文件为最新版本 echo "${{ steps.next_version.outputs.new_version }}" > VERSION # 检查是否有更改 @@ -141,18 +169,17 @@ jobs: echo "Updated VERSION file to ${{ steps.next_version.outputs.new_version }}" fi - - name: Update CHANGELOG.md + - name: Commit VERSION update if: steps.check_changes.outputs.has_changes == 'true' run: | - # 生成完整的 CHANGELOG - git cliff --config .github/cliff.toml --output CHANGELOG.md - - # 提交 CHANGELOG 和 VERSION 更新 - if git diff --quiet CHANGELOG.md VERSION; then - echo "No changes to CHANGELOG.md or VERSION" + # 提交 VERSION 更新 + if git diff --quiet VERSION; then + echo "No changes to VERSION" else - git add CHANGELOG.md VERSION - git commit -m "chore: update CHANGELOG.md and VERSION for ${{ steps.next_version.outputs.new_tag }} [skip ci]" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add VERSION + git commit -m "chore: update VERSION to ${{ steps.next_version.outputs.new_version }} for ${{ steps.next_version.outputs.new_tag }} [skip ci]" git push origin main fi