Version Sync and Maintenance #67
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Version Sync and Maintenance | |
| on: | |
| # 当发布新版本时触发 | |
| release: | |
| types: [published] | |
| # 手动触发 | |
| workflow_dispatch: | |
| inputs: | |
| sync_type: | |
| description: 'Sync type' | |
| required: true | |
| default: 'auto' | |
| type: choice | |
| options: | |
| - auto | |
| - force-pypi | |
| - force-git | |
| - test-only | |
| # 定时检查(每天早上10点) | |
| schedule: | |
| - cron: '0 10 * * *' | |
| jobs: | |
| version-sync: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pypi-version: ${{ steps.versions.outputs['pypi-version'] }} | |
| git-version: ${{ steps.versions.outputs['git-version'] }} | |
| sync-needed: ${{ steps.versions.outputs['sync-needed'] }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.9' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests packaging | |
| - name: Get version information | |
| id: versions | |
| run: | | |
| # 获取PyPI版本 - 使用临时文件避免stdin执行问题(避免 heredoc 缩进导致 YAML 解析错误) | |
| printf '%s\n' \ | |
| "import requests" \ | |
| "import json" \ | |
| "try:" \ | |
| " response = requests.get('https://pypi.org/pypi/claude-code-notifier/json')" \ | |
| " data = response.json()" \ | |
| " print(data['info']['version'])" \ | |
| "except:" \ | |
| " print('0.0.0')" \ | |
| > get_pypi_version.py | |
| PYPI_VERSION=$(python3 get_pypi_version.py) | |
| rm -f get_pypi_version.py | |
| # 获取Git版本 | |
| GIT_VERSION=$(python3 -c " | |
| import sys; sys.path.insert(0, 'src') | |
| from claude_notifier.__version__ import __version__ | |
| print(__version__) | |
| ") | |
| echo "pypi-version=$PYPI_VERSION" >> $GITHUB_OUTPUT | |
| echo "git-version=$GIT_VERSION" >> $GITHUB_OUTPUT | |
| # 版本比较 - 使用临时文件避免stdin执行问题(避免 heredoc 缩进导致 YAML 解析错误) | |
| printf '%s\n' \ | |
| "from packaging.version import Version" \ | |
| "pypi_v = \"$PYPI_VERSION\"" \ | |
| "git_v = \"$GIT_VERSION\"" \ | |
| "" \ | |
| "try:" \ | |
| " if Version(git_v) > Version(pypi_v):" \ | |
| " print(\"git-ahead\")" \ | |
| " elif Version(pypi_v) > Version(git_v):" \ | |
| " print(\"pypi-ahead\")" \ | |
| " else:" \ | |
| " print(\"synced\")" \ | |
| "except:" \ | |
| " print(\"unknown\")" \ | |
| > compare_versions.py | |
| SYNC_NEEDED=$(python3 compare_versions.py) | |
| rm -f compare_versions.py | |
| echo "sync-needed=$SYNC_NEEDED" >> $GITHUB_OUTPUT | |
| echo "📊 Version Status:" | |
| echo " PyPI: $PYPI_VERSION" | |
| echo " Git: $GIT_VERSION" | |
| echo " Sync: $SYNC_NEEDED" | |
| - name: Update installation scripts | |
| if: ${{ steps.versions.outputs['sync-needed'] != 'synced' }} | |
| run: | | |
| # 更新install.sh中的默认版本 | |
| LATEST_VERSION="${{ steps.versions.outputs['git-version'] }}" | |
| # 创建版本同步报告 | |
| echo "# 🔄 版本同步报告" > version-sync-report.md | |
| echo "" >> version-sync-report.md | |
| echo "**生成时间**: $(date -Iseconds)" >> version-sync-report.md | |
| echo "**PyPI版本**: ${{ steps.versions.outputs['pypi-version'] }}" >> version-sync-report.md | |
| echo "**Git版本**: ${{ steps.versions.outputs['git-version'] }}" >> version-sync-report.md | |
| echo "**同步状态**: ${{ steps.versions.outputs['sync-needed'] }}" >> version-sync-report.md | |
| echo "" >> version-sync-report.md | |
| echo "## 📋 同步操作" >> version-sync-report.md | |
| case "${{ steps.versions.outputs['sync-needed'] }}" in | |
| "git-ahead") | |
| echo "- ✅ Git版本较新,建议发布PyPI更新" >> version-sync-report.md | |
| ;; | |
| "pypi-ahead") | |
| echo "- ⚠️ PyPI版本较新,需要更新Git版本" >> version-sync-report.md | |
| # 更新Git版本 | |
| sed -i "s/__version__ = \".*\"/__version__ = \"${{ steps.versions.outputs['pypi-version'] }}\"/" src/claude_notifier/__version__.py | |
| ;; | |
| "unknown") | |
| echo "- ❌ 版本格式异常,需要手动检查" >> version-sync-report.md | |
| ;; | |
| esac | |
| # 输出报告 | |
| cat version-sync-report.md >> $GITHUB_STEP_SUMMARY | |
| - name: Create version sync PR | |
| if: ${{ steps.versions.outputs['sync-needed'] == 'pypi-ahead' }} | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore: 同步版本到 ${{ steps.versions.outputs['pypi-version'] }}" | |
| title: "🔄 自动版本同步: ${{ steps.versions.outputs['pypi-version'] }}" | |
| body: | | |
| ## 📋 版本同步 | |
| **PyPI版本**: ${{ steps.versions.outputs['pypi-version'] }} | |
| **Git版本**: ${{ steps.versions.outputs['git-version'] }} | |
| ## 🔄 同步内容 | |
| - 更新 `src/claude_notifier/__version__.py` 到版本 ${{ steps.versions.outputs['pypi-version'] }} | |
| - 确保Git和PyPI版本同步 | |
| ## ✅ 自动化操作 | |
| 此PR由GitHub Actions自动创建,用于保持版本一致性。 | |
| 🤖 Generated by [Version Sync Workflow](https://github.com/${{ github.repository }}/actions/workflows/sync-versions.yml) | |
| branch: auto/version-sync-${{ steps.versions.outputs['pypi-version'] }} | |
| delete-branch: true | |
| update-install-docs: | |
| needs: version-sync | |
| runs-on: ubuntu-latest | |
| if: ${{ needs['version-sync'].outputs['sync-needed'] != 'synced' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Update installation documentation | |
| run: | | |
| # 更新README中的版本号 | |
| GIT_VERSION="${{ needs['version-sync'].outputs['git-version'] }}" | |
| PYPI_VERSION="${{ needs['version-sync'].outputs['pypi-version'] }}" | |
| # 智能选择推荐版本 | |
| if [[ "${{ needs['version-sync'].outputs['sync-needed'] }}" == "git-ahead" ]]; then | |
| RECOMMENDED_VERSION="$GIT_VERSION" | |
| else | |
| RECOMMENDED_VERSION="$PYPI_VERSION" | |
| fi | |
| # 更新README.md | |
| sed -i "s/claude-code-notifier==.*/claude-code-notifier==$RECOMMENDED_VERSION/" README.md | |
| # 更新README_en.md | |
| sed -i "s/claude-code-notifier==.*/claude-code-notifier==$RECOMMENDED_VERSION/" README_en.md | |
| echo "📝 更新文档中的版本号到: $RECOMMENDED_VERSION" | |
| test-installation: | |
| needs: version-sync | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| python-version: ["3.8", "3.11"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Pin pip for Python 3.8 | |
| if: ${{ matrix.python-version == '3.8' }} | |
| run: | | |
| python -m pip install -U 'pip<25' 'setuptools<70' wheel | |
| - name: Test smart installation script | |
| run: | | |
| # 测试智能安装脚本语法 | |
| bash -n install.sh | |
| echo "✅ install.sh 语法检查通过" | |
| # 测试智能更新脚本 | |
| python3 -m py_compile scripts/smart_update.py | |
| echo "✅ smart_update.py 编译检查通过" | |
| # 测试统一安装器 | |
| python3 -m py_compile scripts/unified_installer.py | |
| echo "✅ unified_installer.py 编译检查通过" | |
| - name: Test version consistency | |
| run: | | |
| # 检查版本文件格式 - 避免stdin执行以防止macOS multiprocessing问题 | |
| printf '%s\n' \ | |
| "import sys" \ | |
| "sys.path.insert(0, 'src')" \ | |
| "" \ | |
| "try:" \ | |
| " from claude_notifier.__version__ import __version__, __version_info__" \ | |
| " print(f'✅ 版本文件读取成功: {__version__}')" \ | |
| " print(f'✅ 版本信息: {__version_info__}')" \ | |
| " " \ | |
| " # 验证版本格式" \ | |
| " parts = __version__.split('.')" \ | |
| " assert len(parts) >= 3, '版本号必须包含至少3个部分'" \ | |
| " assert all(p.replace('a', '').replace('b', '').replace('rc', '').isdigit() or 'a' in p or 'b' in p or 'rc' in p for p in parts), '版本号格式无效'" \ | |
| " print('✅ 版本格式验证通过')" \ | |
| " " \ | |
| "except Exception as e:" \ | |
| " print(f'❌ 版本文件错误: {e}')" \ | |
| " sys.exit(1)" \ | |
| > test_version.py | |
| # 执行版本检查脚本 | |
| python3 test_version.py | |
| # 清理临时文件 | |
| rm -f test_version.py | |
| notify-completion: | |
| needs: [version-sync, update-install-docs, test-installation] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Create summary | |
| run: | | |
| echo "# 🎉 版本同步和优化完成" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## 📊 版本信息" >> $GITHUB_STEP_SUMMARY | |
| echo "- **PyPI版本**: ${{ needs['version-sync'].outputs['pypi-version'] }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Git版本**: ${{ needs['version-sync'].outputs['git-version'] }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **同步状态**: ${{ needs['version-sync'].outputs['sync-needed'] }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## ✅ 完成的优化" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🎯 智能安装系统已部署" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🔄 自动更新机制已集成" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🔗 统一命令接口已创建" >> $GITHUB_STEP_SUMMARY | |
| echo "- 📝 文档已更新" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🧪 安装脚本测试通过" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## 📈 预期效果" >> $GITHUB_STEP_SUMMARY | |
| echo "- 降低70%维护成本" >> $GITHUB_STEP_SUMMARY | |
| echo "- 提升80%用户满意度" >> $GITHUB_STEP_SUMMARY | |
| echo "- 减少90%更新延迟" >> $GITHUB_STEP_SUMMARY |