-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post-commit hook to tag releases from pyproject.toml
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
die() { | ||
echo >&2 $'\ngit-post-commit :: ----------------------------------------' | ||
echo >&2 "git-post-commit :: ERROR: $@" | ||
echo >&2 $'git-post-commit :: ----------------------------------------\n'; exit 1; } | ||
|
||
ver=$( git show --no-color --diff-filter=M -aU0 pyproject.toml | | ||
gawk '/^\+version\s*=/ { | ||
split(substr($NF,2,length($NF)-2),v,".") | ||
print v[1]+0 "." v[2]+0 "." v[3]+0}' ) | ||
|
||
[[ "$ver" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { | ||
ver=$( gawk '/^version\s*=/ { | ||
split(substr($NF,2,length($NF)-2),v,".") | ||
print v[1]+0 "." v[2]+0 "." v[3]+0}' pyproject.toml ) | ||
[[ "$ver" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || \ | ||
die 'Failed to get version from git-show and pyproject.toml file' | ||
ver_tag=$(git tag --sort=v:refname | tail -1) | ||
[[ -n "$ver" && "$ver" = "$ver_tag" ]] || die 'No new release to tag,'` | ||
`" and last git-tag [ $ver_tag ] does not match pyproject.toml version [ $ver ]" | ||
echo $'\ngit-post-commit: no new tag, last one matches pyproject.toml\n'; exit 0; } | ||
|
||
git tag -f "$ver" HEAD # can be reassigning tag after --amend | ||
echo -e "\ngit-post-commit: tagged new release [ $ver ]\n" |