|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Because `hub` is used, this script expects the following environment variables defined in travis job settings: |
| 5 | +# GITHUB_TOKEN - github api token with repo permissions (display value in build log setting: OFF) |
| 6 | +# GITHUB_USER - github username that GITHUB_TOKEN is associated with (display value in build log setting: ON) |
| 7 | + |
| 8 | +# Additionally, it needs the following environment variables: |
| 9 | +# VERSION - defined in .travis.yml |
| 10 | + |
| 11 | +# Variables starting with TRAVIS_ are default environment variables available to all Travis CI builds |
| 12 | + |
| 13 | +COLOR_RESET='\033[0m' |
| 14 | +COLOR_MAGENTA='\033[0;35m' |
| 15 | +COLOR_CYAN='\033[0;36m' |
| 16 | +MYREPO=${HOME}/workdir/${TRAVIS_REPO_SLUG} |
| 17 | +AUTOBRANCH=${GITHUB_USER}/prepareRelease${VERSION} |
| 18 | +BUILD_OUTPUT=/tmp/build.out |
| 19 | +touch $BUILD_OUTPUT |
| 20 | + |
| 21 | +function prep_workspace { |
| 22 | + rm -rf ${MYREPO} |
| 23 | + mkdir -p ${MYREPO} |
| 24 | + git clone -b ${TRAVIS_BRANCH} https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${MYREPO} |
| 25 | + cd ${MYREPO} |
| 26 | + git checkout -b ${AUTOBRANCH} |
| 27 | +} |
| 28 | + |
| 29 | +dump_output() { |
| 30 | + echo "last 100 lines of output:" |
| 31 | + tail -100 $BUILD_OUTPUT |
| 32 | +} |
| 33 | + |
| 34 | +function error_handler() { |
| 35 | + echo "ERROR: An error was encountered." |
| 36 | + dump_output |
| 37 | + exit 1 |
| 38 | +} |
| 39 | + |
| 40 | +function do_stuff { |
| 41 | + # keepalive for Travis |
| 42 | + while :; do sleep 10; echo -n .; done & |
| 43 | + trap "kill $!" EXIT |
| 44 | + trap 'error_handler' ERR |
| 45 | + |
| 46 | + myscripts=( "build_all.sh" "test_all.sh" "update_version.sh ${VERSION}" ) |
| 47 | + for i in "${myscripts[@]}"; do |
| 48 | + echo -n "${i} " |
| 49 | + Scripts/${i} >> $BUILD_OUTPUT 2>&1 |
| 50 | + echo |
| 51 | + done |
| 52 | + |
| 53 | + dump_output |
| 54 | + kill $! && trap " " EXIT |
| 55 | +} |
| 56 | + |
| 57 | +function push_changes { |
| 58 | + git config user.email "optibot@users.noreply.github.com" |
| 59 | + git config user.name "${GITHUB_USER}" |
| 60 | + git add --all && git commit -m "ci(travis): auto release prep for $VERSION" |
| 61 | + git push https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${AUTOBRANCH} |
| 62 | + PR_URL=$(hub pull-request --no-edit -b ${TRAVIS_BRANCH}) |
| 63 | + echo -e "${COLOR_CYAN}ATTENTION:${COLOR_RESET} review and merge ${COLOR_CYAN}${PR_URL}${COLOR_RESET}" |
| 64 | + echo "then to release to cocoapods use Travis CI's Trigger build with the following payload:" |
| 65 | + echo -e "${COLOR_MAGENTA}env:${COLOR_RESET}" |
| 66 | + echo -e "${COLOR_MAGENTA} - RELEASE=true${COLOR_RESET}" |
| 67 | +} |
| 68 | + |
| 69 | +function main { |
| 70 | + prep_workspace |
| 71 | + time do_stuff |
| 72 | + push_changes |
| 73 | +} |
| 74 | + |
| 75 | +main |
0 commit comments