From ef7583a8dd0776ba43ccf14350ee166512264140 Mon Sep 17 00:00:00 2001 From: Lucas de Sousa Rosa Date: Wed, 29 Nov 2023 22:47:18 -0300 Subject: [PATCH] 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`. --- .git-hooks/post-commit | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 .git-hooks/post-commit diff --git a/.git-hooks/post-commit b/.git-hooks/post-commit new file mode 100755 index 0000000..9891333 --- /dev/null +++ b/.git-hooks/post-commit @@ -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" \ No newline at end of file