create_release_files.sh 9.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/env bash

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Quick-and-dirty automation of making maven and binary releases. Not robust at all.
# Publishes releases to Maven and packages/copies binary release artifacts.
# Expects to be run in a totally empty directory.
#

#
#  NOTE: The code in this file is based on code from the Apache Spark
#  project, licensed under the Apache License v 2.0
#
#  https://github.com/apache/spark/blob/master/dev/create-release/create-release.sh
#
31

32 33 34 35 36 37 38 39
##
#
#   Flink release script
#   ===================
#
#   Can be called like this:
#
#    sonatype_user=APACHEID sonatype_pw=APACHEIDPASSWORD \
40 41 42
#     NEW_VERSION=1.2.0 \
#     RELEASE_CANDIDATE="rc1" RELEASE_BRANCH=release-1.2.0
#     OLD_VERSION=1.1-SNAPSHOT \
43 44 45 46 47 48 49 50 51 52 53
#     USER_NAME=APACHEID \
#     GPG_PASSPHRASE=XXX GPG_KEY=KEYID \
#     GIT_AUTHOR="`git config --get user.name` <`git config --get user.email`>" \
#     ./create_release_files.sh
#
##


# fail immediately
set -o errexit
set -o nounset
54 55
# print command before executing
set -o xtrace
56

57 58 59 60 61 62
CURR_DIR=`pwd`
if [[ `basename $CURR_DIR` != "tools" ]] ; then
  echo "You have to call the script from the tools/ dir"
  exit 1
fi

63 64 65
##
## Variables with defaults (if not overwritten by environment)
##
66 67
GPG_PASSPHRASE=${GPG_PASSPHRASE:-XXX}
GPG_KEY=${GPG_KEY:-XXX}
68
GIT_AUTHOR=${GIT_AUTHOR:-"Your name <you@apache.org>"}
69 70 71
OLD_VERSION=${OLD_VERSION:-1.2-SNAPSHOT}
RELEASE_VERSION=${NEW_VERSION:-1.3-SNAPSHOT}
RELEASE_CANDIDATE=${RELEASE_CANDIDATE:-none}
M
Maximilian Michels 已提交
72
RELEASE_BRANCH=${RELEASE_BRANCH:-master}
73
USER_NAME=${USER_NAME:-yourapacheidhere}
74
MVN=${MVN:-mvn}
U
uce 已提交
75
GPG=${GPG:-gpg}
76
sonatype_user=${sonatype_user:-yourapacheidhere}
77
sonatype_pw=${sonatype_pw:-XXX}
78 79 80 81 82
# whether only build the dist local and don't release to apache
IS_LOCAL_DIST=${IS_LOCAL_DIST:-false}
GIT_REPO=${GIT_REPO:-git-wip-us.apache.org/repos/asf/flink.git}
SCALA_VERSION=none
HADOOP_VERSION=none
83

84
if [ "$(uname)" == "Darwin" ]; then
M
Maximilian Michels 已提交
85 86
    SHASUM="shasum -a 512"
    MD5SUM="md5 -r"
87
else
M
Maximilian Michels 已提交
88 89
    SHASUM="sha512sum"
    MD5SUM="md5sum"
90 91
fi

92 93
usage() {
  set +x
94
  echo "./create_release_files.sh --scala-version 2.11 --hadoop-version 2.7.3"
95 96 97 98 99 100 101 102 103 104
  echo ""
  echo "usage:"
  echo "[--scala-version <version>] [--hadoop-version <version>]"
  echo ""
  echo "example 1: build apache release"
  echo "  sonatype_user=APACHEID sonatype_pw=APACHEIDPASSWORD \ "
  echo "  NEW_VERSION=1.2.0 RELEASE_CANDIDATE="rc1" RELEASE_BRANCH=release-1.2.0 OLD_VERSION=1.1-SNAPSHOT \ "
  echo "  USER_NAME=APACHEID GPG_PASSPHRASE=XXX GPG_KEY=KEYID \ "
  echo "  GIT_AUTHOR=\"`git config --get user.name` <`git config --get user.email`>\" \ "
  echo "  GIT_REPO=github.com/apache/flink.git \ "
105
  echo "  ./create_release_files.sh --scala-version 2.11 --hadoop-version 2.7.3"
106 107 108 109
  echo ""
  echo "example 2: build local release"
  echo "  NEW_VERSION=1.2.0 RELEASE_BRANCH=master OLD_VERSION=1.2-SNAPSHOT \ "
  echo "  GPG_PASSPHRASE=XXX GPG_KEY=XXX IS_LOCAL_DIST=true \ "
110
  echo "  ./create_release_files.sh --scala-version 2.11 --hadoop-version 2.7.3"
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

  exit 1
}

