pipreqs/.git-hooks/post-commit
Lucas de Sousa Rosa ef7583a8dd 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`.
2023-11-29 22:47:18 -03:00

10 lines
387 B
Bash
Executable File

#! /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"