Skip to content

Release

Release #3

Workflow file for this run

name: Weekly Release
on:
schedule:
- 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@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v7
- 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
# Check for real commits excluding version bumps
# Exclude "chore: bump version" and commits created by GitHub Action
if [ -z "$last_tag_commit" ]; then
# No tag exists, check all commits
real_commits=$(git log --oneline --no-merges \
--author-not="GitHub Action <action@github.com>" \
--grep="^chore: bump version" --invert-grep)
else
# Tag exists, check commits since last tag
real_commits=$(git log $last_tag_commit..HEAD --oneline --no-merges \
--author-not="GitHub Action <action@github.com>" \
--grep="^chore: bump version" --invert-grep)
fi
if [ -n "$real_commits" ]; then
echo "has_new_commits=true" >> $GITHUB_OUTPUT
commit_count=$(echo "$real_commits" | wc -l)
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
echo "Found $commit_count real commits since last release (excluding version bumps)"
echo "$real_commits"
else
echo "has_new_commits=false" >> $GITHUB_OUTPUT
echo "No real commits since last release (only version bump commits found)"
fi
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
echo "release_date=$(date -u +"%Y-%m-%d")" >> $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: v${{ steps.version.outputs.new_version }}
body: |
## 🚀 Release v${{ steps.version.outputs.new_version }}
Released on: ${{ steps.changelog.outputs.release_date }}.
### Installation
```bash
uv add fastapi-cachex==${{ 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 }}
---
**Full Changelog**: https://github.com/allen0099/FastAPI-CacheX/compare/${{ steps.last_tag.outputs.last_tag }}...v${{ steps.version.outputs.new_version }}
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
- 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