-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincrement_version.sh
executable file
·66 lines (54 loc) · 1.55 KB
/
increment_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# One stop shop for incrementing the lifx-cli version.
declare -l ANSWER
NEW_VERSION=$1
CURRENT_VERSION=$(git describe --tags --abbrev=0)
FILES=('pyproject.toml'
'src/lifx/lifx.py'
'tests/lifx_cli_test.py')
function is_command {
local FAILURE
for program in $@; do
hash ${program} > /dev/null 2>&1
if [ $? != 0 ]; then
echo "Command not found: ${program}" >&2
FAILURE='true'
fi
done
if [ ! -z ${FAILURE} ]; then
exit 127
fi
}
function err {
local EXIT=$1
shift 1
echo "[$(date +'%Y-%m-%d %H:%M:%S')]: $@" >&2
exit ${EXIT}
}
function increment_version {
for file in ${FILES[@]}; do
gawk -i inplace \
-F'"' \
-v VER=${NEW_VERSION} \
'BEGIN{IGNORECASE=1} /^version/ {sub($2,VER)}; {print $0}' \
${file}
git add ${file}
done
git commit -m "Bumping version: ${NEW_VERSION}"
git push origin main
git tag v${NEW_VERSION}
git push origin --tags
}
# Input validation.
if [ -z ${NEW_VERSION} ]; then
echo "Current Tagged Version: ${CURRENT_VERSION}"
err 5 "Must supply a new version number to continue."
fi
if ! echo ${NEW_VERSION} | grep -q "^[0-9]*\.[0-9]*\.[0-9]*$"; then
err 6 "New version number is in the wrong format. Must be: <MAJOR>.<MINOR>.<PATCH>"
fi
is_command gawk
read -p "Are you certain that you want to increment to version: ${CURRENT_VERSION} -> ${NEW_VERSION}? y/N " ANSWER
if [ "${ANSWER}" == "y" ]; then
increment_version
fi