diff --git a/scripts/versioning/bump_version.sh b/scripts/versioning/bump_version.sh index c963c044..1c69715b 100755 --- a/scripts/versioning/bump_version.sh +++ b/scripts/versioning/bump_version.sh @@ -11,7 +11,6 @@ prerel=${2:-none} targetpath="../../scripts/versioning" if [[ $bump == "prerel" ]]; then - bump="patch" prerel="prerel" fi @@ -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)" @@ -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 diff --git a/scripts/versioning/semver b/scripts/versioning/semver index 674229e0..353ff39e 100755 --- a/scripts/versioning/semver +++ b/scripts/versioning/semver @@ -87,22 +87,28 @@ 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 @@ -110,18 +116,27 @@ function compare-version { } 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 @@ -133,13 +148,13 @@ 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" @@ -147,54 +162,75 @@ function command-bump { } 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 diff --git a/scripts/versioning/version.sh b/scripts/versioning/version.sh index c76d9539..5732d4d5 100755 --- a/scripts/versioning/version.sh +++ b/scripts/versioning/version.sh @@ -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"