Skip to content

Bump version

Bump version #44

Workflow file for this run

name: Bump version
on:
workflow_dispatch:
inputs:
increment:
description: "Version increment type"
required: false
default: ""
type: choice
options:
- ""
- "PATCH"
- "MINOR"
- "MAJOR"
permissions:
contents: write
concurrency:
group: release-operations
cancel-in-progress: false
jobs:
bump:
name: Bump version and release
if: "github.event.head_commit == null || !startsWith(github.event.head_commit.message, 'bump:')"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
with:
enable-cache: true
cache-python: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
run: uv python install 3.12
- name: Install dev dependencies
run: uv sync --frozen --group dev
- name: Get next version
id: get_version
run: |
if [ -n "${{ inputs.increment }}" ]; then
NEXT=$(uv run cz bump --get-next --yes --increment "${{ inputs.increment }}")
else
NEXT=$(uv run cz bump --get-next --yes)
fi
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
- name: Replace Unreleased header in CHANGELOG
id: unreleased
run: |
if grep -q '^## Unreleased' CHANGELOG.md; then
DATE=$(date -u +%Y-%m-%d)
sed -i.bak "s/^## Unreleased.*/## ${{ steps.get_version.outputs.version }} ($DATE)/" CHANGELOG.md
rm -f CHANGELOG.md.bak
echo "replaced=true" >> "$GITHUB_OUTPUT"
else
echo "replaced=false" >> "$GITHUB_OUTPUT"
fi
# Run cz bump on the runner (not commitizen-action Docker) so Commitizen pre_bump_hooks can run `uv lock`.
- name: Bump version and changelog
id: bump
env:
PAT: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
previous_version=$(uv run cz version --project)
echo "previous_version=${previous_version}" >> "$GITHUB_OUTPUT"
cz_args=(uv run cz --no-raise 21 bump --yes)
if [ -n "${{ inputs.increment }}" ]; then
cz_args+=(--increment "${{ inputs.increment }}")
fi
if [ "${{ steps.unreleased.outputs.replaced }}" = "true" ]; then
cz_args+=(--files-only)
else
cz_args+=(--changelog)
fi
"${cz_args[@]}"
version=$(uv run cz version --project)
echo "version=${version}" >> "$GITHUB_OUTPUT"
if [ "${{ steps.unreleased.outputs.replaced }}" != "true" ] && [ "${version}" != "${previous_version}" ]; then
remote="https://x-access-token:${PAT}@github.com/${GITHUB_REPOSITORY}.git"
branch="${GITHUB_REF_NAME}"
git pull "$remote" "$branch" --rebase
git push "$remote" "HEAD:${branch}" --tags
fi
- name: Commit, tag and push (single commit when using custom changelog)
if: steps.unreleased.outputs.replaced == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md pyproject.toml litestar_auth/__init__.py uv.lock
git commit -m "bump: version ${{ steps.bump.outputs.previous_version }} → ${{ steps.bump.outputs.version }}"
git tag "${{ steps.bump.outputs.version }}"
git push origin HEAD --tags
- name: Prepare release notes
id: release_notes
run: |
awk '/^## [0-9]+\.[0-9]+\.[0-9]+ / {if(d) exit; d=1; next} d && /^## / {exit} d {print}' CHANGELOG.md > release_body.md
echo "path=release_body.md" >> "$GITHUB_OUTPUT"
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release create "${{ steps.bump.outputs.version }}" \
--title "${{ steps.bump.outputs.version }}" \
--notes-file release_body.md