Skip to content

Instantly share code, notes, and snippets.

@approximatenumber
Created April 13, 2023 08:41
Show Gist options
  • Save approximatenumber/3e8dbddb8c261bb04b5d8e8d6ddba900 to your computer and use it in GitHub Desktop.
Save approximatenumber/3e8dbddb8c261bb04b5d8e8d6ddba900 to your computer and use it in GitHub Desktop.
# dumb function to replace setuptools-scm in python packaging
get_version () {
if hash docker 2>/dev/null; then
git_version=$(docker run --rm -v $(pwd):/git alpine/git describe --tags --long)
else
git_version=$(git describe --tags --long)
fi
tag=$(echo ${git_version} | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
dev=$(echo ${git_version} | grep -oE '\-[0-9]+\-' | tr -d '-')
hash=$(echo ${git_version} | grep -oE '\-[a-z0-9]+$' | tr -d '-')
if [ $dev -eq "0" ]; then
version="$tag"
else
version="$tag.dev$dev+$hash"
fi
echo $version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment