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" \
184 --log-file="${working_dir}/hbase-site-log-${CURRENT_HBASE_COMMIT}.txt"; then
185 echo "Successfully built site."
188 echo "Maven commands to build the site failed. check logs for details ${working_dir}/hbase-*-log-*.txt"
193 echo "Staging HBase site"
196 --log-file="${working_dir}/hbase-stage-log-${CURRENT_HBASE_COMMIT}.txt" \
199 if [ $status -ne 0 ] ||
[ ! -d target
/staging
]; then
200 echo "Failure: mvn site:stage"
204 # Get ready to update the hbase-site repo with the new artifacts
205 cd "${working_dir}/hbase-site"
207 #Remove previously-generated files
208 FILES_TO_REMOVE
=("hbase-*"
222 for FILE
in "${FILES_TO_REMOVE[@]}"; do
223 if [ -e "${FILE}" ]; then
224 echo "Removing hbase-site/$FILE"
229 # Copy in the newly-built artifacts
230 # TODO what do we do when the site build wants to remove something? Can't rsync because e.g. release-specific docs.
231 cp -pPR "${component_dir}"/target
/staging
/* .
233 # If the index.html is missing, bail because this is serious
234 if [ ! -f index.html
]; then
235 echo "The index.html is missing. Aborting."
239 echo "Adding all the files we know about"
241 # Create the commit message and commit the changes
242 WEBSITE_COMMIT_MSG
="Published site at $CURRENT_HBASE_COMMIT."
243 echo "WEBSITE_COMMIT_MSG: $WEBSITE_COMMIT_MSG"
244 git commit
-m "${WEBSITE_COMMIT_MSG}" -a
245 # Dump a little report
246 echo "This commit changed these files (excluding Modified files):"
247 git
diff --name-status --diff-filter=ADCRTXUB origin
/asf-site |
tee "${working_dir}/hbase-file-diff-summary-${CURRENT_HBASE_COMMIT}.txt"
248 # Create a patch, which Jenkins can save as an artifact and can be examined for debugging
249 git format-patch
--stdout origin
/asf-site
> "${working_dir}/${CURRENT_HBASE_COMMIT}.patch"
250 if [ ! -s "${working_dir}/${CURRENT_HBASE_COMMIT}.patch" ]; then
251 echo "Something went wrong when creating the patch of our updated site."
254 echo "Change set saved to patch ${working_dir}/${CURRENT_HBASE_COMMIT}.patch"
256 if [ -n "${publish}" ]; then
257 echo "Publishing changes to remote repo..."
258 if git push origin asf-site
; then
259 echo "changes pushed."
261 echo "Failed to push to asf-site. Website not updated."
264 echo "Sending empty commit to work around INFRA-10751."
265 git commit
--allow-empty -m "INFRA-10751 Empty commit"
266 # Push the empty commit
267 if git push origin asf-site
; then
268 echo "empty commit pushed."
270 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)"
273 echo "Pushed the changes to branch asf-site. Refresh http://hbase.apache.org/ to see the changes within a few minutes."
276 # Zip up the patch so Jenkins can save it
278 zip website.
patch.
zip "${CURRENT_HBASE_COMMIT}.patch"