|
| 1 | +name: Release Prepare |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump_type: |
| 7 | + description: 'Version bump type' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + - pre |
| 15 | + changelog: |
| 16 | + description: 'Custom changelog entry (optional - leave empty to auto-generate)' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + prepare-release: |
| 26 | + name: Prepare Release |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + version: ${{ steps.bump.outputs.version }} |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Validate running from main |
| 33 | + if: github.ref != 'refs/heads/main' |
| 34 | + run: | |
| 35 | + echo "❌ ERROR: Must run from main branch, got ${{ github.ref }}" |
| 36 | + exit 1 |
| 37 | +
|
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v5 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + - name: Setup Python |
| 44 | + uses: actions/setup-python@v6 |
| 45 | + with: |
| 46 | + python-version: '3.10' |
| 47 | + |
| 48 | + - name: Configure git |
| 49 | + run: | |
| 50 | + git config --global user.name "github-actions[bot]" |
| 51 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | +
|
| 53 | + - name: Install uv |
| 54 | + run: | |
| 55 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 56 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 57 | +
|
| 58 | + - name: Get current version |
| 59 | + id: current |
| 60 | + run: | |
| 61 | + VERSION=$(grep -m1 -oP '^version = "\K[^"]+' pyproject.toml) |
| 62 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 63 | + echo "Current version: $VERSION" |
| 64 | +
|
| 65 | + - name: Bump version |
| 66 | + id: bump |
| 67 | + env: |
| 68 | + CHANGELOG_INPUT: ${{ github.event.inputs.changelog }} |
| 69 | + BUMP_TYPE: ${{ github.event.inputs.bump_type }} |
| 70 | + run: | |
| 71 | + chmod +x scripts/bump_version.py |
| 72 | +
|
| 73 | + if [ -z "$CHANGELOG_INPUT" ]; then |
| 74 | + echo "ℹ️ No custom changelog provided. Will auto-generate from commits." |
| 75 | + fi |
| 76 | +
|
| 77 | + if [ -n "$CHANGELOG_INPUT" ]; then |
| 78 | + python scripts/bump_version.py "$BUMP_TYPE" --changelog "$CHANGELOG_INPUT" |
| 79 | + else |
| 80 | + python scripts/bump_version.py "$BUMP_TYPE" |
| 81 | + fi |
| 82 | +
|
| 83 | + uv lock --no-progress |
| 84 | +
|
| 85 | + NEW_VERSION=$(grep -m1 -oP '^version = "\K[^"]+' pyproject.toml) |
| 86 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 87 | + echo "New version: $NEW_VERSION" |
| 88 | +
|
| 89 | + - name: Create release branch and push |
| 90 | + env: |
| 91 | + NEW_VERSION: ${{ steps.bump.outputs.version }} |
| 92 | + run: | |
| 93 | + BRANCH_NAME="release/v$NEW_VERSION" |
| 94 | +
|
| 95 | + if git ls-remote --exit-code --heads origin $BRANCH_NAME; then |
| 96 | + echo "⚠️ Branch $BRANCH_NAME already exists. Deleting it first..." |
| 97 | + git push origin --delete $BRANCH_NAME |
| 98 | + fi |
| 99 | +
|
| 100 | + if git show-ref --verify --quiet refs/heads/$BRANCH_NAME; then |
| 101 | + git branch -D $BRANCH_NAME |
| 102 | + fi |
| 103 | +
|
| 104 | + git checkout -b $BRANCH_NAME |
| 105 | + git add -A |
| 106 | + git commit -m "chore: bump version to $NEW_VERSION |
| 107 | +
|
| 108 | + Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>" |
| 109 | +
|
| 110 | + git push origin $BRANCH_NAME |
| 111 | +
|
| 112 | + COMMITTED_VERSION=$(git show HEAD:pyproject.toml | grep -m1 -oP '^version = "\K[^"]+') |
| 113 | + if [ "$COMMITTED_VERSION" != "$NEW_VERSION" ]; then |
| 114 | + echo "❌ ERROR: Version not committed correctly!" |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | +
|
| 118 | + - name: Create Pull Request |
| 119 | + env: |
| 120 | + GH_TOKEN: ${{ github.token }} |
| 121 | + NEW_VERSION: ${{ steps.bump.outputs.version }} |
| 122 | + GITHUB_REF: ${{ github.ref }} |
| 123 | + GITHUB_ACTOR: ${{ github.actor }} |
| 124 | + run: | |
| 125 | + BRANCH_NAME="release/v$NEW_VERSION" |
| 126 | +
|
| 127 | + WARNING_TEXT="" |
| 128 | + if [ "$GITHUB_REF" != "refs/heads/main" ]; then |
| 129 | + WARNING_TEXT="**WARNING**: Not running from main branch!" |
| 130 | + else |
| 131 | + WARNING_TEXT="✅ Running from main branch" |
| 132 | + fi |
| 133 | +
|
| 134 | + gh pr create \ |
| 135 | + --base main \ |
| 136 | + --head "$BRANCH_NAME" \ |
| 137 | + --title "Release v$NEW_VERSION" \ |
| 138 | + --body "## 🚀 Release v$NEW_VERSION |
| 139 | +
|
| 140 | + This PR was automatically created by the release workflow. |
| 141 | +
|
| 142 | + ### ⚠️ Pre-merge Checklist |
| 143 | + - [ ] Review CHANGELOG.md - ensure it has meaningful release notes |
| 144 | + - [ ] Verify version numbers are correct in all files |
| 145 | + - [ ] All CI checks are passing |
| 146 | +
|
| 147 | + ### 📝 How to improve changelog |
| 148 | + If the auto-generated changelog isn't good enough: |
| 149 | + 1. Edit CHANGELOG.md in this PR |
| 150 | + 2. Commit the changes |
| 151 | + 3. Then approve and merge |
| 152 | +
|
| 153 | + ### 🔄 Release Process |
| 154 | + After merging this PR, the **release-publish** workflow will: |
| 155 | + 1. Build the package from main |
| 156 | + 2. Require **manual approval** before publishing to PyPI |
| 157 | + 3. Publish to PyPI, create tag and GitHub release |
| 158 | +
|
| 159 | + ### 🚨 Running from: $GITHUB_REF |
| 160 | + $WARNING_TEXT |
| 161 | +
|
| 162 | + --- |
| 163 | + *Triggered by @$GITHUB_ACTOR*" |
| 164 | +
|
| 165 | + test-and-build: |
| 166 | + name: Test and Build |
| 167 | + needs: prepare-release |
| 168 | + runs-on: ubuntu-latest |
| 169 | + |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v5 |
| 172 | + with: |
| 173 | + ref: release/v${{ needs.prepare-release.outputs.version }} |
| 174 | + |
| 175 | + - name: Verify version before build |
| 176 | + env: |
| 177 | + EXPECTED_VERSION: ${{ needs.prepare-release.outputs.version }} |
| 178 | + run: | |
| 179 | + ACTUAL_VERSION=$(grep -m1 -oP '^version = "\K[^"]+' pyproject.toml) |
| 180 | + echo "Expected version: $EXPECTED_VERSION" |
| 181 | + echo "Actual version: $ACTUAL_VERSION" |
| 182 | +
|
| 183 | + if [ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]; then |
| 184 | + echo "❌ ERROR: Version mismatch!" |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | + echo "✓ Version verified: $ACTUAL_VERSION" |
| 188 | +
|
| 189 | + - name: Set up Python |
| 190 | + uses: actions/setup-python@v6 |
| 191 | + with: |
| 192 | + python-version: '3.10' |
| 193 | + |
| 194 | + - name: Install uv |
| 195 | + run: | |
| 196 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 197 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 198 | +
|
| 199 | + - name: Setup build environment |
| 200 | + run: | |
| 201 | + uv venv |
| 202 | + source .venv/bin/activate |
| 203 | + uv pip install build twine |
| 204 | +
|
| 205 | + - name: Build and check package |
| 206 | + run: | |
| 207 | + source .venv/bin/activate |
| 208 | + uv build |
| 209 | + twine check dist/* |
| 210 | + echo "=== Package contents ===" |
| 211 | + python -m zipfile -l dist/*.whl | head -20 |
| 212 | +
|
| 213 | + - name: Upload artifacts |
| 214 | + uses: actions/upload-artifact@v4 |
| 215 | + with: |
| 216 | + name: dist |
| 217 | + path: dist/ |
0 commit comments