Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions scripts/versioning/bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ prerel=${2:-none}
targetpath="../../scripts/versioning"

if [[ $bump == "prerel" ]]; then
bump="patch"
prerel="prerel"
fi

Expand All @@ -23,7 +22,7 @@ elif [[ $(git status --porcelain -b | grep -e "ahead" -e "behind") != "" ]]; the
exit 1
fi

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

previous_version="$("$dir"/$targetpath/version.sh -s)"

Expand Down Expand Up @@ -51,8 +50,7 @@ echo "Bumping version from v${previous_version} to ${new_version}"

read -p "Are you sure? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [[ $REPLY =~ ^[Yy]$ ]]; then
git tag -m "release ${new_version}" -a "$new_version" && git push "${ORIGIN}" tag "$new_version"
echo "done"
fi
140 changes: 88 additions & 52 deletions scripts/versioning/semver
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,56 @@ function compare-version {
for i in 0 1 2; do
local diff=$((${V[$i]} - ${V_[$i]}))
if [[ $diff -lt 0 ]]; then
echo -1; return 0
echo -1
return 0
elif [[ $diff -gt 0 ]]; then
echo 1; return 0
echo 1
return 0
fi
done

# PREREL should compare with the ASCII order.
if [[ -z "${V[3]}" ]] && [[ -n "${V_[3]}" ]]; then
echo 1; return 0;
echo 1
return 0
elif [[ -n "${V[3]}" ]] && [[ -z "${V_[3]}" ]]; then
echo -1; return 0;
echo -1
return 0
elif [[ -n "${V[3]}" ]] && [[ -n "${V_[3]}" ]]; then
if [[ "${V[3]}" > "${V_[3]}" ]]; then
echo 1; return 0;
echo 1
return 0
elif [[ "${V[3]}" < "${V_[3]}" ]]; then
echo -1; return 0;
echo -1
return 0
fi
fi

echo 0
}

function command-bump {
local new; local version; local sub_version; local command;
local new
local version
local sub_version
local command

case $# in
2) case $1 in
major|minor|patch|release) command=$1; version=$2;;
*) usage-help;;
esac ;;
3) case $1 in
prerel|build) command=$1; sub_version=$2 version=$3 ;;
*) usage-help;;
esac ;;
*) usage-help;;
2) case $1 in
major | minor | patch | release)
command=$1
version=$2
;;
*) usage-help ;;
esac ;;
3) case $1 in
prerel | build)
command=$1
sub_version=$2 version=$3
;;
*) usage-help ;;
esac ;;
*) usage-help ;;
esac

validate-version "$version" parts
Expand All @@ -133,68 +148,89 @@ function command-bump {
local build="${parts[4]}"

case "$command" in
major) new="$((major + 1)).0.0";;
minor) new="${major}.$((minor + 1)).0";;
patch) new="${major}.${minor}.$((patch + 1))";;
release) new="${major}.${minor}.${patch}";;
prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}");;
build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}");;
*) usage-help ;;
major) new="$((major + 1)).0.0" ;;
minor) new="${major}.$((minor + 1)).0" ;;
patch) new="${major}.${minor}.$((patch + 1))" ;;
release) new="${major}.${minor}.${patch}" ;;
prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}") ;;
build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}") ;;
*) usage-help ;;
esac

echo "$new"
exit 0
}

function command-compare {
local v; local v_;
local v
local v_

case $# in
2) v=$(validate-version "$1"); v_=$(validate-version "$2") ;;
*) usage-help ;;
2)
v=$(validate-version "$1")
v_=$(validate-version "$2")
;;
*) usage-help ;;
esac

compare-version "$v" "$v_"
exit 0
}


# shellcheck disable=SC2034
function command-get {
local part version
local part version

if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then
usage-help
exit 0
fi
if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then
usage-help
exit 0
fi

part="$1"
version="$2"
part="$1"
version="$2"

validate-version "$version" parts
local major="${parts[0]}"
local minor="${parts[1]}"
local patch="${parts[2]}"
local prerel="${parts[3]:1}"
local build="${parts[4]:1}"
validate-version "$version" parts
local major="${parts[0]}"
local minor="${parts[1]}"
local patch="${parts[2]}"
local prerel="${parts[3]:1}"
local build="${parts[4]:1}"

case "$part" in
major|minor|patch|release|prerel|build) echo "${!part}" ;;
*) usage-help ;;
esac
case "$part" in
major | minor | patch | release | prerel | build) echo "${!part}" ;;
*) usage-help ;;
esac

exit 0
exit 0
}

case $# in
0) echo "Unknown command: $*"; usage-help;;
0)
echo "Unknown command: $*"
usage-help
;;
esac

case $1 in
--help|-h) echo -e "$USAGE"; exit 0;;
--version|-v) usage-version ;;
bump) shift; command-bump "$@";;
get) shift; command-get "$@";;
compare) shift; command-compare "$@";;
*) echo "Unknown arguments: $*"; usage-help;;
--help | -h)
echo -e "$USAGE"
exit 0
;;
--version | -v) usage-version ;;
bump)
shift
command-bump "$@"
;;
get)
shift
command-get "$@"
;;
compare)
shift
command-compare "$@"
;;
*)
echo "Unknown arguments: $*"
usage-help
;;
esac
2 changes: 1 addition & 1 deletion scripts/versioning/version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ORIGIN=${ORIGIN:-origin}

version=$(git fetch --tags "${ORIGIN}" &>/dev/null | git -c "versionsort.prereleasesuffix=-pre" tag -l --sort=version:refname | tail -n1 | cut -c 2-)
version=$(git fetch --tags "${ORIGIN}" &>/dev/null | git -c "versionsort.prereleasesuffix=-pre" tag -l --sort=version:refname | tail -n1 | cut -c 2-)

echo "$version"
Loading