Skip to content

Commit

Permalink
fix: add check for legacy semver
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Aug 13, 2024
1 parent 60c0eae commit 31c019b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions script/semver_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ SEMVER_REGEX_STR="\
(\\-(${IDENT})(\\.(${IDENT}))*)?\
(\\+${FIELD}(\\.${FIELD})*)?$"

SEMVER_REGEX_LEGACY="\
[vV]?\
($NAT)\\.($NAT)(\\.($NAT))?\
(\\-(${IDENT})(\\.(${IDENT}))*)?\
(\\+${FIELD}(\\.${FIELD})*)?$"

SEMVER_REGEX="^$SEMVER_REGEX_STR"

function error {
Expand Down Expand Up @@ -43,6 +49,18 @@ function validate_version {
else
echo "$version"
fi
elif [[ "$version" =~ $SEMVER_REGEX_LEGACY ]]; then
# if a second argument is passed, store the result in var named by $2
if [[ "$#" -eq "2" ]]; then
local major=${BASH_REMATCH[1]}
local minor=${BASH_REMATCH[2]}
local patch=0
local prere=${BASH_REMATCH[4]}
local build=${BASH_REMATCH[6]}
eval "$2=(\"${major}\" \"${minor}\" \"${patch}\" \"${prere}\" \"${build}\")"
else
echo "$version"
fi
else
error "version $version does not match the semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'. See help for more information."
fi
Expand Down

0 comments on commit 31c019b

Please sign in to comment.