2011-12-09 21:55:49 +13:00
#!/usr/bin/env bash
#
# Release script for Akka.
2012-02-06 12:06:36 +13:00
#
2013-05-14 13:17:39 +02:00
# ATTENTION: This script involves calling `git clean -fxd` which will remove all untracked
# files from your working directory (including IDE settings).
#
2012-11-07 11:51:59 +01:00
# Prerequisites and Installation Instructions
2012-02-06 12:06:36 +13:00
#
2012-11-07 11:51:59 +01:00
# 1) You must be able to sign the artifacts with PGP
#
# 1.1) If you don't have PGP and a PGP key
# On OS X from othe command line:
# shell> brew install gnupg
# shell> gpg --gen-key
#
2020-01-27 13:27:56 +01:00
# On OS X the following should be added to ~/.bash_profile
# GPG_TTY=$(tty)
# export GPG_TTY
#
2012-11-07 11:51:59 +01:00
# Default values for the key type and 2048 bits is OK.
# Make sure to use the email address that you will use later to register
# with Sonatype.
#
2013-05-14 11:50:23 +02:00
# 1.2) Check that signing works
2012-11-07 11:51:59 +01:00
# From inside sbt do the following
2016-02-22 11:17:33 +02:00
# sbt> publishLocalSigned
2012-11-07 11:51:59 +01:00
# It should should ask you for your pass phrase, and create .asc files for
# all artifacts
#
2013-05-14 11:50:23 +02:00
# 1.3) Publish your key to a server that Sonatype use
2012-11-07 11:51:59 +01:00
# From the command line:
# shell> gpg --keyserver hkp://pool.sks-keyservers.net/ --send-keys <your key id>
# To find out your key id do this from the command line:
# shell> gpg --list-keys
# pub 2048/<your key id> ...
2013-05-14 11:50:23 +02:00
# You can verify the existence of your key here, if you don't trust your tool:
2014-08-16 11:47:23 -07:00
# https://sks-keyservers.net/i/#extract
2012-11-07 11:51:59 +01:00
#
# 2) You must have publishing rights to oss.sonatype.org
#
# 2.1) Register with oss.sonatype.org by only following the instructions under
# sign up here https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
# Use the same email address as you used for the pgp key.
#
# 2.2) Ask Jonas who is the original creator of this ticket https://issues.sonatype.org/browse/OSSRH-3097
# to add a comment that says that your username (not your full name) should
# have publish access to that project. There is manual administration of
# the ticket at Sonatype, so it could take a little while.
#
# 2.3) Add your credentials to sbt by adding a global.sbt file in your sbt home
# directory containing the following.
# credentials += Credentials("Sonatype Nexus Repository Manager",
# "oss.sonatype.org",
# "<your username>",
# "<your password>")
#
2017-09-12 11:13:25 +02:00
# 3) You must have access to gustav.akka.io
# Please note that gustav.akka.io is the same as repo.akka.io,
# but the latter domain is pointed at cloudflare so one could not ssh into it.
2012-11-07 11:51:59 +01:00
#
2014-01-17 11:07:10 +01:00
# 3.1) Ask someone in the team for login information for the akkarepo user.
2012-11-07 11:51:59 +01:00
#
2014-01-17 11:07:10 +01:00
# 3.2) Install your public ssh key to avoid typing in your password.
2012-11-07 11:51:59 +01:00
# From the command line:
2017-09-12 11:13:25 +02:00
# shell> cat ~/.ssh/id_rsa.pub | ssh akkarepo@gustav.akka.io "cat >> ~/.ssh/authorized_keys"
2020-03-27 10:30:38 +01:00
#
# 3.3) Also make it available for publishing snapshots.
# From the command line:
2020-05-07 15:18:20 +02:00
# shell> cp ~/.ssh/id_rsa ~/.ssh/id_rsa_gustav.pem
2020-03-27 10:30:38 +01:00
# shell> ssh-keygen -p -f ~/.ssh/id_rsa_gustav.pem -m pem
#
2017-01-25 18:04:24 +01:00
# 4) Have access to github.com/akka/akka. This should be a given.
2012-11-07 11:51:59 +01:00
#
# Now you should be all set to run the script
#
2020-06-11 12:31:07 +02:00
# Run the script:
#
2020-03-27 11:59:30 +01:00
# shell> project/scripts/release
2012-11-07 11:51:59 +01:00
#
2020-06-11 12:31:07 +02:00
# The artifacts published to oss.sonatype.org need to be released by following the
2012-11-07 11:51:59 +01:00
# instructions under release here
# https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
2011-12-09 21:55:49 +13:00
# defaults
2017-09-12 11:13:25 +02:00
declare -r default_server="akkarepo@gustav.akka.io"
2012-10-24 11:37:26 +13:00
declare -r default_path="www"
2011-12-09 21:55:49 +13:00
# settings
declare release_server=${default_server}
declare release_path=${default_path}
# get the source location for this script; handles symlinks
function get_script_path {
local source="${BASH_SOURCE[0]}"
while [ -h "${source}" ] ; do
source="$(readlink "${source}")";
done
echo ${source}
}
# path, name, and dir for this script
declare -r script_path=$(get_script_path)
declare -r script_name=$(basename "${script_path}")
declare -r script_dir="$(cd -P "$(dirname "${script_path}")" && pwd)"
# print usage info
function usage {
cat <<EOM
2014-11-30 15:53:41 +02:00
Dry run is be default.
2020-03-27 11:59:30 +01:00
Usage: ${script_name} [options]
2011-12-24 16:43:08 +13:00
-h | --help Print this usage message
-s | --server SERVER Set the release server (default ${default_server})
-p | --path PATH Set the path on the release server (default ${default_path})
2011-12-09 21:55:49 +13:00
EOM
}
# echo a log message
function echolog {
echo "[${script_name}] $@"
}
# echo an error message
function echoerr {
echo "[${script_name}] $@" 1>&2
}
# fail the script with an error message
function fail {
echoerr "$@"
exit 1
}
# process options and set flags
while true; do
case "$1" in
-h | --help ) usage; exit 1 ;;
-s | --server ) release_server=$2; shift 2 ;;
-p | --path ) release_path=$2; shift 2 ;;
* ) break ;;
esac
done
declare -r publish_path="${release_server}:${release_path}"
2018-07-02 16:38:07 +02:00
JAVA_VERSION=`java -version 2>&1 | grep -E "java version|openjdk version" | cut -d '"' -f2 | cut -d '.' -f1`
2019-03-12 15:50:54 +01:00
[[ $JAVA_VERSION -ge 11 ]] || fail "Java version is not at least 11"
2012-06-11 11:26:28 +02:00
2011-12-09 21:55:49 +13:00
# check for a git command
type -P git &> /dev/null || fail "git command not found"
# check for an sbt command
type -P sbt &> /dev/null || fail "sbt command not found"
2011-12-24 16:43:08 +13:00
# check for an rsync command
type -P rsync &> /dev/null || fail "rsync command not found"
# check for a tar command
type -P tar &> /dev/null || fail "tar command not found"
2011-12-09 21:55:49 +13:00
# get the current project version from sbt
# a little messy as the ansi escape codes are included
function get_current_version {
2017-12-08 16:53:47 +01:00
local result=$(sbt version | grep -v warn | grep -v "coordinated shutdown" | tail -1 | cut -f2)
2011-12-09 21:55:49 +13:00
# remove ansi escape code from end
local code0=$(echo -e "\033[0m")
echo ${result%$code0}
}
# check that we have a clean status
[[ -z "$(git status --porcelain)" ]] || {
git status
fail "There are uncommitted changes - please commit before releasing"
}
2013-05-14 13:17:39 +02:00
(read -p "The working directory will now be cleaned from all non-tracked files. Are you sure you want this? " x; test "$x" = yes) || fail "bailing out"
git clean -fxd || fail "cannot git clean -fxd"
2011-12-09 21:55:49 +13:00
# try to run a cleanup command - these shouldn't actually fail
function safely {
"$@" || fail "Failed to clean up release - please check current state"
}
# perform a clean up when a failure has occurred
function git_cleanup {
echoerr "Cleaning up..."
safely git reset --hard
safely git clean -f
}
# clean up and fail the script with an error message
function bail_out {
echoerr "Bailing out!"
git_cleanup
2011-12-24 16:43:08 +13:00
echoerr "Cleaned up failed release"
2011-12-09 21:55:49 +13:00
fail "$@"
}
# bail out for signals
function signal_bail_out {
echoerr "Interrupted by signal"
bail_out "Received signal to stop release"
}
# bail out on signals
trap signal_bail_out SIGHUP SIGINT SIGTERM
# try to run a command or otherwise bail out
function try {
"$@" || bail_out "Failed to create release"
}
2020-03-27 11:59:30 +01:00
declare -r version=$(get_current_version)
if [ ${#version} -gt 6 ]; then
fail "Version [$version] is too long to be a regular release, have you created a tag?"
fi
echolog "Creating release ${version}..."
2011-12-24 16:43:08 +13:00
2020-06-11 12:31:07 +02:00
echolog "Publishing to ${publish_path}"
2011-12-09 21:55:49 +13:00
# try ssh'ing to the release server
echolog "Checking ssh connection to ${release_server}"
try ssh -t ${release_server} echo "Successfully contacted release server."
# start clean
try sbt clean
2020-06-11 12:31:07 +02:00
echolog "Running migration manager report..."
try sbt $RELEASE_OPT +mimaReportBinaryIssues
echolog "Finished migration manager report"
2020-03-27 11:59:30 +01:00
2011-12-09 21:55:49 +13:00
# build the release
echolog "Building the release..."
2020-06-11 12:31:07 +02:00
RELEASE_OPT="-Dakka.genjavadoc.enabled=true -Dpublish.maven.central=true"
2019-05-24 11:31:19 +02:00
2020-03-27 11:59:30 +01:00
# Release artifacts
2020-03-30 16:48:15 +02:00
try sbt $RELEASE_OPT +publishSigned
2019-12-16 14:33:17 +01:00
2020-03-30 16:48:15 +02:00
echolog "Successfully released artifacts"
2017-06-13 02:18:24 -07:00
2020-03-27 11:59:30 +01:00
try sbt $RELEASE_OPT whitesourceCheckPolicies
2011-12-09 21:55:49 +13:00
# use a special failure from now on
function arrgh {
cat 1>&2 <<EOM
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Release failed while pushing to servers!
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EOM
fail "Could not complete release - please check current state"
}
# try running a pushing command or otherwise fail
function important {
"$@" || arrgh
}
# new interrupted bail out for signals
function arrgh_interrupt {
echoerr "Interrupted by signal"
arrgh
}
# new exit on signals
trap arrgh_interrupt SIGHUP SIGINT SIGTERM
# push the commits and tags to git origin
echolog "Pushing to git origin..."
2020-06-11 12:31:07 +02:00
important git push origin --tags
2011-12-09 21:55:49 +13:00
2020-03-30 16:48:15 +02:00
echolog "Building docs and pushing to the server..."
2020-06-11 12:31:07 +02:00
important ssh ${release_server} "cd ${release_path}/docs/akka; git add .; git commit -m 'before publishing version $version'; true"
# using Scala 2.13 here to avoid the infamous problem with missing AskSupport in classpath
important sbt -Dakka.build.scalaVersion=2.13.0 $RELEASE_OPT publishRsync
important ssh ${release_server} "cd ${release_path}/docs/akka; git add .; git commit -m 'publish version $version'"
2011-12-09 21:55:49 +13:00
2016-03-08 15:11:43 +01:00
echolog "*****"
2020-06-11 12:31:07 +02:00
echolog "Do not forget to update https://github.com/akka/akka.io/blob/master/versions.json !"
2016-03-08 15:11:43 +01:00
echolog "*****"
2015-08-22 18:35:20 +02:00
2020-06-11 12:31:07 +02:00
echolog "Successfully created release ${version}"