Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/env bash
0002 
0003 #
0004 # Licensed to the Apache Software Foundation (ASF) under one or more
0005 # contributor license agreements.  See the NOTICE file distributed with
0006 # this work for additional information regarding copyright ownership.
0007 # The ASF licenses this file to You under the Apache License, Version 2.0
0008 # (the "License"); you may not use this file except in compliance with
0009 # the License.  You may obtain a copy of the License at
0010 #
0011 #    http://www.apache.org/licenses/LICENSE-2.0
0012 #
0013 # Unless required by applicable law or agreed to in writing, software
0014 # distributed under the License is distributed on an "AS IS" BASIS,
0015 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 # See the License for the specific language governing permissions and
0017 # limitations under the License.
0018 #
0019 
0020 DRY_RUN=${DRY_RUN:-0}
0021 GPG="gpg --no-tty --batch"
0022 ASF_REPO="https://gitbox.apache.org/repos/asf/spark.git"
0023 ASF_REPO_WEBUI="https://gitbox.apache.org/repos/asf?p=spark.git"
0024 ASF_GITHUB_REPO="https://github.com/apache/spark"
0025 
0026 function error {
0027   echo "$*"
0028   exit 1
0029 }
0030 
0031 function read_config {
0032   local PROMPT="$1"
0033   local DEFAULT="$2"
0034   local REPLY=
0035 
0036   read -p "$PROMPT [$DEFAULT]: " REPLY
0037   local RETVAL="${REPLY:-$DEFAULT}"
0038   if [ -z "$RETVAL" ]; then
0039     error "$PROMPT is must be provided."
0040   fi
0041   echo "$RETVAL"
0042 }
0043 
0044 function parse_version {
0045   grep -e '<version>.*</version>' | \
0046     head -n 2 | tail -n 1 | cut -d'>' -f2 | cut -d '<' -f1
0047 }
0048 
0049 function run_silent {
0050   local BANNER="$1"
0051   local LOG_FILE="$2"
0052   shift 2
0053 
0054   echo "========================"
0055   echo "= $BANNER"
0056   echo "Command: $@"
0057   echo "Log file: $LOG_FILE"
0058 
0059   "$@" 1>"$LOG_FILE" 2>&1
0060 
0061   local EC=$?
0062   if [ $EC != 0 ]; then
0063     echo "Command FAILED. Check full logs for details."
0064     tail "$LOG_FILE"
0065     exit $EC
0066   fi
0067 }
0068 
0069 function fcreate_secure {
0070   local FPATH="$1"
0071   rm -f "$FPATH"
0072   touch "$FPATH"
0073   chmod 600 "$FPATH"
0074 }
0075 
0076 function check_for_tag {
0077   curl -s --head --fail "$ASF_GITHUB_REPO/releases/tag/$1" > /dev/null
0078 }
0079 
0080 function get_release_info {
0081   if [ -z "$GIT_BRANCH" ]; then
0082     # If no branch is specified, found out the latest branch from the repo.
0083     GIT_BRANCH=$(git ls-remote --heads "$ASF_REPO" |
0084       grep -v refs/heads/master |
0085       awk '{print $2}' |
0086       sort -r |
0087       head -n 1 |
0088       cut -d/ -f3)
0089   fi
0090 
0091   export GIT_BRANCH=$(read_config "Branch" "$GIT_BRANCH")
0092 
0093   # Find the current version for the branch.
0094   local VERSION=$(curl -s "$ASF_REPO_WEBUI;a=blob_plain;f=pom.xml;hb=refs/heads/$GIT_BRANCH" |
0095     parse_version)
0096   echo "Current branch version is $VERSION."
0097 
0098   if [[ ! $VERSION =~ .*-SNAPSHOT ]]; then
0099     error "Not a SNAPSHOT version: $VERSION"
0100   fi
0101 
0102   NEXT_VERSION="$VERSION"
0103   RELEASE_VERSION="${VERSION/-SNAPSHOT/}"
0104   SHORT_VERSION=$(echo "$VERSION" | cut -d . -f 1-2)
0105   local REV=$(echo "$RELEASE_VERSION" | cut -d . -f 3)
0106 
0107   # Find out what rc is being prepared.
0108   # - If the current version is "x.y.0", then this is rc1 of the "x.y.0" release.
0109   # - If not, need to check whether the previous version has been already released or not.
0110   #   - If it has, then we're building rc1 of the current version.
0111   #   - If it has not, we're building the next RC of the previous version.
0112   local RC_COUNT
0113   if [ $REV != 0 ]; then
0114     local PREV_REL_REV=$((REV - 1))
0115     local PREV_REL_TAG="v${SHORT_VERSION}.${PREV_REL_REV}"
0116     if check_for_tag "$PREV_REL_TAG"; then
0117       RC_COUNT=1
0118       REV=$((REV + 1))
0119       NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
0120     else
0121       RELEASE_VERSION="${SHORT_VERSION}.${PREV_REL_REV}"
0122       RC_COUNT=$(git ls-remote --tags "$ASF_REPO" "v${RELEASE_VERSION}-rc*" | wc -l)
0123       RC_COUNT=$((RC_COUNT + 1))
0124     fi
0125   else
0126     REV=$((REV + 1))
0127     NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
0128     RC_COUNT=1
0129   fi
0130 
0131   export NEXT_VERSION
0132   export RELEASE_VERSION=$(read_config "Release" "$RELEASE_VERSION")
0133 
0134   RC_COUNT=$(read_config "RC #" "$RC_COUNT")
0135 
0136   # Check if the RC already exists, and if re-creating the RC, skip tag creation.
0137   RELEASE_TAG="v${RELEASE_VERSION}-rc${RC_COUNT}"
0138   SKIP_TAG=0
0139   if check_for_tag "$RELEASE_TAG"; then
0140     read -p "$RELEASE_TAG already exists. Continue anyway [y/n]? " ANSWER
0141     if [ "$ANSWER" != "y" ]; then
0142       error "Exiting."
0143     fi
0144     SKIP_TAG=1
0145   fi
0146 
0147 
0148   export RELEASE_TAG
0149 
0150   GIT_REF="$RELEASE_TAG"
0151   if is_dry_run; then
0152     echo "This is a dry run. Please confirm the ref that will be built for testing."
0153     if [[ $SKIP_TAG = 0 ]]; then
0154       GIT_REF="$GIT_BRANCH"
0155     fi
0156     GIT_REF=$(read_config "Ref" "$GIT_REF")
0157   fi
0158   export GIT_REF
0159   export SPARK_PACKAGE_VERSION="$RELEASE_TAG"
0160 
0161   # Gather some user information.
0162   if [ -z "$ASF_USERNAME" ]; then
0163     export ASF_USERNAME=$(read_config "ASF user" "$LOGNAME")
0164   fi
0165 
0166   if [ -z "$GIT_NAME" ]; then
0167     GIT_NAME=$(git config user.name || echo "")
0168     export GIT_NAME=$(read_config "Full name" "$GIT_NAME")
0169   fi
0170 
0171   export GIT_EMAIL="$ASF_USERNAME@apache.org"
0172   export GPG_KEY=$(read_config "GPG key" "$GIT_EMAIL")
0173 
0174   cat <<EOF
0175 ================
0176 Release details:
0177 BRANCH:     $GIT_BRANCH
0178 VERSION:    $RELEASE_VERSION
0179 TAG:        $RELEASE_TAG
0180 NEXT:       $NEXT_VERSION
0181 
0182 ASF USER:   $ASF_USERNAME
0183 GPG KEY:    $GPG_KEY
0184 FULL NAME:  $GIT_NAME
0185 E-MAIL:     $GIT_EMAIL
0186 ================
0187 EOF
0188 
0189   read -p "Is this info correct [y/n]? " ANSWER
0190   if [ "$ANSWER" != "y" ]; then
0191     echo "Exiting."
0192     exit 1
0193   fi
0194 
0195   if ! is_dry_run; then
0196     if [ -z "$ASF_PASSWORD" ]; then
0197       stty -echo && printf "ASF password: " && read ASF_PASSWORD && printf '\n' && stty echo
0198     fi
0199   else
0200     ASF_PASSWORD="***INVALID***"
0201   fi
0202 
0203   if [ -z "$GPG_PASSPHRASE" ]; then
0204     stty -echo && printf "GPG passphrase: " && read GPG_PASSPHRASE && printf '\n' && stty echo
0205   fi
0206 
0207   export ASF_PASSWORD
0208   export GPG_PASSPHRASE
0209 }
0210 
0211 function is_dry_run {
0212   [[ $DRY_RUN = 1 ]]
0213 }
0214 
0215 # Initializes JAVA_VERSION to the version of the JVM in use.
0216 function init_java {
0217   if [ -z "$JAVA_HOME" ]; then
0218     error "JAVA_HOME is not set."
0219   fi
0220   JAVA_VERSION=$("${JAVA_HOME}"/bin/javac -version 2>&1 | cut -d " " -f 2)
0221   export JAVA_VERSION
0222 }
0223 
0224 # Initializes MVN_EXTRA_OPTS and SBT_OPTS depending on the JAVA_VERSION in use. Requires init_java.
0225 function init_maven_sbt {
0226   MVN="build/mvn -B"
0227   MVN_EXTRA_OPTS=
0228   SBT_OPTS=
0229   if [[ $JAVA_VERSION < "1.8." ]]; then
0230     # Needed for maven central when using Java 7.
0231     SBT_OPTS="-Dhttps.protocols=TLSv1.1,TLSv1.2"
0232     MVN_EXTRA_OPTS="-Dhttps.protocols=TLSv1.1,TLSv1.2"
0233     MVN="$MVN $MVN_EXTRA_OPTS"
0234   fi
0235   export MVN MVN_EXTRA_OPTS SBT_OPTS
0236 }