Skip to content

Commit 5896d87

Browse files
authored
Revert "allow non-patch prereleases and shellformat versioning script (#320)" (#321)
This reverts commit b247f7d.
1 parent b247f7d commit 5896d87

3 files changed

Lines changed: 57 additions & 91 deletions

File tree

scripts/versioning/bump_version.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ prerel=${2:-none}
1111
targetpath="../../scripts/versioning"
1212

1313
if [[ $bump == "prerel" ]]; then
14+
bump="patch"
1415
prerel="prerel"
1516
fi
1617

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

25-
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26+
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2627

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

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

5152
read -p "Are you sure? " -n 1 -r
5253
echo
53-
if [[ $REPLY =~ ^[Yy]$ ]]; then
54+
if [[ $REPLY =~ ^[Yy]$ ]]
55+
then
5456
git tag -m "release ${new_version}" -a "$new_version" && git push "${ORIGIN}" tag "$new_version"
5557
echo "done"
5658
fi

scripts/versioning/semver

Lines changed: 52 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -87,56 +87,41 @@ function compare-version {
8787
for i in 0 1 2; do
8888
local diff=$((${V[$i]} - ${V_[$i]}))
8989
if [[ $diff -lt 0 ]]; then
90-
echo -1
91-
return 0
90+
echo -1; return 0
9291
elif [[ $diff -gt 0 ]]; then
93-
echo 1
94-
return 0
92+
echo 1; return 0
9593
fi
9694
done
9795

9896
# PREREL should compare with the ASCII order.
9997
if [[ -z "${V[3]}" ]] && [[ -n "${V_[3]}" ]]; then
100-
echo 1
101-
return 0
98+
echo 1; return 0;
10299
elif [[ -n "${V[3]}" ]] && [[ -z "${V_[3]}" ]]; then
103-
echo -1
104-
return 0
100+
echo -1; return 0;
105101
elif [[ -n "${V[3]}" ]] && [[ -n "${V_[3]}" ]]; then
106102
if [[ "${V[3]}" > "${V_[3]}" ]]; then
107-
echo 1
108-
return 0
103+
echo 1; return 0;
109104
elif [[ "${V[3]}" < "${V_[3]}" ]]; then
110-
echo -1
111-
return 0
105+
echo -1; return 0;
112106
fi
113107
fi
114108

115109
echo 0
116110
}
117111

118112
function command-bump {
119-
local new
120-
local version
121-
local sub_version
122-
local command
113+
local new; local version; local sub_version; local command;
123114

124115
case $# in
125-
2) case $1 in
126-
major | minor | patch | release)
127-
command=$1
128-
version=$2
129-
;;
130-
*) usage-help ;;
131-
esac ;;
132-
3) case $1 in
133-
prerel | build)
134-
command=$1
135-
sub_version=$2 version=$3
136-
;;
137-
*) usage-help ;;
138-
esac ;;
139-
*) usage-help ;;
116+
2) case $1 in
117+
major|minor|patch|release) command=$1; version=$2;;
118+
*) usage-help;;
119+
esac ;;
120+
3) case $1 in
121+
prerel|build) command=$1; sub_version=$2 version=$3 ;;
122+
*) usage-help;;
123+
esac ;;
124+
*) usage-help;;
140125
esac
141126

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

150135
case "$command" in
151-
major) new="$((major + 1)).0.0" ;;
152-
minor) new="${major}.$((minor + 1)).0" ;;
153-
patch) new="${major}.${minor}.$((patch + 1))" ;;
154-
release) new="${major}.${minor}.${patch}" ;;
155-
prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}") ;;
156-
build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}") ;;
157-
*) usage-help ;;
136+
major) new="$((major + 1)).0.0";;
137+
minor) new="${major}.$((minor + 1)).0";;
138+
patch) new="${major}.${minor}.$((patch + 1))";;
139+
release) new="${major}.${minor}.${patch}";;
140+
prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}");;
141+
build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}");;
142+
*) usage-help ;;
158143
esac
159144

160145
echo "$new"
161146
exit 0
162147
}
163148

164149
function command-compare {
165-
local v
166-
local v_
150+
local v; local v_;
167151

168152
case $# in
169-
2)
170-
v=$(validate-version "$1")
171-
v_=$(validate-version "$2")
172-
;;
173-
*) usage-help ;;
153+
2) v=$(validate-version "$1"); v_=$(validate-version "$2") ;;
154+
*) usage-help ;;
174155
esac
175156

176157
compare-version "$v" "$v_"
177158
exit 0
178159
}
179160

161+
180162
# shellcheck disable=SC2034
181163
function command-get {
182-
local part version
164+
local part version
183165

184-
if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then
185-
usage-help
186-
exit 0
187-
fi
166+
if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then
167+
usage-help
168+
exit 0
169+
fi
188170

189-
part="$1"
190-
version="$2"
171+
part="$1"
172+
version="$2"
191173

192-
validate-version "$version" parts
193-
local major="${parts[0]}"
194-
local minor="${parts[1]}"
195-
local patch="${parts[2]}"
196-
local prerel="${parts[3]:1}"
197-
local build="${parts[4]:1}"
174+
validate-version "$version" parts
175+
local major="${parts[0]}"
176+
local minor="${parts[1]}"
177+
local patch="${parts[2]}"
178+
local prerel="${parts[3]:1}"
179+
local build="${parts[4]:1}"
198180

199-
case "$part" in
200-
major | minor | patch | release | prerel | build) echo "${!part}" ;;
201-
*) usage-help ;;
202-
esac
181+
case "$part" in
182+
major|minor|patch|release|prerel|build) echo "${!part}" ;;
183+
*) usage-help ;;
184+
esac
203185

204-
exit 0
186+
exit 0
205187
}
206188

207189
case $# in
208-
0)
209-
echo "Unknown command: $*"
210-
usage-help
211-
;;
190+
0) echo "Unknown command: $*"; usage-help;;
212191
esac
213192

214193
case $1 in
215-
--help | -h)
216-
echo -e "$USAGE"
217-
exit 0
218-
;;
219-
--version | -v) usage-version ;;
220-
bump)
221-
shift
222-
command-bump "$@"
223-
;;
224-
get)
225-
shift
226-
command-get "$@"
227-
;;
228-
compare)
229-
shift
230-
command-compare "$@"
231-
;;
232-
*)
233-
echo "Unknown arguments: $*"
234-
usage-help
235-
;;
194+
--help|-h) echo -e "$USAGE"; exit 0;;
195+
--version|-v) usage-version ;;
196+
bump) shift; command-bump "$@";;
197+
get) shift; command-get "$@";;
198+
compare) shift; command-compare "$@";;
199+
*) echo "Unknown arguments: $*"; usage-help;;
236200
esac

scripts/versioning/version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ORIGIN=${ORIGIN:-origin}
22

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

55
echo "$version"

0 commit comments

Comments
 (0)