Add a git hook for automatic tagging

- When the version field of `pyproject.toml` changes, after the changes have been committed, a tag is created with `git tag` that refers to the new version.
- It's necessary to configure the `git-hooks' directory `git config core.hooksPath .git-hooks`.
This commit is contained in:
Lucas de Sousa Rosa 2023-11-29 22:47:18 -03:00
parent 4826afdac0
commit ef7583a8dd

10
.git-hooks/post-commit Executable file
View File

@ -0,0 +1,10 @@
#! /bin/bash
version=`git diff HEAD^..HEAD -- "$(git rev-parse --show-toplevel)"/pyproject.toml | grep -m 1 '^\+.*version' | sed -s 's/[^A-Z0-9\.\-]//g'`
if [[ ! $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(\-[A-Z]+\.[0-9]+)?$ ]]; then
echo -e "Skip tag: invalid version '$version'"
exit 1
fi
git tag -a "v$version" -m "`git log -1 --format=%s`"
echo "Created a new tag, $version"