-
Notifications
You must be signed in to change notification settings - Fork 0
/
version
executable file
·73 lines (62 loc) · 1.36 KB
/
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
#!/bin/bash
# Version script for dcos-migration
#
# Change MINOR to x+1 and BRANCH_POINT to commit hash of common ancestor of master and releases/1.x
# after a releases/1.x was cut
MAJOR=0
MINOR=1
BRANCH_POINT=d6ce4319ab6659237faf1fa07850d14274c73ab0
REF=HEAD
declare -a OTHERARGS
help() {
cat <<-EOF
Usage $0 [options]
--help This help
--ref The reference for which version to output Defaults to HEAD
Non-arg params
* commit - output just the formatted commit hash
* version - output just the version, without the hash
* package - output the version with the commit hash, ie 1.9.34-a122edcb4
EOF
}
while ! [ -z "$1" ]; do
arg="$1"
shift
case "$arg" in
--help)
help
exit 0
;;
--ref)
REF="$1"
shift
;;
*)
OTHERARGS+=("$arg")
;;
esac
done
# Infer version
# Number of commits since branch point
COMMIT_NUMBER="$(git rev-list --count --first-parent $BRANCH_POINT..$REF)"
COMMIT_HASH=$(git rev-parse --short $REF)
case ${OTHERARGS[0]} in
commit)
# Echo commit hash
echo "$COMMIT_HASH"
;;
version)
# Echo package version plus hash
echo "$MAJOR.$MINOR.$COMMIT_NUMBER"
;;
"" | package)
# Echo package version plus hash
echo "$MAJOR.$MINOR.$COMMIT_NUMBER-$COMMIT_HASH"
;;
*)
echo "ERROR: ${OTHERARGS[0]} is not a version format"
echo
help
exit 1
;;
esac