release-build.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. function exit_with_usage {
  19. cat << EOF
  20. usage: release-build.sh <package|publish-release>
  21. Creates build deliverables from a Livy commit.
  22. Top level targets are
  23. package: Create binary packages and copy them to home.apache
  24. publish-release: Publish a release to Apache release repo
  25. All other inputs are environment variables
  26. GIT_REF - Release tag or commit to build from
  27. LIVY_VERSION - Release identifier used when Publishing
  28. RELEASE_RC - Release RC identifier used when Publishing
  29. ASF_USERNAME - Username of ASF committer account
  30. ASF_PASSWORD - Password of ASF committer account
  31. GPG_PASSPHRASE - Passphrase for GPG key
  32. EOF
  33. exit 1
  34. }
  35. set -e
  36. if [ $# -eq 0 ]; then
  37. exit_with_usage
  38. fi
  39. if [[ $@ == *"help"* ]]; then
  40. exit_with_usage
  41. fi
  42. # Explicitly set locale in order to make `sort` output consistent across machines.
  43. # See https://stackoverflow.com/questions/28881 for more details.
  44. export LC_ALL=C
  45. # Setup env
  46. # Commit ref to checkout when building
  47. if [ -z "$GIT_REF" ]; then
  48. read -p "Choose git branch/tag [master]: " GIT_REF
  49. GIT_REF=${GIT_REF:-master}
  50. echo $GIT_REF
  51. fi
  52. # Set RELEASE_RC
  53. if [ -z "$RELEASE_RC" ]; then
  54. read -p "Choose RC [rc1]: " RELEASE_RC
  55. RELEASE_RC=${RELEASE_RC:-rc1}
  56. echo $RELEASE_RC
  57. fi
  58. # Get ASF Login
  59. if [ -z "$ASF_USERNAME" ]; then
  60. read -p "ASF username: " ASF_USERNAME
  61. echo $ASF_USERNAME
  62. fi
  63. if [ -z "$ASF_PASSWORD" ]; then
  64. read -s -p "ASF password: " ASF_PASSWORD
  65. echo
  66. fi
  67. # Destination directory on remote server
  68. RELEASE_STAGING_LOCATION="https://dist.apache.org/repos/dist/dev/incubator/livy"
  69. LIVY_REPO=${LIVY_REPO:-https://gitbox.apache.org/repos/asf/incubator-livy.git}
  70. GPG="gpg --no-tty --batch"
  71. NEXUS_ROOT=https://repository.apache.org/service/local/staging
  72. NEXUS_PROFILE=91529f2f65d84e # Profile for Livy staging uploads
  73. BASE_DIR=$(pwd)
  74. MVN="mvn"
  75. # Use temp staging dir for release process
  76. rm -rf release-staging
  77. mkdir release-staging
  78. cd release-staging
  79. git clone $LIVY_REPO incubator-livy
  80. cd incubator-livy
  81. git checkout $GIT_REF
  82. git_hash=`git rev-parse --short HEAD`
  83. echo "Checked out Livy git hash $git_hash"
  84. if [ -z "$LIVY_VERSION" ]; then
  85. LIVY_VERSION=$($MVN help:evaluate -Dexpression=project.version \
  86. | grep -v INFO | grep -v WARNING | grep -v Download)
  87. fi
  88. git clean -d -f -x
  89. rm .gitignore
  90. rm -rf .git
  91. cd ..
  92. ARCHIVE_NAME_PREFIX="apache-livy-$LIVY_VERSION"
  93. SRC_ARCHIVE="$ARCHIVE_NAME_PREFIX-src.zip"
  94. BIN_ARCHIVE="$ARCHIVE_NAME_PREFIX-bin.zip"
  95. if [[ "$1" == "package" ]]; then
  96. # Source and binary tarballs
  97. echo "Packaging release tarballs"
  98. cp -r incubator-livy $ARCHIVE_NAME_PREFIX
  99. zip -r $SRC_ARCHIVE $ARCHIVE_NAME_PREFIX
  100. echo "" | $GPG --passphrase-fd 0 --armour --output $SRC_ARCHIVE.asc --detach-sig $SRC_ARCHIVE
  101. echo "" | $GPG --passphrase-fd 0 --print-md SHA512 $SRC_ARCHIVE > $SRC_ARCHIVE.sha512
  102. rm -rf $ARCHIVE_NAME_PREFIX
  103. # Updated for binary build
  104. make_binary_release() {
  105. cp -r incubator-livy $ARCHIVE_NAME_PREFIX-bin
  106. cd $ARCHIVE_NAME_PREFIX-bin
  107. $MVN clean package -DskipTests -Dgenerate-third-party
  108. echo "Copying and signing regular binary distribution"
  109. cp assembly/target/$BIN_ARCHIVE .
  110. echo "" | $GPG --passphrase-fd 0 --armour --output $BIN_ARCHIVE.asc --detach-sig $BIN_ARCHIVE
  111. echo "" | $GPG --passphrase-fd 0 --print-md SHA512 $BIN_ARCHIVE > $BIN_ARCHIVE.sha512
  112. cp $BIN_ARCHIVE* ../
  113. cd ..
  114. }
  115. make_binary_release
  116. svn co --depth=empty $RELEASE_STAGING_LOCATION svn-livy
  117. mkdir -p svn-livy/$LIVY_VERSION-$RELEASE_RC
  118. echo "Copying release tarballs to local svn directory"
  119. cp ./$SRC_ARCHIVE* svn-livy/$LIVY_VERSION-$RELEASE_RC/
  120. cp ./$BIN_ARCHIVE* svn-livy/$LIVY_VERSION-$RELEASE_RC/
  121. cd svn-livy
  122. svn add $LIVY_VERSION-$RELEASE_RC
  123. svn ci -m "Apache Livy $LIVY_VERSION-$RELEASE_RC"
  124. exit 0
  125. fi
  126. if [[ "$1" == "publish-release" ]]; then
  127. tmp_dir=$(mktemp -d livy-repo-XXXXX)
  128. # the following recreates `readlink -f "$tmp_dir"` since readlink -f is unsupported on MacOS
  129. cd $tmp_dir
  130. tmp_repo=$(pwd)
  131. cd ..
  132. cd incubator-livy
  133. # Publish Livy to Maven release repo
  134. echo "Publishing Livy checkout at '$GIT_REF' ($git_hash)"
  135. echo "Publish version is $LIVY_VERSION"
  136. # Coerce the requested version
  137. $MVN versions:set -DnewVersion=$LIVY_VERSION
  138. # Using Nexus API documented here:
  139. # https://support.sonatype.com/entries/39720203-Uploading-to-a-Staging-Repository-via-REST-API
  140. echo "Creating Nexus staging repository"
  141. repo_request="<promoteRequest><data><description>Apache Livy $LIVY_VERSION (commit $git_hash)</description></data></promoteRequest>"
  142. out=$(curl -X POST -d "$repo_request" -u $ASF_USERNAME:$ASF_PASSWORD \
  143. -H "Content-Type:application/xml" -v \
  144. $NEXUS_ROOT/profiles/$NEXUS_PROFILE/start)
  145. staged_repo_id=$(echo $out | sed -e "s/.*\(orgapachelivy-[0-9]\{4\}\).*/\1/")
  146. echo "Created Nexus staging repository: $staged_repo_id"
  147. $MVN -Dmaven.repo.local=$tmp_repo -DskipTests -DskipITs clean install
  148. pushd $tmp_repo/org/apache/livy
  149. # Remove any extra files generated during install
  150. find . -type f |grep -v \.jar |grep -v \.pom | xargs rm
  151. echo "Creating hash and signature files"
  152. for file in $(find . -type f)
  153. do
  154. echo "" | $GPG --passphrase-fd 0 --output $file.asc \
  155. --detach-sig --armour $file;
  156. if [ $(command -v md5) ]; then
  157. # Available on OS X; -q to keep only hash
  158. md5 -q $file > $file.md5
  159. else
  160. # Available on Linux; cut to keep only hash
  161. md5sum $file | cut -f1 -d' ' > $file.md5
  162. fi
  163. sha1sum $file | cut -f1 -d' ' > $file.sha1
  164. done
  165. nexus_upload=$NEXUS_ROOT/deployByRepositoryId/$staged_repo_id
  166. echo "Uploading files to $nexus_upload"
  167. for file in $(find . -type f)
  168. do
  169. # strip leading ./
  170. file_short=$(echo $file | sed -e "s/\.\///")
  171. dest_url="$nexus_upload/org/apache/livy/$file_short"
  172. echo " Uploading $file_short"
  173. curl -u $ASF_USERNAME:$ASF_PASSWORD --upload-file $file_short $dest_url
  174. done
  175. echo "Closing nexus staging repository"
  176. repo_request="<promoteRequest><data><stagedRepositoryId>$staged_repo_id</stagedRepositoryId><description>Apache Livy$LIVY_VERSION (commit $git_hash)</description></data></promoteRequest>"
  177. out=$(curl -X POST -d "$repo_request" -u $ASF_USERNAME:$ASF_PASSWORD \
  178. -H "Content-Type:application/xml" -v \
  179. $NEXUS_ROOT/profiles/$NEXUS_PROFILE/finish)
  180. echo "Closed Nexus staging repository: $staged_repo_id"
  181. popd
  182. rm -rf $tmp_repo
  183. cd ..
  184. exit 0
  185. fi
  186. cd ..
  187. rm -rf release-staging
  188. echo "ERROR: expects to be called with 'package', 'publish-release'"