-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·95 lines (83 loc) · 1.69 KB
/
version.sh
File metadata and controls
executable file
·95 lines (83 loc) · 1.69 KB
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
#! /bin/bash
# Run this script inside of the directory it resides in.
cd $(dirname $(realpath $0))
# Set much more strict behavior for failed commands and unexpanded variables.
set -eu
# Allow's the script to refer to itself.
me=$(basename $0)
function log() {
echo "[$me] $@"
}
function increment-version() {
local version=$(cat VERSION.txt)
local old_version="$version"
local a=( ${version//./ } )
local major=${a[0]}
local minor=${a[1]}
local patch=${a[2]}
while true; do
read -p "Increment version [(m)ajor/m(i)nor/(p)atch]? " part
if [[ "$part" == "" ]]; then
part="M"
fi
case "$part" in
[Mm])
major=$((major + 1))
minor=0
patch=0
break
;;
[Ii])
minor=$((minor + 1))
patch=0
break
;;
[Pp])
patch=$((patch + 1))
break
;;
*)
echo "Enter M to increment major version, I for minor version, or P for patch"
;;
esac
done
version="$major.$minor.$patch"
local commit_msg="Version: $old_version -> $version"
echo "$commit_msg"
echo "$version" > VERSION.txt
git add VERSION.txt
git commit -m "$commit_msg"
git tag "v$version"
}
function publish-version() {
local version="v$(cat VERSION.txt)"
git push origin "$version"
GOPROXY="proxy.golang.org" go list -m "github.com/toddgaunt/persistent@$version"
}
function usage() {
echo "Usage: $me [version|increment|publish|help]"
}
function main() {
local subcommand=${1-version}
local args=${@:2}
case $subcommand in
version)
echo "$(cat VERSION.txt)"
;;
increment)
increment-version $args
;;
publish)
publish-version $args
;;
-h|--help|help)
usage
;;
*)
log "$subcommand is not a valid subcommand."
usage
exit 1
;;
esac
}
main $@