# Parse arguments
while (( "$#" )); do
  case $1 in
    --scala-version)
      SCALA_VERSION="$2"
      shift
      ;;
    --hadoop-version)
      HADOOP_VERSION="$2"
      shift
      ;;
    --help)
      usage
      ;;
    *)
      break
      ;;
  esac
  shift
done

###########################
137

138 139
prepare() {
  # prepare
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  target_branch=release-$RELEASE_VERSION
  if [ "$RELEASE_CANDIDATE" != "none" ]; then
    target_branch=$target_branch-$RELEASE_CANDIDATE
  fi

  if [ ! -d ./flink ]; then
    git clone http://$GIT_REPO flink
  else
    # if flink git repo exist, delete target branch, delete builded distribution
    rm -rf flink-*.tgz
    cd flink
    # try-catch
    {
      git pull --all
      git checkout master
      git branch -D $target_branch -f
    } || {
      echo "branch $target_branch not found"
    }
    cd ..
  fi

162
  cd flink
163 164 165 166

  git checkout -b $target_branch origin/$RELEASE_BRANCH
  rm -rf .gitignore .gitattributes .travis.yml deploysettings.xml CHANGELOG .github

167
  cd ..
168 169
}

170
# create source package
171
make_source_release() {
172

173 174
  cd flink

175
  #change version in all pom files
176
  find . -name 'pom.xml' -type f -exec perl -pi -e 's#<version>'$OLD_VERSION'</version>#<version>'$NEW_VERSION'</version>#' {} \;
177

178
  #change version in quickstart archetypes
179
  find . -name 'pom.xml' -type f -exec perl -pi -e 's#<flink.version>'$OLD_VERSION'</flink.version>#<flink.version>'$NEW_VERSION'</flink.version>#' {} \;
180

181 182
  #change version of documentation
  cd docs
183 184
  perl -pi -e "s#^version: .*#version: ${NEW_VERSION}#" _config.yml
  perl -pi -e "s#^version_short: .*#version_short: ${NEW_VERSION}#" _config.yml
185 186
  cd ..

187
  # local dist have no need to commit to remote
188
  if [ "$IS_LOCAL_DIST" == "false" ]; then
189 190 191 192 193
    git commit --author="$GIT_AUTHOR" -am "Commit for release $RELEASE_VERSION"
    git remote add asf_push https://$USER_NAME@$GIT_REPO
    RELEASE_HASH=`git rev-parse HEAD`
    echo "Echo created release hash $RELEASE_HASH"
  fi
194

195
  cd ..
196

197
  echo "Creating source package"
198
  rsync -a --exclude ".git" flink/ flink-$RELEASE_VERSION
199 200 201 202 203 204 205
  tar czf flink-${RELEASE_VERSION}-src.tgz flink-$RELEASE_VERSION
  echo $GPG_PASSPHRASE | $GPG --batch --default-key $GPG_KEY --passphrase-fd 0 --armour --output flink-$RELEASE_VERSION-src.tgz.asc \
    --detach-sig flink-$RELEASE_VERSION-src.tgz
  $MD5SUM flink-$RELEASE_VERSION-src.tgz > flink-$RELEASE_VERSION-src.tgz.md5
  $SHASUM flink-$RELEASE_VERSION-src.tgz > flink-$RELEASE_VERSION-src.tgz.sha
  rm -rf flink-$RELEASE_VERSION
}
206

207
# build maven package, create Flink distribution, generate signature
208 209 210
make_binary_release() {
  NAME=$1
  FLAGS=$2
M
Maximilian Michels 已提交
211 212 213 214 215
  SCALA_VERSION=$3

  echo "Creating binary release name: $NAME, flags: $FLAGS, SCALA_VERSION: ${SCALA_VERSION}"
  dir_name="flink-$RELEASE_VERSION-bin-$NAME-scala_${SCALA_VERSION}"
  rsync -a --exclude "flink/.git" flink/ "${dir_name}"
216

217
  # make distribution
M
Maximilian Michels 已提交
218 219
  cd "${dir_name}"

220
  # enable release profile here (to check for the maven version)
221
  $MVN clean package $FLAGS -DskipTests -Prelease,scala-${SCALA_VERSION} -Dgpg.skip
222

223 224
  cd flink-dist/target/flink-*-bin/
  tar czf "${dir_name}.tgz" flink-*
225

226 227 228 229
  cp flink-*.tgz ../../../../
  cd ../../../../

  # Sign md5 and sha the tgz
U
uce 已提交
230
  echo $GPG_PASSPHRASE | $GPG --batch --default-key $GPG_KEY \
231
    --passphrase-fd 0 --armour \
M
Maximilian Michels 已提交
232 233 234 235
    --output "${dir_name}.tgz.asc" \
    --detach-sig "${dir_name}.tgz"
  $MD5SUM "${dir_name}.tgz" > "${dir_name}.tgz.md5"
  $SHASUM "${dir_name}.tgz" > "${dir_name}.tgz.sha"
236 237
}

