forked from openzipkin/zipkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·122 lines (106 loc) · 3.48 KB
/
publish.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -ex
function heartbeat() {
# Some operations (for example Bintray GPG signing) run for a long time without output,
# causing Travis to time out the build. This is an ugly hack to work around that.
hard_timeout=3600 # 1 hour
heartbeat_interval=10
counter=0
while [[ $counter -lt $hard_timeout ]] && kill -0 "$$" 2>/dev/null; do
echo "(heartbeat $counter)"
counter=$(($counter + $heartbeat_interval))
sleep $heartbeat_interval
done &
}
function increment_version() {
# TODO this would be cleaner in release.versionPatterns
local v=$1
if [ -z $2 ]; then
local rgx='^((?:[0-9]+\.)*)([0-9]+)($)'
else
local rgx='^((?:[0-9]+\.){'$(($2-1))'})([0-9]+)(\.|$)'
for (( p=`grep -o "\."<<<".$v"|wc -l`; p<$2; p++)); do
v+=.0; done; fi
val=`echo -e "$v" | perl -pe 's/^.*'$rgx'.*$/$2/'`
echo "$v" | perl -pe s/$rgx.*$'/${1}'`printf %0${#val}s $(($val+1))`/
}
function build_started_by_tag(){
if [ "${TRAVIS_TAG}" == "" ]; then
echo "[Publishing] This build was not started by a tag, publishing"
return 1
else
echo "[Publishing] This build was started by the tag ${TRAVIS_TAG}, creating release commits"
return 0
fi
}
function is_pull_request(){
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
echo "[Not Publishing] This is a Pull Request"
return 0
else
echo "[Publishing] This is not a Pull Request"
return 1
fi
}
function is_travis_branch_master(){
if [ "${TRAVIS_BRANCH}" = master ]; then
echo "[Publishing] Travis branch is master"
return 0
else
echo "[Not Publishing] Travis branch is not master"
return 1
fi
}
function check_travis_branch_equals_travis_tag(){
#Weird comparison comparing branch to tag because when you 'git push --tags'
#the branch somehow becomes the tag value
#github issue: https://github.com/travis-ci/travis-ci/issues/1675
if [ "${TRAVIS_BRANCH}" != "${TRAVIS_TAG}" ]; then
echo "Travis branch does not equal Travis tag, which it should, bailing out."
echo " github issue: https://github.com/travis-ci/travis-ci/issues/1675"
exit 1
else
echo "[Publishing] Branch (${TRAVIS_BRANCH}) same as Tag (${TRAVIS_TAG})"
fi
}
function publish(){
echo "[Publishing] Publishing..."
PUBLISHING=true ./gradlew --info --stacktrace zipkinUpload
echo "[Publishing] Done"
}
function do_gradle_release(){
# TODO this would be cleaner in release.versionPatterns
major_minor_revision=$(echo "$TRAVIS_TAG" | cut -f1 -d-)
qualifier=$(echo "$TRAVIS_TAG" | cut -f2 -d- -s)
# do not increment if the version is tentative ex. 1.0.0-rc1
if [[ -n "$qualifier" ]]; then
new_version=${major_minor_revision}
else
new_version=$(increment_version "${major_minor_revision}")
fi
new_version="${new_version}-SNAPSHOT"
echo "[Publishing] Creating release commits"
echo "[Publishing] Release version: ${TRAVIS_TAG}"
echo "[Publishing] Post-release version: ${new_version}"
git checkout -B master
PUBLISHING=true ./gradlew --info --stacktrace release -Prelease.useAutomaticVersion=true -PreleaseVersion=${TRAVIS_TAG} -PnewVersion=${new_version}
echo "[Publishing] Done"
}
function run_tests(){
echo "[Not Publishing] Running tests then exiting."
./gradlew check
}
#----------------------
# MAIN
#----------------------
action=run_tests
if ! is_pull_request; then
if build_started_by_tag; then
check_travis_branch_equals_travis_tag
action=do_gradle_release
elif is_travis_branch_master; then
action=publish
fi
fi
heartbeat
$action