-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.sh
executable file
·37 lines (33 loc) · 940 Bytes
/
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
#!/bin/bash
function get_git_current_branch() {
git branch 2>/dev/null | sed -n '/\* /s///p' 2>/dev/null
}
function branch_to_version() {
if test "${1}" = "master"; then
echo "latest"
else
TMP_VERSION=`echo ${1} |awk -F '.' '{print $1;}'`
N=`echo ${TMP_VERSION} |grep '^[0-9][0-9]*$' |wc -l`
if test ${N} -gt 0; then
echo "V${TMP_VERSION}"
else
echo "dev"
fi
fi
}
VERSION=dev
if test "${TRAVIS_PULL_REQUEST}" = "false"; then
# This is travis build (and not a pull request one)
if test "${TRAVIS_TAG}" != ""; then
VERSION=${TRAVIS_TAG}
else
VERSION=`branch_to_version ${TRAVIS_BRANCH}`
fi
else
if test "${TRAVIS_PULL_REQUEST}" = ""; then
# This is not a travis build (VERSION=dev here)
GIT_BRANCH=`get_git_current_branch`
VERSION=`branch_to_version ${GIT_BRANCH}`
fi
fi
echo ${VERSION}