release-build.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. GPG="gpg --no-tty --batch"
  70. NEXUS_ROOT=https://repository.apache.org/service/local/staging
  71. NEXUS_PROFILE=91529f2f65d84e # Profile for Livy staging uploads
  72. BASE_DIR=$(pwd)
  73. MVN="mvn"
  74. # Use temp staging dir for release process
  75. rm -rf release-staging
  76. mkdir release-staging
  77. cd release-staging
  78. git clone https://git-wip-us.apache.org/repos/asf/incubator-livy.git
  79. cd incubator-livy
  80. git checkout $GIT_REF
  81. git_hash=`git rev-parse --short HEAD`
  82. echo "Checked out Livy git hash $git_hash"
  83. if [ -z "$LIVY_VERSION" ]; then
  84. LIVY_VERSION=$($MVN help:evaluate -Dexpression=project.version \
  85. | grep -v INFO | grep -v WARNING | grep -v Download)
  86. fi
  87. git clean -d -f -x
  88. rm .gitignore
  89. rm -rf .git
  90. cd ..
  91. if [[ "$1" == "package" ]]; then
  92. # Source and binary tarballs
  93. echo "Packaging release tarballs"
  94. cp -r incubator-livy livy-$LIVY_VERSION-src
  95. zip -r livy-$LIVY_VERSION-src.zip livy-$LIVY_VERSION-src
  96. echo "" | $GPG --passphrase-fd 0 --armour --output livy-$LIVY_VERSION-src.zip.asc \
  97. --detach-sig livy-$LIVY_VERSION-src.zip
  98. echo "" | $GPG --passphrase-fd 0 --print-md MD5 livy-$LIVY_VERSION-src.zip > \
  99. livy-$LIVY_VERSION-src.zip.md5
  100. echo "" | $GPG --passphrase-fd 0 --print-md \
  101. SHA512 livy-$LIVY_VERSION-src.zip > livy-$LIVY_VERSION-src.zip.sha512
  102. rm -rf livy-$LIVY_VERSION-src
  103. # Updated for binary build
  104. make_binary_release() {
  105. cp -r incubator-livy livy-$LIVY_VERSION-bin
  106. cd livy-$LIVY_VERSION-bin
  107. $MVN clean install -DskipTests -DskipITs
  108. $MVN clean package -DskipTests -Dgenerate-third-party
  109. echo "Copying and signing regular binary distribution"
  110. cp assembly/target/livy-$LIVY_VERSION-bin.zip .
  111. echo "" | $GPG --passphrase-fd 0 --armour \
  112. --output livy-$LIVY_VERSION-bin.zip.asc \
  113. --detach-sig livy-$LIVY_VERSION-bin.zip
  114. echo "" | $GPG --passphrase-fd 0 --print-md \
  115. MD5 livy-$LIVY_VERSION-bin.zip > \
  116. livy-$LIVY_VERSION-bin.zip.md5
  117. echo "" | $GPG --passphrase-fd 0 --print-md \
  118. SHA512 livy-$LIVY_VERSION-bin.zip > \
  119. livy-$LIVY_VERSION-bin.zip.sha512
  120. cp livy-$LIVY_VERSION-bin.zip* ../
  121. cd ..
  122. }
  123. make_binary_release
  124. svn co $RELEASE_STAGING_LOCATION svn-livy
  125. mkdir -p svn-livy/$LIVY_VERSION-$RELEASE_RC
  126. echo "Copying release tarballs to local svn directory"
  127. cp ./livy-$LIVY_VERSION-src.zip* svn-livy/$LIVY_VERSION-$RELEASE_RC/
  128. cp ./livy-$LIVY_VERSION-bin.zip* svn-livy/$LIVY_VERSION-$RELEASE_RC/
  129. cd svn-livy
  130. svn add $LIVY_VERSION-$RELEASE_RC
  131. svn ci -m "Apache Livy $LIVY_VERSION-$RELEASE_RC"
  132. exit 0
  133. fi
  134. if [[ "$1" == "publish-release" ]]; then
  135. tmp_dir=$(mktemp -d livy-repo-XXXXX)
  136. # the following recreates `readlink -f "$tmp_dir"` since readlink -f is unsupported on MacOS
  137. cd $tmp_dir
  138. tmp_repo=$(pwd)
  139. cd ..
  140. cd incubator-livy
  141. # Publish Livy to Maven release repo
  142. echo "Publishing Livy checkout at '$GIT_REF' ($git_hash)"
  143. echo "Publish version is $LIVY_VERSION"
  144. # Coerce the requested version
  145. $MVN versions:set -DnewVersion=$LIVY_VERSION
  146. # Using Nexus API documented here:
  147. # https://support.sonatype.com/entries/39720203-Uploading-to-a-Staging-Repository-via-REST-API
  148. echo "Creating Nexus staging repository"
  149. repo_request="<promoteRequest><data><description>Apache Livy $LIVY_VERSION (commit $git_hash)</description></data></promoteRequest>"
  150. out=$(curl -X POST -d "$repo_request" -u $ASF_USERNAME:$ASF_PASSWORD \
  151. -H "Content-Type:application/xml" -v \
  152. $NEXUS_ROOT/profiles/$NEXUS_PROFILE/start)
  153. staged_repo_id=$(echo $out | sed -e "s/.*\(orgapachelivy-[0-9]\{4\}\).*/\1/")
  154. echo "Created Nexus staging repository: $staged_repo_id"
  155. $MVN -Dmaven.repo.local=$tmp_repo -DskipTests -DskipITs clean install
  156. pushd $tmp_repo/org/apache/livy
  157. # Remove any extra files generated during install
  158. find . -type f |grep -v \.jar |grep -v \.pom | xargs rm
  159. echo "Creating hash and signature files"
  160. for file in $(find . -type f)
  161. do
  162. echo "" | $GPG --passphrase-fd 0 --output $file.asc \
  163. --detach-sig --armour $file;
  164. if [ $(command -v md5) ]; then
  165. # Available on OS X; -q to keep only hash
  166. md5 -q $file > $file.md5
  167. else
  168. # Available on Linux; cut to keep only hash
  169. md5sum $file | cut -f1 -d' ' > $file.md5
  170. fi
  171. sha1sum $file | cut -f1 -d' ' > $file.sha1
  172. done
  173. nexus_upload=$NEXUS_ROOT/deployByRepositoryId/$staged_repo_id
  174. echo "Uploading files to $nexus_upload"
  175. for file in $(find . -type f)
  176. do
  177. # strip leading ./
  178. file_short=$(echo $file | sed -e "s/\.\///")
  179. dest_url="$nexus_upload/org/apache/livy/$file_short"
  180. echo " Uploading $file_short"
  181. curl -u $ASF_USERNAME:$ASF_PASSWORD --upload-file $file_short $dest_url
  182. done
  183. echo "Closing nexus staging repository"
  184. repo_request="<promoteRequest><data><stagedRepositoryId>$staged_repo_id</stagedRepositoryId><description>Apache Livy$LIVY_VERSION (commit $git_hash)</description></data></promoteRequest>"
  185. out=$(curl -X POST -d "$repo_request" -u $ASF_USERNAME:$ASF_PASSWORD \
  186. -H "Content-Type:application/xml" -v \
  187. $NEXUS_ROOT/profiles/$NEXUS_PROFILE/finish)
  188. echo "Closed Nexus staging repository: $staged_repo_id"
  189. popd
  190. rm -rf $tmp_repo
  191. cd ..
  192. exit 0
  193. fi
  194. cd ..
  195. rm -rf release-staging
  196. echo "ERROR: expects to be called with 'package', 'publish-release'"