#!/usr/bin/env bash set -e set -o pipefail yellow='\033[0;33m' green='\033[0;32m' clear='\033[0m' function indent() { sed -u 's/^/ /' } function announce() { color="$1" msg="$2" echo -e "\n${color}----> ${msg}${clear}" } function step() { color="$1" msg="$2" echo -e "\n${color} ${msg}${clear}" } function cleanup { announce "${yellow}" "Cleaning up" rm -rf ~/.gem } trap cleanup EXIT announce "${yellow}" "Create the postgres databases" psql -c 'CREATE DATABASE lalala_test' -U postgres | indent announce "${yellow}" "Run the tests" rake | indent # Are we allowed to push gems? if [[ "$TRAVIS_SECURE_ENV_VARS" == "true" && "$TRAVIS_PULL_REQUEST" == "false" ]] then # Are we in the canonical environment? if [[ "$TRAVIS_BRANCH" == "master" && "$DB" == "postgresql" ]] then announce "${yellow}" "Build development gems" export LALALA_BUILD_VERSION="$TRAVIS_BUILD_NUMBER" { # set the build version cd lib/lalala mv version.rb version.rb_ cat version.rb_ | sed "s|{{BUILD_NUMBER}}|$LALALA_BUILD_VERSION|" > version.rb rm version.rb_ cd - } > /dev/null step "${yellow}" "Building lalala" rake lalala:build | indent step "${yellow}" "Building lalala-assets" rake lalala-assets:build | indent step "${yellow}" "Building lalala-development" rake lalala-development:build | indent step "${yellow}" "Building lalala-test" rake lalala-test:build | indent announce "${yellow}" "Release development gems" mkdir -p "$HOME/.gem/" echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > "$HOME/.gem/credentials" chmod 0600 "$HOME/.gem/credentials" step "${yellow}" "Releasing lalala" gem push pkg/lalala-[0-9]*.gem | indent step "${yellow}" "Releasing lalala-assets" gem push pkg/lalala-assets-[0-9]*.gem | indent step "${yellow}" "Releasing lalala-development" gem push pkg/lalala-development-[0-9]*.gem | indent step "${yellow}" "Releasing lalala-test" gem push pkg/lalala-test-[0-9]*.gem | indent fi fi announce "${green}" "Done"