spark-instrumented-optimizer/dev/create-release/release-util.sh

236 lines
6.3 KiB
Bash
Raw Normal View History

#!/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.
#
DRY_RUN=${DRY_RUN:-0}
GPG="gpg --no-tty --batch"
[SPARK-31687][INFRA] Use GitHub instead of GitBox in release script ### What changes were proposed in this pull request? This PR aims to use GitHub urls instead of GitHub in the release scripts. ### Why are the changes needed? Currently, Spark Packaing jobs are broken due to GitBox issue. ``` fatal: unable to access 'https://gitbox.apache.org/repos/asf/spark.git/': Failed to connect to gitbox.apache.org port 443: Connection timed out ``` - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-master-maven-snapshots/2906/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-3.0-maven-snapshots/105/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-2.4-maven-snapshots/439/console ### Does this PR introduce _any_ user-facing change? No. (This is a dev-only script.) ### How was this patch tested? Manual. ``` $ cat ./test.sh . dev/create-release/release-util.sh get_release_info git clone "$ASF_REPO" $ sh test.sh Branch [branch-3.0]: Current branch version is 3.0.1-SNAPSHOT. Release [3.0.0]: RC # [2]: Full name [Dongjoon Hyun]: GPG key [dongjoonapache.org]: ================ Release details: BRANCH: branch-3.0 VERSION: 3.0.0 TAG: v3.0.0-rc2 NEXT: 3.0.1-SNAPSHOT ASF USER: dongjoon GPG KEY: dongjoonapache.org FULL NAME: Dongjoon Hyun E-MAIL: dongjoonapache.org ================ Is this info correct [y/n]? y ASF password: GPG passphrase: Cloning into 'spark'... remote: Enumerating objects: 223, done. remote: Counting objects: 100% (223/223), done. remote: Compressing objects: 100% (117/117), done. remote: Total 708324 (delta 70), reused 138 (delta 32), pack-reused 708101 Receiving objects: 100% (708324/708324), 322.08 MiB | 2.94 MiB/s, done. Resolving deltas: 100% (289268/289268), done. Updating files: 100% (16287/16287), done. $ sh test.sh ... ``` Closes #28513 from dongjoon-hyun/SPARK-31687. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
2020-05-12 16:07:00 -04:00
ASF_REPO="https://github.com/apache/spark"
ASF_REPO_WEBUI="https://raw.githubusercontent.com/apache/spark"
function error {
echo "$*"
exit 1
}
function read_config {
local PROMPT="$1"
local DEFAULT="$2"
local REPLY=
read -p "$PROMPT [$DEFAULT]: " REPLY
local RETVAL="${REPLY:-$DEFAULT}"
if [ -z "$RETVAL" ]; then
error "$PROMPT is must be provided."
fi
echo "$RETVAL"
}
function parse_version {
grep -e '<version>.*</version>' | \
head -n 2 | tail -n 1 | cut -d'>' -f2 | cut -d '<' -f1
}
function run_silent {
local BANNER="$1"
local LOG_FILE="$2"
shift 2
echo "========================"
echo "= $BANNER"
echo "Command: $@"
echo "Log file: $LOG_FILE"
"$@" 1>"$LOG_FILE" 2>&1
local EC=$?
if [ $EC != 0 ]; then
echo "Command FAILED. Check full logs for details."
tail "$LOG_FILE"
exit $EC
fi
}
function fcreate_secure {
local FPATH="$1"
rm -f "$FPATH"
touch "$FPATH"
chmod 600 "$FPATH"
}
function check_for_tag {
[SPARK-31687][INFRA] Use GitHub instead of GitBox in release script ### What changes were proposed in this pull request? This PR aims to use GitHub urls instead of GitHub in the release scripts. ### Why are the changes needed? Currently, Spark Packaing jobs are broken due to GitBox issue. ``` fatal: unable to access 'https://gitbox.apache.org/repos/asf/spark.git/': Failed to connect to gitbox.apache.org port 443: Connection timed out ``` - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-master-maven-snapshots/2906/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-3.0-maven-snapshots/105/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-2.4-maven-snapshots/439/console ### Does this PR introduce _any_ user-facing change? No. (This is a dev-only script.) ### How was this patch tested? Manual. ``` $ cat ./test.sh . dev/create-release/release-util.sh get_release_info git clone "$ASF_REPO" $ sh test.sh Branch [branch-3.0]: Current branch version is 3.0.1-SNAPSHOT. Release [3.0.0]: RC # [2]: Full name [Dongjoon Hyun]: GPG key [dongjoonapache.org]: ================ Release details: BRANCH: branch-3.0 VERSION: 3.0.0 TAG: v3.0.0-rc2 NEXT: 3.0.1-SNAPSHOT ASF USER: dongjoon GPG KEY: dongjoonapache.org FULL NAME: Dongjoon Hyun E-MAIL: dongjoonapache.org ================ Is this info correct [y/n]? y ASF password: GPG passphrase: Cloning into 'spark'... remote: Enumerating objects: 223, done. remote: Counting objects: 100% (223/223), done. remote: Compressing objects: 100% (117/117), done. remote: Total 708324 (delta 70), reused 138 (delta 32), pack-reused 708101 Receiving objects: 100% (708324/708324), 322.08 MiB | 2.94 MiB/s, done. Resolving deltas: 100% (289268/289268), done. Updating files: 100% (16287/16287), done. $ sh test.sh ... ``` Closes #28513 from dongjoon-hyun/SPARK-31687. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
2020-05-12 16:07:00 -04:00
curl -s --head --fail "$ASF_REPO/releases/tag/$1" > /dev/null
}
function get_release_info {
if [ -z "$GIT_BRANCH" ]; then
# If no branch is specified, found out the latest branch from the repo.
GIT_BRANCH=$(git ls-remote --heads "$ASF_REPO" |
grep -v refs/heads/master |
awk '{print $2}' |
sort -r |
head -n 1 |
cut -d/ -f3)
fi
export GIT_BRANCH=$(read_config "Branch" "$GIT_BRANCH")
# Find the current version for the branch.
[SPARK-31687][INFRA] Use GitHub instead of GitBox in release script ### What changes were proposed in this pull request? This PR aims to use GitHub urls instead of GitHub in the release scripts. ### Why are the changes needed? Currently, Spark Packaing jobs are broken due to GitBox issue. ``` fatal: unable to access 'https://gitbox.apache.org/repos/asf/spark.git/': Failed to connect to gitbox.apache.org port 443: Connection timed out ``` - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-master-maven-snapshots/2906/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-3.0-maven-snapshots/105/console - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20Packaging/job/spark-branch-2.4-maven-snapshots/439/console ### Does this PR introduce _any_ user-facing change? No. (This is a dev-only script.) ### How was this patch tested? Manual. ``` $ cat ./test.sh . dev/create-release/release-util.sh get_release_info git clone "$ASF_REPO" $ sh test.sh Branch [branch-3.0]: Current branch version is 3.0.1-SNAPSHOT. Release [3.0.0]: RC # [2]: Full name [Dongjoon Hyun]: GPG key [dongjoonapache.org]: ================ Release details: BRANCH: branch-3.0 VERSION: 3.0.0 TAG: v3.0.0-rc2 NEXT: 3.0.1-SNAPSHOT ASF USER: dongjoon GPG KEY: dongjoonapache.org FULL NAME: Dongjoon Hyun E-MAIL: dongjoonapache.org ================ Is this info correct [y/n]? y ASF password: GPG passphrase: Cloning into 'spark'... remote: Enumerating objects: 223, done. remote: Counting objects: 100% (223/223), done. remote: Compressing objects: 100% (117/117), done. remote: Total 708324 (delta 70), reused 138 (delta 32), pack-reused 708101 Receiving objects: 100% (708324/708324), 322.08 MiB | 2.94 MiB/s, done. Resolving deltas: 100% (289268/289268), done. Updating files: 100% (16287/16287), done. $ sh test.sh ... ``` Closes #28513 from dongjoon-hyun/SPARK-31687. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
2020-05-12 16:07:00 -04:00
local VERSION=$(curl -s "$ASF_REPO_WEBUI/$GIT_BRANCH/pom.xml" |
parse_version)
echo "Current branch version is $VERSION."
if [[ ! $VERSION =~ .*-SNAPSHOT ]]; then
error "Not a SNAPSHOT version: $VERSION"
fi
NEXT_VERSION="$VERSION"
RELEASE_VERSION="${VERSION/-SNAPSHOT/}"
SHORT_VERSION=$(echo "$VERSION" | cut -d . -f 1-2)
local REV=$(echo "$RELEASE_VERSION" | cut -d . -f 3)
# Find out what rc is being prepared.
# - If the current version is "x.y.0", then this is rc1 of the "x.y.0" release.
# - If not, need to check whether the previous version has been already released or not.
# - If it has, then we're building rc1 of the current version.
# - If it has not, we're building the next RC of the previous version.
local RC_COUNT
if [ $REV != 0 ]; then
local PREV_REL_REV=$((REV - 1))
local PREV_REL_TAG="v${SHORT_VERSION}.${PREV_REL_REV}"
if check_for_tag "$PREV_REL_TAG"; then
RC_COUNT=1
REV=$((REV + 1))
NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
else
RELEASE_VERSION="${SHORT_VERSION}.${PREV_REL_REV}"
RC_COUNT=$(git ls-remote --tags "$ASF_REPO" "v${RELEASE_VERSION}-rc*" | wc -l)
RC_COUNT=$((RC_COUNT + 1))
fi
else
REV=$((REV + 1))
NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
RC_COUNT=1
fi
export NEXT_VERSION
export RELEASE_VERSION=$(read_config "Release" "$RELEASE_VERSION")
RC_COUNT=$(read_config "RC #" "$RC_COUNT")
# Check if the RC already exists, and if re-creating the RC, skip tag creation.
RELEASE_TAG="v${RELEASE_VERSION}-rc${RC_COUNT}"
SKIP_TAG=0
if check_for_tag "$RELEASE_TAG"; then
read -p "$RELEASE_TAG already exists. Continue anyway [y/n]? " ANSWER
if [ "$ANSWER" != "y" ]; then
error "Exiting."
fi
SKIP_TAG=1
fi
export RELEASE_TAG
GIT_REF="$RELEASE_TAG"
if is_dry_run; then
echo "This is a dry run. Please confirm the ref that will be built for testing."
[SPARK-28496][INFRA] Use branch name instead of tag during dry-run ## What changes were proposed in this pull request? There are two cases when we use `dry run`. First, when the tag already exists, we can ask `confirmation` on the existing tag name. ``` $ dev/create-release/do-release-docker.sh -d /tmp/spark-2.4.4 -n -s docs Output directory already exists. Overwrite and continue? [y/n] y Branch [branch-2.4]: Current branch version is 2.4.4-SNAPSHOT. Release [2.4.4]: 2.4.3 RC # [1]: v2.4.3-rc1 already exists. Continue anyway [y/n]? y This is a dry run. Please confirm the ref that will be built for testing. Ref [v2.4.3-rc1]: ``` Second, when the tag doesn't exist, we had better ask `confirmation` on the branch name. If we do not change the default value, it will fail eventually. ``` $ dev/create-release/do-release-docker.sh -d /tmp/spark-2.4.4 -n -s docs Branch [branch-2.4]: Current branch version is 2.4.4-SNAPSHOT. Release [2.4.4]: RC # [1]: This is a dry run. Please confirm the ref that will be built for testing. Ref [v2.4.4-rc1]: ``` This PR improves the second case by providing the branch name instead. This helps the release testing before tagging. ## How was this patch tested? Manually do the following and check the default value of `Ref` field. ``` $ dev/create-release/do-release-docker.sh -d /tmp/spark-2.4.4 -n -s docs Branch [branch-2.4]: Current branch version is 2.4.4-SNAPSHOT. Release [2.4.4]: RC # [1]: This is a dry run. Please confirm the ref that will be built for testing. Ref [branch-2.4]: ... ``` Closes #25240 from dongjoon-hyun/SPARK-28496. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Marcelo Vanzin <vanzin@cloudera.com>
2019-07-24 17:20:25 -04:00
if [[ $SKIP_TAG = 0 ]]; then
GIT_REF="$GIT_BRANCH"
fi
GIT_REF=$(read_config "Ref" "$GIT_REF")
fi
export GIT_REF
export SPARK_PACKAGE_VERSION="$RELEASE_TAG"
# Gather some user information.
if [ -z "$ASF_USERNAME" ]; then
export ASF_USERNAME=$(read_config "ASF user" "$LOGNAME")
fi
if [ -z "$GIT_NAME" ]; then
GIT_NAME=$(git config user.name || echo "")
export GIT_NAME=$(read_config "Full name" "$GIT_NAME")
fi
export GIT_EMAIL="$ASF_USERNAME@apache.org"
export GPG_KEY=$(read_config "GPG key" "$GIT_EMAIL")
cat <<EOF
================
Release details:
BRANCH: $GIT_BRANCH
VERSION: $RELEASE_VERSION
TAG: $RELEASE_TAG
NEXT: $NEXT_VERSION
ASF USER: $ASF_USERNAME
GPG KEY: $GPG_KEY
FULL NAME: $GIT_NAME
E-MAIL: $GIT_EMAIL
================
EOF
read -p "Is this info correct [y/n]? " ANSWER
if [ "$ANSWER" != "y" ]; then
echo "Exiting."
exit 1
fi
if ! is_dry_run; then
if [ -z "$ASF_PASSWORD" ]; then
stty -echo && printf "ASF password: " && read ASF_PASSWORD && printf '\n' && stty echo
fi
else
ASF_PASSWORD="***INVALID***"
fi
if [ -z "$GPG_PASSPHRASE" ]; then
stty -echo && printf "GPG passphrase: " && read GPG_PASSPHRASE && printf '\n' && stty echo
fi
export ASF_PASSWORD
export GPG_PASSPHRASE
}
function is_dry_run {
[[ $DRY_RUN = 1 ]]
}
# Initializes JAVA_VERSION to the version of the JVM in use.
function init_java {
if [ -z "$JAVA_HOME" ]; then
error "JAVA_HOME is not set."
fi
JAVA_VERSION=$("${JAVA_HOME}"/bin/javac -version 2>&1 | cut -d " " -f 2)
export JAVA_VERSION
}
# Initializes MVN_EXTRA_OPTS and SBT_OPTS depending on the JAVA_VERSION in use. Requires init_java.
function init_maven_sbt {
MVN="build/mvn -B"
MVN_EXTRA_OPTS=
SBT_OPTS=
if [[ $JAVA_VERSION < "1.8." ]]; then
# Needed for maven central when using Java 7.
SBT_OPTS="-Dhttps.protocols=TLSv1.1,TLSv1.2"
MVN_EXTRA_OPTS="-Xmx2g -XX:ReservedCodeCacheSize=1g -Dhttps.protocols=TLSv1.1,TLSv1.2"
MVN="$MVN $MVN_EXTRA_OPTS"
fi
export MVN MVN_EXTRA_OPTS SBT_OPTS
}