4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
12 # * http://www.apache.org/licenses/LICENSE-2.0
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
21 # This script is meant to run as part of a Jenkins job such as
22 # https://builds.apache.org/job/hbase_generate_website/
24 # It needs to be built on a Jenkins server with the label git-websites
26 # Allows specifying options for working directory, maven repo, and publishing to git
27 # run with --help for usage.
29 # If there is a build error, the Jenkins job is configured to send an email
31 declare CURRENT_HBASE_COMMIT
34 declare WEBSITE_COMMIT_MSG
35 declare -a FILES_TO_REMOVE
39 echo "Usage: ${0} [options] /path/to/hbase/checkout"
41 echo " --working-dir /path/to/use Path for writing logs and a local checkout of hbase-site repo."
42 echo " if given must exist."
43 echo " defaults to making a directory via mktemp."
44 echo " --local-repo /path/for/maven/.m2 Path for putting local maven repo."
45 echo " if given must exist."
46 echo " defaults to making a clean directory in --working-dir."
47 echo " --publish if given, will attempt to push results back to the hbase-site repo."
48 echo " --help show this usage message."
51 # if no args specified, show usage
64 --working-dir) shift; working_dir
=$1; shift;;
65 --local-repo) shift; local_repo
=$1; shift;;
66 --publish) shift; publish
="true";;
69 *) break;; # terminate while loop
73 # should still have where component checkout is.
77 component_dir
="$(cd "$
(dirname "$1")"; pwd)/$(basename "$1")"
79 if [ -z "${working_dir}" ]; then
80 echo "[DEBUG] defaulting to creating a directory via mktemp"
81 if ! working_dir
="$(mktemp -d -t hbase-generate-website)" ; then
82 echo "Failed to create temporary working directory. Please specify via --working-dir"
87 working_dir
="$(cd "$
(dirname "${working_dir}")"; pwd)/$(basename "${working_dir}")"
88 if [ ! -d "${working_dir}" ]; then
89 echo "passed working directory '${working_dir}' must already exist."
94 echo "You'll find logs and temp files in ${working_dir}"
96 if [ -z "${local_repo}" ]; then
97 echo "[DEBUG] defaulting to creating a local repo within '${working_dir}'"
98 local_repo
="${working_dir}/.m2/repo"
99 # Nuke the local maven repo each time, to start with a known environment
100 rm -Rf "${local_repo}"
101 mkdir
-p "${local_repo}"
104 local_repo
="$(cd "$
(dirname "${local_repo}")"; pwd)/$(basename "${local_repo}")"
105 if [ ! -d "${local_repo}" ]; then
106 echo "passed directory for storing the maven repo '${local_repo}' must already exist."
111 # Set up the environment
112 if [ -z "${JAVA_HOME}" ]; then
113 JAVA_HOME
="${JDK_1_8_LATEST__HOME}"
115 export PATH
="${JAVA_HOME}/bin:${PATH}"
117 if [ -z "${MAVEN_HOME}" ]; then
118 MAVEN_HOME
="${MAVEN_3_3_3_HOME}"
120 export PATH
="${MAVEN_HOME}/bin:${PATH}"
122 export MAVEN_OPTS
="${MAVEN_OPTS} -Dmaven.repo.local=${local_repo}"
124 # Verify the Maven version
126 # Verify the git version
131 # Clean any leftover files in case we are reusing the workspace
132 rm -Rf -- *.
patch *.
patch.
zip target
*.txt hbase-site
134 # Save and print the SHA we are building
135 CURRENT_HBASE_COMMIT
="$(cd "${component_dir}" && git show-ref --hash --dereference --verify refs/remotes/origin/HEAD)"
137 if [ -z "${CURRENT_HBASE_COMMIT}" ]; then
138 echo "Got back a blank answer for the current HEAD on the remote hbase repository. failing."
141 echo "Current HBase commit: $CURRENT_HBASE_COMMIT"
143 # Clone the hbase-site repo manually so it doesn't trigger spurious
144 # commits in Jenkins.
145 git clone
--depth 1 --branch asf-site https
://gitbox.apache.org
/repos
/asf
/hbase-site.git
147 # Figure out if the commit of the hbase repo has already been built and bail if so.
149 PUSHED
=$
(cd hbase-site
&& git rev-list
--grep "${CURRENT_HBASE_COMMIT}" --fixed-strings --count HEAD
)
150 echo "[DEBUG] hash was found in $PUSHED commits for hbase-site repository."
152 if [ "${PUSHED}" -ne 0 ]; then
153 echo "$CURRENT_HBASE_COMMIT is already mentioned in the hbase-site commit log. Not building."
156 echo "$CURRENT_HBASE_COMMIT is not yet mentioned in the hbase-site commit log. Assuming we don't have it yet."
159 # Go to the hbase directory so we can build the site
160 cd "${component_dir}"
162 # This will only be set for builds that are triggered by SCM change, not manual builds
163 if [ -n "$CHANGE_ID" ]; then
164 echo -n " ($CHANGE_ID - $CHANGE_TITLE)"
167 # Build and install HBase, then build the site
168 echo "Building HBase"
169 # TODO we have to do a local install first because for whatever reason, the maven-javadoc-plugin's
170 # forked compile phase requires that test-scoped dependencies be available, which
171 # doesn't work since we will not have done a test-compile phase (MJAVADOC-490). the first place this
172 # breaks for me is hbase-server trying to find hbase-http:test and hbase-zookeeper:test.
173 # But! some sunshine: because we're doing a full install before running site, we can skip all the
174 # compiling in the forked executions. We have to do it awkwardly because MJAVADOC-444.
177 -Psite-install-step \
178 --log-file="${working_dir}/hbase-install-log-${CURRENT_HBASE_COMMIT}.txt" \
183 --log-file="${working_dir}/hbase-site-log-${CURRENT_HBASE_COMMIT}.txt"; then
184 echo "Successfully built site."
187 echo "Maven commands to build the site failed. check logs for details ${working_dir}/hbase-*-log-*.txt"
192 echo "Staging HBase site"
195 --log-file="${working_dir}/hbase-stage-log-${CURRENT_HBASE_COMMIT}.txt" \
198 if [ $status -ne 0 ] ||
[ ! -d target
/staging
]; then
199 echo "Failure: mvn site:stage"
203 # Get ready to update the hbase-site repo with the new artifacts
204 cd "${working_dir}/hbase-site"
206 #Remove previously-generated files
207 FILES_TO_REMOVE
=("hbase-*"
221 for FILE
in "${FILES_TO_REMOVE[@]}"; do
222 if [ -e "${FILE}" ]; then
223 echo "Removing hbase-site/$FILE"
228 # Copy in the newly-built artifacts
229 # TODO what do we do when the site build wants to remove something? Can't rsync because e.g. release-specific docs.
230 cp -pPR "${component_dir}"/target
/staging
/* .
232 # If the index.html is missing, bail because this is serious
233 if [ ! -f index.html
]; then
234 echo "The index.html is missing. Aborting."
238 echo "Adding all the files we know about"
240 # Create the commit message and commit the changes
241 WEBSITE_COMMIT_MSG
="Published site at $CURRENT_HBASE_COMMIT."
242 echo "WEBSITE_COMMIT_MSG: $WEBSITE_COMMIT_MSG"
243 git commit
-m "${WEBSITE_COMMIT_MSG}" -a
244 # Dump a little report
245 echo "This commit changed these files (excluding Modified files):"
246 git
diff --name-status --diff-filter=ADCRTXUB origin
/asf-site |
tee "${working_dir}/hbase-file-diff-summary-${CURRENT_HBASE_COMMIT}.txt"
247 # Create a patch, which Jenkins can save as an artifact and can be examined for debugging
248 git format-patch
--stdout origin
/asf-site
> "${working_dir}/${CURRENT_HBASE_COMMIT}.patch"
249 if [ ! -s "${working_dir}/${CURRENT_HBASE_COMMIT}.patch" ]; then
250 echo "Something went wrong when creating the patch of our updated site."
253 echo "Change set saved to patch ${working_dir}/${CURRENT_HBASE_COMMIT}.patch"
255 if [ -n "${publish}" ]; then
256 echo "Publishing changes to remote repo..."
257 if git push origin asf-site
; then
258 echo "changes pushed."
260 echo "Failed to push to asf-site. Website not updated."
263 echo "Sending empty commit to work around INFRA-10751."
264 git commit
--allow-empty -m "INFRA-10751 Empty commit"
265 # Push the empty commit
266 if git push origin asf-site
; then
267 echo "empty commit pushed."
269 echo "Failed to push the empty commit to asf-site. Website may not update. Manually push an empty commit to fix this. (See INFRA-10751)"
272 echo "Pushed the changes to branch asf-site. Refresh http://hbase.apache.org/ to see the changes within a few minutes."
275 # Zip up the patch so Jenkins can save it
277 zip website.
patch.
zip "${CURRENT_HBASE_COMMIT}.patch"