Skip to content

Commit

Permalink
Add a post-commit hook for automatic tagging
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
firilisinof and herati committed Dec 1, 2023
1 parent f041de9 commit 6d3e42b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .git-hooks/post-commit
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 6d3e42b

Please sign in to comment.