Skip to content

Commit

Permalink
added support for building named releases based from travis based on …
Browse files Browse the repository at this point in the history
…tags / releases
  • Loading branch information
OriHoch authored Feb 8, 2017
1 parent 1ed0b34 commit 84f354a
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions .travis/on_build_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ _get_package_version() {

_get_deployment_package_filename() {
local package_version="${1}"
echo "spark-`npm view spark version`-${TRAVIS_BRANCH}-${TRAVIS_BUILD_ID}.tar.gz"
local is_tagged="${2}"
if [ "${is_tagged}" == "1" ]; then
echo "spark-${package_version}.tar.gz"
else
echo "spark-${package_version}-${TRAVIS_BRANCH}-${TRAVIS_BUILD_ID}.tar.gz"
fi
}

_get_build_details() {
Expand All @@ -21,7 +26,8 @@ _get_travis_build_url() {

_get_package_url() {
local package_version="${1}"
local package_filename=`_get_deployment_package_filename "${package_version}"`
local is_tagged="${2}"
local package_filename=`_get_deployment_package_filename "${package_version}" "${is_tagged}"`
if [ -f "${package_filename}.slack_url" ]; then
cat "${package_filename}.slack_url"
else
Expand All @@ -46,8 +52,9 @@ _send_slack_notification() {

_build_package() {
local package_version="${1}"
local is_tagged="${2}"
echo "creating build package"
if npm run build --file=`_get_deployment_package_filename "${package_version}"`; then
if npm run build --file=`_get_deployment_package_filename "${package_version}" "${is_tagged}"`; then
echo; echo "OK"
return 0
else
Expand All @@ -59,9 +66,10 @@ _build_package() {

_upload_package() {
local package_version="${1}"
local is_tagged="${2}"
if [ "${TRAVIS_PULL_REQUEST}" == "false" ] && [ "${SLACK_API_TOKEN}" != "" ]; then
echo "uploading build package to slack"
if npm run upload --token="${SLACK_API_TOKEN}" --file=`_get_deployment_package_filename "${package_version}"`; then
if npm run upload --token="${SLACK_API_TOKEN}" --file=`_get_deployment_package_filename "${package_version}" "${is_tagged}"`; then
echo; echo "OK"
return 0
else
Expand All @@ -76,10 +84,11 @@ _upload_package() {

_deploy() {
local package_version="${1}"
local is_tagged="${2}"
if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ] && [ "${SLACK_API_TOKEN}" != "" ]; then
echo -e "${SPARK_DEPLOYMENT_KEY}" > deployment.key
chmod 400 deployment.key
if ssh -o StrictHostKeyChecking=no -i deployment.key "${SPARK_DEPLOYMENT_HOST}" "`_get_package_url "${package_version}"`"; then
if ssh -o StrictHostKeyChecking=no -i deployment.key "${SPARK_DEPLOYMENT_HOST}" "`_get_package_url "${package_version}" "${is_tagged}"`"; then
echo; echo "OK"
return 0
else
Expand All @@ -101,7 +110,8 @@ _exit_error_send_slack_notification() {

_exit_success_send_slack_notification() {
local package_version="${1}"
_send_slack_notification ":sunglasses: Travis build success\npackage_url=`_get_package_url "${package_version}"`\n"
local is_tagged="${2}"
_send_slack_notification ":sunglasses: Travis build success\npackage_url=`_get_package_url "${package_version}" "${is_tagged}"`\n"
echo
echo "GREAT SUCCESS!"
exit 0
Expand All @@ -113,22 +123,26 @@ main() {
local is_success="${1}"
if [ "${is_success}" == "1" ]; then
echo "building and uploading deployment package"
local package_version=`_get_package_version`
if [ "${TRAVIS_TAG}" != "" ] && [ "${TRAVIS_REPO_SLUG}" == "Midburn/Spark" ]; then
local package_version="${TRAVIS_TAG}"
local is_tagged="1"
else
local package_version=`_get_package_version`
local is_tagged="0"
fi
if [ "${SKIP_BUILD}" != "1" ]; then
_build_package "${package_version}" || _exit_error_send_slack_notification
_build_package "${package_version}" "${is_tagged}" || _exit_error_send_slack_notification
fi
if [ "${SKIP_UPLOAD}" != "1" ]; then
_upload_package "${package_version}" || _exit_error_send_slack_notification
_upload_package "${package_version}" "${is_tagged}" || _exit_error_send_slack_notification
fi
if [ "${SKIP_DEPLOY}" != "1" ]; then
_deploy "${package_version}" || _exit_error_send_slack_notification
_deploy "${package_version}" "${is_tagged}" || _exit_error_send_slack_notification
fi
_exit_success_send_slack_notification "${package_version}"
_exit_success_send_slack_notification "${package_version}" "${is_tagged}"
else
_exit_error_send_slack_notification
fi

}

main "${1}"

0 comments on commit 84f354a

Please sign in to comment.