2017-06-13 12:37:11 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
readonly GITHUB_ORG="${GITHUB_ORG:-CatalystCode}"
|
|
|
|
readonly GITHUB_REPO="${GITHUB_REPO:-ibex-dashboard}"
|
2017-06-14 14:05:25 +03:00
|
|
|
readonly TARGET_BRANCH="${TARGET_BRANCH:-ibex-version-1.0}"
|
2017-06-13 12:37:11 +03:00
|
|
|
|
|
|
|
log() {
|
|
|
|
echo "$@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_preconditions_met() {
|
|
|
|
if [ "${TRAVIS_BRANCH}" != "${TARGET_BRANCH}" ]; then
|
2017-06-13 13:48:27 +03:00
|
|
|
log "Build is targeting ${TRAVIS_BRANCH}, not ${TARGET_BRANCH}"
|
2017-06-13 12:37:11 +03:00
|
|
|
log "Skipping creation of production build"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ -z "${GITHUB_TOKEN}" ]; then
|
|
|
|
log "GITHUB_TOKEN not set: won't be able to push production build"
|
|
|
|
log "Please configure the token in .travis.yml or the Travis UI"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
create_production_build() {
|
|
|
|
CI="" yarn build
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_git() {
|
|
|
|
git config user.name "Travis CI"
|
|
|
|
git config user.email "travis@travis-ci.org"
|
|
|
|
git remote add origin-travis "https://${GITHUB_TOKEN}@github.com/${GITHUB_ORG}/${GITHUB_REPO}.git"
|
|
|
|
}
|
|
|
|
|
|
|
|
commit_build_files() {
|
2017-06-14 14:05:25 +03:00
|
|
|
git checkout "${TARGET_BRANCH}"
|
2017-06-13 12:37:11 +03:00
|
|
|
git add --all build
|
|
|
|
echo -e "Travis build: ${TRAVIS_BUILD_NUMBER}\n\nhttps://travis-ci.org/${GITHUB_ORG}/${GITHUB_REPO}/builds/${TRAVIS_BUILD_ID}" | git commit --file -
|
|
|
|
}
|
|
|
|
|
|
|
|
push_to_github() {
|
2017-06-14 14:05:25 +03:00
|
|
|
git push origin-travis "${TARGET_BRANCH}:${TARGET_BRANCH}"
|
2017-06-13 12:37:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ensure_preconditions_met
|
|
|
|
create_production_build
|
|
|
|
setup_git
|
|
|
|
commit_build_files
|
|
|
|
push_to_github
|