From 6d3e42bf7b013127f6f238d5d0d39d05f0e7460b 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 post-commit hook for automatic tagging - When committing the `pyproject.toml` file, if the version has changed, a tag with `git tag` is created. - It's necessary to configure the `./git-hooks/' directory so that it becomes visible to git hooks: `git config core.hooksPath .git-hooks`. Co-authored-by: Darwish Ahmad Herati <13837531+daherati@users.noreply.github.com> --- .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..043e9ca --- /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, v$version" \ No newline at end of file