Skip to content

Commit

Permalink
add pre and post commit hooks for bumpver
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas committed Jan 3, 2025
1 parent b33d3f8 commit 808584a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .bin/bumpver-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

update_changelog() {
local repo_url
repo_url=$(git remote get-url origin | tr -d '\n' | sed 's/\.git$//')

sed -i "0,/## \[Unreleased\]/s/## \[Unreleased\]/## [$BUMPVER_NEW_VERSION]/" CHANGELOG.md
sed -i "/## \[$BUMPVER_NEW_VERSION\]/i ## [Unreleased]\n" CHANGELOG.md
echo "[$BUMPVER_NEW_VERSION]: $repo_url/releases/tag/v$BUMPVER_NEW_VERSION" >>CHANGELOG.md
sed -i "s|\[unreleased\]: .*|[unreleased]: $repo_url/compare/v$BUMPVER_NEW_VERSION...HEAD|" CHANGELOG.md

git add CHANGELOG.md
git commit -m "update CHANGELOG for version $BUMPVER_NEW_VERSION"
}

update_uvlock() {
uv lock

if ! git status --porcelain | grep -q "uv.lock"; then
echo "No changes to uv.lock, skipping commit"
return 0
fi

git add uv.lock
git commit -m "update uv.lock for version $BUMPVER_NEW_VERSION"
}

main() {
update_changelog
update_uvlock
}

main "$@"
22 changes: 22 additions & 0 deletions .bin/bumpver-pre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euo pipefail

create_release_branch() {
local release_branch="release-v${BUMPVER_NEW_VERSION}"

if git show-ref --quiet "refs/heads/$release_branch" ||
git show-ref --quiet "refs/remotes/origin/$release_branch"; then
echo "Error: Branch $release_branch already exists locally or remotely" >&2
exit 1
fi

git checkout -b "$release_branch"
echo "Created and switched to branch: $release_branch"
}

main() {
create_release_branch
}

main "$@"
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Source = "https://github.com/joshuadavidthomas/django-language-server"
commit = true
commit_message = ":bookmark: bump version {old_version} -> {new_version}"
current_version = "5.1.0-alpha.1"
push = false # set to false for CI
post_commit_hook = ".bin/bumpver-post.sh"
pre_commit_hook = ".bin/bumpver-pre.sh"
push = false
tag = false
version_pattern = "MAJOR.MINOR.PATCH[-TAG[.NUM]]"

Expand Down

0 comments on commit 808584a

Please sign in to comment.