Repository navigation
Release #1
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: Weekly Release | |
| on: | |
| schedule: | |
| # 每周一 00:00 UTC 运行 | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| id-token: write # Required for PyPI trusted publishing | |
| jobs: | |
| check-and-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v3 | |
| - name: Get last release tag | |
| id: last_tag | |
| run: | | |
| last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| echo "last_tag=$last_tag" >> $GITHUB_OUTPUT | |
| if [ -z "$last_tag" ]; then | |
| echo "last_tag_commit=$(git rev-list --max-parents=0 HEAD)" >> $GITHUB_OUTPUT | |
| else | |
| echo "last_tag_commit=$(git rev-list -n 1 $last_tag)" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check for new commits | |
| id: check_commits | |
| run: | | |
| last_tag_commit="${{ steps.last_tag.outputs.last_tag_commit }}" | |
| current_commit=$(git rev-parse HEAD) | |
| if [ "$last_tag_commit" != "$current_commit" ]; then | |
| echo "has_new_commits=true" >> $GITHUB_OUTPUT | |
| commit_count=$(git rev-list --count $last_tag_commit..HEAD 2>/dev/null || git rev-list --count HEAD) | |
| echo "commit_count=$commit_count" >> $GITHUB_OUTPUT | |
| echo "Found $commit_count new commits since last release" | |
| else | |
| echo "has_new_commits=false" >> $GITHUB_OUTPUT | |
| echo "No new commits since last release" | |
| fi | |
| - name: Bump minor version | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| id: version | |
| run: | | |
| uv version --bump minor | |
| new_version=$(uv version --short) | |
| echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
| echo "Version bumped to $new_version" | |
| - name: Configure git | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Commit version bump | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| run: | | |
| git add . | |
| git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}" | |
| git push origin HEAD:main 2>/dev/null || git push origin HEAD:master | |
| - name: Create and push tag | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| run: | | |
| git tag -a "v${{ steps.version.outputs.new_version }}" -m "Release v${{ steps.version.outputs.new_version }}" | |
| git push origin --tags | |
| - name: Generate changelog | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| id: changelog | |
| run: | | |
| last_tag="${{ steps.last_tag.outputs.last_tag }}" | |
| if [ -z "$last_tag" ]; then | |
| changelog=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| else | |
| changelog=$(git log $last_tag..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| fi | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$changelog" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Build package | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| run: uv build | |
| - name: Create GitHub Release | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.new_version }} | |
| name: Release v${{ steps.version.outputs.new_version }} | |
| body: | | |
| ## 🚀 Release v${{ steps.version.outputs.new_version }} | |
| **📊 Statistics:** | |
| - New commits: ${{ steps.check_commits.outputs.commit_count }} | |
| - Previous version: ${{ steps.last_tag.outputs.last_tag || 'Initial release' }} | |
| **📝 Changelog:** | |
| ${{ steps.changelog.outputs.changelog }} | |
| --- | |
| *This is an automated weekly release* | |
| draft: false | |
| prerelease: false | |
| make_latest: true | |
| files: | | |
| dist/*.whl | |
| dist/*.tar.gz | |
| - name: Publish to PyPI | |
| if: steps.check_commits.outputs.has_new_commits == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| print-hash: true | |
| - name: Summary | |
| if: always() | |
| run: | | |
| echo "### Weekly Release Summary" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.check_commits.outputs.has_new_commits }}" == "true" ]; then | |
| echo "✅ New commits found: ${{ steps.check_commits.outputs.commit_count }}" >> $GITHUB_STEP_SUMMARY | |
| echo "📦 Version bumped to: ${{ steps.version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "🏷️ Release created: v${{ steps.version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "🚀 Published to PyPI" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⏭️ No new commits since last release" >> $GITHUB_STEP_SUMMARY | |
| echo "ℹ️ Current version: $(uv version --short)" >> $GITHUB_STEP_SUMMARY | |
| fi |