forked from openzipkin/zipkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·182 lines (159 loc) · 6.24 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
#
# Copyright 2015-2017 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#
set -euo pipefail
set -x
build_started_by_tag() {
if [ "${TRAVIS_TAG}" == "" ]; then
echo "[Publishing] This build was not started by a tag, publishing snapshot"
return 1
else
echo "[Publishing] This build was started by the tag ${TRAVIS_TAG}, publishing release"
return 0
fi
}
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
}
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
}
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
}
check_release_tag() {
tag="${TRAVIS_TAG}"
if [[ "$tag" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then
echo "Build started by version tag $tag. During the release process tags like this"
echo "are created by the 'release' Maven plugin. Nothing to do here."
exit 0
elif [[ ! "$tag" =~ ^release-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then
echo "You must specify a tag of the format 'release-0.0.0' to release this project."
echo "The provided tag ${tag} doesn't match that. Aborting."
exit 1
fi
}
print_project_version() {
./mvnw help:evaluate -N -Dexpression=project.version|grep -v '\['
}
is_release_commit() {
project_version="$(print_project_version)"
if [[ "$project_version" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then
echo "Build started by release commit $project_version. Will synchronize to maven central."
return 0
else
return 1
fi
}
release_version() {
echo "${TRAVIS_TAG}" | sed 's/^release-//'
}
safe_checkout_master() {
# We need to be on a branch for release:perform to be able to create commits, and we want that branch to be master.
# But we also want to make sure that we build and release exactly the tagged version, so we verify that the remote
# master is where our tag is.
git checkout -B master
git fetch origin master:origin/master
commit_local_master="$(git show --pretty='format:%H' master)"
commit_remote_master="$(git show --pretty='format:%H' origin/master)"
if [ "$commit_local_master" != "$commit_remote_master" ]; then
echo "Master on remote 'origin' has commits since the version under release, aborting"
exit 1
fi
}
javadoc_to_gh_pages() {
version="$(print_project_version)"
rm -rf javadoc-builddir
builddir="javadoc-builddir/$version"
# Collect javadoc for all modules
for jar in $(find . -name "*${version}-javadoc.jar"); do
module="$(echo "$jar" | sed "s~.*/\(.*\)-${version}-javadoc.jar~\1~")"
this_builddir="$builddir/$module"
if [ -d "$this_builddir" ]; then
# Skip modules we've already processed.
# We may find multiple instances of the same javadoc jar because of, for instance,
# integration tests copying jars around.
continue
fi
mkdir -p "$this_builddir"
unzip "$jar" -d "$this_builddir"
# Build a simple module-level index
echo "<li><a href=\"${module}/index.html\">${module}</a></li>" >> "${builddir}/index.html"
done
# Update gh-pages
git fetch origin gh-pages:gh-pages
git checkout gh-pages
rm -rf "$version"
mv "javadoc-builddir/$version" ./
rm -rf "javadoc-builddir"
# Update simple version-level index
if ! grep "$version" index.html 2>/dev/null; then
echo "<li><a href=\"${version}/index.html\">${version}</a></li>" >> index.html
fi
# Ensure links are ordered by versions, latest on top
sort -rV index.html > index.html.sorted
mv index.html.sorted index.html
git add "$version"
git add index.html
git commit -m "Automatically updated javadocs for $version"
git push origin gh-pages
}
#----------------------
# MAIN
#----------------------
if ! is_pull_request && build_started_by_tag; then
check_travis_branch_equals_travis_tag
check_release_tag
fi
# skip license on travis due to #1512
MYSQL_USER=root ./mvnw install -nsu -Dlicense.skip=true
# If we are on a pull request, our only job is to run tests, which happened above via ./mvnw install
if is_pull_request; then
true
# If we are on master, we will deploy the latest snapshot or release version
# - If a release commit fails to deploy for a transient reason, delete the broken version from bintray and click rebuild
elif is_travis_branch_master; then
./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -pl -:benchmarks -DskipTests deploy
# If the deployment succeeded, sync it to Maven Central. Note: this needs to be done once per project, not module, hence -N
if is_release_commit; then
./mvnw --batch-mode -s ./.settings.xml -nsu -N io.zipkin.centralsync-maven-plugin:centralsync-maven-plugin:sync
javadoc_to_gh_pages
fi
# If we are on a release tag, the following will update any version references and push a version tag for deployment.
elif build_started_by_tag; then
safe_checkout_master
# skip license on travis due to #1512
./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -DreleaseVersion="$(release_version)" -Darguments="-DskipTests -Dlicense.skip=true" release:prepare
fi