Skip to content

Commit fd6bfed

Browse files
committed
+ add bump-scripts-version.sh
1 parent 8c08e9d commit fd6bfed

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test-cases/bump-scripts-version.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -eEuo pipefail
3+
4+
################################################################################
5+
# util functions
6+
################################################################################
7+
8+
# NOTE: $'foo' is the escape sequence syntax of bash
9+
readonly ec=$'\033' # escape char
10+
readonly eend=$'\033[0m' # escape end
11+
readonly nl=$'\n' # new line
12+
13+
colorEcho() {
14+
local color=$1
15+
shift
16+
17+
# if stdout is the console, turn on color output.
18+
[ -t 1 ] && echo "${ec}[1;${color}m$*${eend}" || echo "$*"
19+
}
20+
21+
redEcho() {
22+
colorEcho 31 "$@"
23+
}
24+
25+
yellowEcho() {
26+
colorEcho 33 "$@"
27+
}
28+
29+
blueEcho() {
30+
colorEcho 36 "$@"
31+
}
32+
33+
logAndRun() {
34+
local simple_mode=false
35+
[ "$1" = "-s" ] && {
36+
simple_mode=true
37+
shift
38+
}
39+
40+
if $simple_mode; then
41+
echo "Run under work directory $PWD : $*"
42+
"$@"
43+
else
44+
blueEcho "Run under work directory $PWD :$nl$*"
45+
time "$@"
46+
fi
47+
}
48+
49+
die() {
50+
redEcho "Error: $*" 1>&2
51+
exit 1
52+
}
53+
54+
################################################################################
55+
# biz logic
56+
################################################################################
57+
58+
[ $# -ne 1 ] && die "need only 1 argument for version!$nl${nl}usage:$nl $0 2.x.y"
59+
readonly bump_version="$1"
60+
61+
# adjust current dir to project dir
62+
cd "$(dirname "$(readlink -f "$0")")/.."
63+
64+
script_files=$(
65+
find bin legacy-bin -type f
66+
)
67+
68+
# shellcheck disable=SC2086
69+
logAndRun sed -ri \
70+
's/^(.*PROG_VERSION\s*=\s*)'\''(.*)'\''(.*)$/\1'\'"$bump_version"\''\3/' \
71+
$script_files

0 commit comments

Comments
 (0)