Skip to content

Commit c1eda0f

Browse files
author
Stefano Torresi
committed
update get_version_from_git.sh script
1 parent e3b5eac commit c1eda0f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

.ci/get_version_from_git.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/sh
2-
TAG=$(git tag | grep -E "[0-9]\.[0-9]\.[0-9]" | sort -rn | head -n1)
2+
3+
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
4+
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-]+)*))?$"
5+
6+
TAG=$(git tag | grep -P "$SEMVER_REGEX" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -n1)
37

48
if [ -z "${TAG}" ]; then
5-
echo "Could not find any tag" 1>&2
9+
echo "Could not find any semver tag" 1>&2
610
exit 1
711
else
812
COMMITS_SINCE_TAG=$(git rev-list "${TAG}".. --count)

0 commit comments

Comments
 (0)