forked from d2iq-archive/marathon
-
Notifications
You must be signed in to change notification settings - Fork 6
/
version
executable file
·92 lines (80 loc) · 1.98 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Version script for Marathon.
#
# 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=1
MINOR=9
BRANCH_POINT=8228cea
PREVIOUS_BRANCH=origin/releases/1.$(($MINOR - 1))
REF=b9c86683866
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
* tag - output Criteo tag
* docker - output the version as used by the Docker tag
* 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
IS_DIRECT_CHILD=$( git log origin/master..$BRANCH_POINT)
COMMIT_NUMBER="$(git rev-list --count --first-parent $BRANCH_POINT..$REF)"
COMMIT_HASH=$(git rev-parse --short $REF)
# Detect if the commit in question belongs to another minor version
if !(git merge-base --is-ancestor $BRANCH_POINT $REF) || (git merge-base --is-ancestor $REF $PREVIOUS_BRANCH) &&
[ $(git rev-parse --verify $REF) != $(git rev-parse --verify $BRANCH_POINT) ]; then
echo "$REF is not a ${MAJOR}.${MINOR}.x version"
exit 1
fi
case ${OTHERARGS[0]} in
commit)
# Echo commit hash
echo "$COMMIT_HASH"
;;
tag)
COMMIT_TAG=$(git describe --tags HEAD | sed -E 's/^v//')
echo "$COMMIT_TAG"
;;
package)
# Echo package version plus hash
echo "$MAJOR.$MINOR.$COMMIT_NUMBER-$COMMIT_HASH"
;;
docker)
# Version for Docker image, e.g. v1.7.42
echo "v$MAJOR.$MINOR.$COMMIT_NUMBER"
;;
"")
# Echo version
# E.g. 1.7.42
echo "$MAJOR.$MINOR.$COMMIT_NUMBER"
;;
*)
echo "ERROR: ${OTHERARGS[0]} is not a version format"
echo
help
exit 1
;;
esac