Skip to content

Commit

Permalink
refactor(scripts): update semver tool with support of legacy semantics (
Browse files Browse the repository at this point in the history
#171)

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Jan 9, 2024
1 parent dc4e5ae commit 3952c34
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions script/semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -o errexit -o nounset -o pipefail

SEMVER_REGEX="^[v|V]?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"

SEMVER_REGEX_LEGACY="^[v|V]?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.0|[1-9][0-9]*)?(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"

PROG=semver
PROG_VERSION=2.1.0

Expand Down Expand Up @@ -68,6 +70,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 Expand Up @@ -200,6 +214,9 @@ function command-get {
local build="${parts[4]:1}"

case "$part" in
"major-minor")
echo "$major.$minor"
;;
major | minor | patch | release | prerel | build)
echo "${!part}" ;;
*)
Expand Down

0 comments on commit 3952c34

Please sign in to comment.