-
Notifications
You must be signed in to change notification settings - Fork 0
/
srcenv.version
executable file
·97 lines (78 loc) · 2.38 KB
/
srcenv.version
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
#
# srcenv.version - Version tool for srcenv
TAG=$(git describe --tags --abbrev=0)
CURRENT=${TAG#v}
VERSION=$1
shift
if [ "$VERSION" = bump ]; then
IFS=. read -r major minor patch << EOF
$CURRENT
EOF
case $1 in
major) VERSION="$((major+1)).0.0"; shift ;;
minor) VERSION="$major.$((minor+1)).0"; shift ;;
patch|'') VERSION="$major.$minor.$((patch+1))"; shift ;;
*) VERSION="$major.$minor.$((patch+1))"; ;;
esac
fi
CURRENT=${1:-$CURRENT}
ERRORS=
NORMAL=$(tput sgr0 2> /dev/null || printf '\033[0m')
BOLD=$(tput bold 2> /dev/null || printf '\033[1m')
DIM=$(tput dim 2> /dev/null || printf '\033[2m')
RED=$(tput setaf 1 2> /dev/null || printf '\033[31m')
GREEN=$(tput setaf 2 2> /dev/null || printf '\033[32m')
YELLOW=$(tput setaf 3 2> /dev/null || printf '\033[33m')
check() {
if ! grep "$2" "$1" > /dev/null; then
ERRORS="$ERRORS${ERRORS:+\n}$(printf "${RED}✖${NORMAL} %s version does not match version: ${YELLOW}%s${NORMAL}" "$1" "$2")"
return 1
fi
}
usage() {
echo
echo "make ${BOLD}bump [v=major|minor|patch] ${DIM}[from=X.Y.Z]${NORMAL} or "
echo "make ${BOLD}version v=X.Y.Z ${DIM}[from=X.Y.Z]${NORMAL} to change version"
}
if [ -n "$VERSION" ]; then
check srcenv "$VERSION"
check srcenv.tests "$VERSION"
check srcenv.1.md "$VERSION"
if [ -z "$ERRORS" ]; then
printf "${GREEN}✔${NORMAL} srcenv \033[33m%s${NORMAL}\n" "$VERSION"
exit
fi
ERRORS=
fi
check srcenv "$CURRENT"
check srcenv.tests "$CURRENT"
check srcenv.1.md "$CURRENT"
if [ -n "$ERRORS" ]; then
echo "$ERRORS"
usage
exit 1
fi
if [ -z "$VERSION" ]; then
printf "srcenv ${YELLOW}%s${NORMAL}\n" "$CURRENT"
usage
exit
fi
REPLACE="srcenv $(echo "$CURRENT" | sed s/\\./\\\\./g)"
WITH="srcenv $(echo "$VERSION" | sed s/\\./\\\\./g)"
sed -i '' "s/$REPLACE/$WITH/g" srcenv srcenv.tests srcenv.1.md
check srcenv "$VERSION"
check srcenv.tests "$VERSION"
check srcenv.1.md "$VERSION"
if [ -n "$ERRORS" ]; then
echo "$ERRORS"
usage
exit 1
fi
printf "${GREEN}✔${NORMAL} Change srcenv ${YELLOW}%s${NORMAL} to srcenv ${YELLOW}%s${NORMAL}\n" "$CURRENT" "$VERSION"
make build || exit 1
git add srcenv srcenv.tests srcenv.1.md srcenv.1 && \
git commit -m "Bump version to $VERSION" && \
git tag "v$VERSION" && \
git push && \
git push origin "v$VERSION"