Skip to content

Commit

Permalink
Add a git hook for automatic tagging
Browse files Browse the repository at this point in the history
- 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`.
  • Loading branch information
firilisinof committed Nov 30, 2023
1 parent 4826afd commit ef7583a
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, $version"

0 comments on commit ef7583a

Please sign in to comment.