|
| 1 | +name: Prepare Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version override (leave empty to use release-drafter's resolved version)" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + prepare-release: |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v5 |
| 22 | + |
| 23 | + - name: Install uv |
| 24 | + uses: astral-sh/setup-uv@v5 |
| 25 | + |
| 26 | + - name: Get draft release |
| 27 | + id: draft |
| 28 | + uses: release-drafter/release-drafter@v6 |
| 29 | + with: |
| 30 | + disable-autolabeler: true |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + |
| 34 | + - name: Determine version |
| 35 | + id: version |
| 36 | + env: |
| 37 | + VERSION_OVERRIDE: ${{ inputs.version }} |
| 38 | + RESOLVED_VERSION: ${{ steps.draft.outputs.resolved_version }} |
| 39 | + run: | |
| 40 | + if [ -n "$VERSION_OVERRIDE" ]; then |
| 41 | + VERSION="$VERSION_OVERRIDE" |
| 42 | + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 43 | + echo "::error::Version must be in semver format (e.g., 0.2.0)" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + else |
| 47 | + VERSION="$RESOLVED_VERSION" |
| 48 | + fi |
| 49 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + - name: Update changelog |
| 52 | + uses: stefanzweifel/changelog-updater-action@v1 |
| 53 | + with: |
| 54 | + latest-version: ${{ steps.version.outputs.version }} |
| 55 | + release-notes: ${{ steps.draft.outputs.body }} |
| 56 | + path-to-changelog: CHANGELOG.md |
| 57 | + heading-text: "[${{ steps.version.outputs.version }}]" |
| 58 | + |
| 59 | + - name: Bump version |
| 60 | + env: |
| 61 | + VERSION: ${{ steps.version.outputs.version }} |
| 62 | + run: sed -i '0,/^version = ".*"/s//version = "'"$VERSION"'"/' pyproject.toml |
| 63 | + |
| 64 | + - name: Update uv.lock |
| 65 | + run: uv lock |
| 66 | + |
| 67 | + - name: Stage files |
| 68 | + run: git add CHANGELOG.md pyproject.toml uv.lock |
| 69 | + |
| 70 | + - name: Create release PR |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + VERSION: ${{ steps.version.outputs.version }} |
| 74 | + run: | |
| 75 | + BRANCH="release/${VERSION}" |
| 76 | +
|
| 77 | + git checkout -b "$BRANCH" |
| 78 | + git -c user.name="github-actions[bot]" \ |
| 79 | + -c user.email="github-actions[bot]@users.noreply.github.com" \ |
| 80 | + commit -m "release: ${VERSION}" |
| 81 | + git push origin "$BRANCH" |
| 82 | +
|
| 83 | + BODY="## Release ${VERSION} |
| 84 | +
|
| 85 | + This PR was automatically generated by the release workflow. |
| 86 | +
|
| 87 | + ### Checklist |
| 88 | + - [ ] Changelog looks correct |
| 89 | + - [ ] Version numbers are correct" |
| 90 | +
|
| 91 | + gh pr create \ |
| 92 | + --title "release: ${VERSION}" \ |
| 93 | + --body "$BODY" \ |
| 94 | + --base main \ |
| 95 | + --head "$BRANCH" |
0 commit comments