238 239 240 241 242
deploy_to_maven() {
  echo "Deploying to repository.apache.org"

  cd flink
  cp ../../deploysettings.xml .
243 244
  
  echo "Deploying Scala 2.11 version"
245
  $MVN clean deploy -Prelease,docs-and-source,scala-2.11 --settings deploysettings.xml -DskipTests -Dgpg.executable=$GPG -Dgpg.keyname=$GPG_KEY -Dgpg.passphrase=$GPG_PASSPHRASE -DretryFailedDeploymentCount=10
246 247 248 249
  
  # It is important to first deploy scala 2.11 and then scala 2.10 so that the quickstarts (which are independent of the scala version)
  # are depending on scala 2.10.
  echo "Deploying Scala 2.10 version"
250
  $MVN clean deploy -Prelease,docs-and-source,scala-2.10 --settings deploysettings.xml -DskipTests -Dgpg.executable=$GPG -Dgpg.keyname=$GPG_KEY -Dgpg.passphrase=$GPG_PASSPHRASE -DretryFailedDeploymentCount=10
251 252 253 254 255
}

copy_data() {
  # Copy data
  echo "Copying release tarballs"
256 257 258 259 260
  folder=flink-$RELEASE_VERSION
  # candidate is not none, append it
  if [ "$RELEASE_CANDIDATE" != "none" ]; then
    folder=$folder-$RELEASE_CANDIDATE
  fi
261 262 263 264 265
  sftp $USER_NAME@home.apache.org <<EOF
mkdir public_html/$folder
put flink-*.tgz* public_html/$folder
bye
EOF
266 267 268 269 270 271 272
  echo "copy done"
}

prepare

make_source_release

273 274
# build dist by input parameter of "--scala-vervion xxx --hadoop-version xxx"
if [ "$SCALA_VERSION" == "none" ] && [ "$HADOOP_VERSION" == "none" ]; then
275 276 277 278 279 280 281 282 283
  make_binary_release "hadoop2" "" "2.10"
  make_binary_release "hadoop26" "-Dhadoop.version=2.6.5" "2.10"
  make_binary_release "hadoop27" "-Dhadoop.version=2.7.3" "2.10"
  make_binary_release "hadoop28" "-Dhadoop.version=2.8.0" "2.10"

  make_binary_release "hadoop2" "" "2.11"
  make_binary_release "hadoop26" "-Dhadoop.version=2.6.5" "2.11"
  make_binary_release "hadoop27" "-Dhadoop.version=2.7.3" "2.11"
  make_binary_release "hadoop28" "-Dhadoop.version=2.8.0" "2.11"
284 285 286 287 288 289
elif [ "$SCALA_VERSION" == none ] && [ "$HADOOP_VERSION" != "none" ]
then
  make_binary_release "hadoop2" "-Dhadoop.version=$HADOOP_VERSION" "2.10"
  make_binary_release "hadoop2" "-Dhadoop.version=$HADOOP_VERSION" "2.11"
elif [ "$SCALA_VERSION" != none ] && [ "$HADOOP_VERSION" == "none" ]
then
290 291 292 293
  make_binary_release "hadoop2" "" "$SCALA_VERSION"
  make_binary_release "hadoop26" "-Dhadoop.version=2.6.5" "$SCALA_VERSION"
  make_binary_release "hadoop27" "-Dhadoop.version=2.7.3" "$SCALA_VERSION"
  make_binary_release "hadoop28" "-Dhadoop.version=2.8.0" "$SCALA_VERSION"
294 295 296
else
  make_binary_release "hadoop2x" "-Dhadoop.version=$HADOOP_VERSION" "$SCALA_VERSION"
fi
297

298
if [ "$IS_LOCAL_DIST" == "false" ] ; then
299 300 301
    copy_data
    deploy_to_maven
fi
302

303
echo "Done. Don't forget to commit the release version"