From c1eda0fff470b3819f25c8b71986010eb215797c Mon Sep 17 00:00:00 2001 From: Stefano Torresi Date: Fri, 20 Dec 2024 12:07:53 +0100 Subject: [PATCH] update get_version_from_git.sh script --- .ci/get_version_from_git.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.ci/get_version_from_git.sh b/.ci/get_version_from_git.sh index 28b8d17..51ab797 100755 --- a/.ci/get_version_from_git.sh +++ b/.ci/get_version_from_git.sh @@ -1,8 +1,12 @@ #!/bin/sh -TAG=$(git tag | grep -E "[0-9]\.[0-9]\.[0-9]" | sort -rn | head -n1) + +# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string +SEMVER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" + +TAG=$(git tag | grep -P "$SEMVER_REGEX" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -n1) if [ -z "${TAG}" ]; then - echo "Could not find any tag" 1>&2 + echo "Could not find any semver tag" 1>&2 exit 1 else COMMITS_SINCE_TAG=$(git rev-list "${TAG}".. --count)