forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.sh
executable file
·74 lines (62 loc) · 1.42 KB
/
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
67
68
69
70
71
72
73
74
#!/bin/sh
# Update the package version number
GIT=`which git`
show_help() {
cat <<EOF
$0 [-h] [-r]
This script is used to bump NAV version numbers.
Options:
-h Print this help.
-t Sets and git-tags a production version from the
latest changelog entry
EOF
}
in_git_repo() {
test -e .git && test -x "$GIT"
}
do_describe() {
${GIT} describe --tags
}
get_version() {
do_describe
}
get_version_from_changelog() {
head -n15 CHANGELOG.md | awk '/^## \[[0-9]/ { print $2 }' | tr -d '[]'
}
git_tag_exists() {
local tag="$1"
${GIT} rev-parse "$tag" >/dev/null 2>/dev/null
}
tag_from_changelog() {
local version=$(get_version_from_changelog)
if [ -z "$version" ]; then
>&2 echo "Could not get version from changelog"
exit 1
elif ! in_git_repo; then
>&2 echo "I would have tagged ${version}, but I'm not in a Git repository"
exit 2
elif git_tag_exists "${version}"; then
>&2 echo "Cannot tag ${version}, tag already exists:\n"
${GIT} tag -v "$version"
exit 3
else
echo "Tagging version ${version}"
fi
${GIT} tag --annotate --sign -m "Tag release ${version}" "$version"
${GIT} tag -v "$version"
}
# Parse options
OPTIND=1
while getopts "hdt" opt; do
case "$opt" in
h)
show_help
exit 0
;;
t) tag_from_changelog
exit 0
;;
esac
done
# If we got this far, just print the current version
get_version