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}"
|
|
|
|
readonly TARGET_BRANCH="${TARGET_BRANCH:-master}"
|
2017-06-14 14:22:25 +03:00
|
|
|
readonly SOURCE_BRANCH="${SOURCE_BRANCH:-ibex-version-1.0}"
|
|
|
|
|
|
|
|
readonly AUTOCOMMIT_NAME="Travis CI"
|
|
|
|
readonly AUTOCOMMIT_EMAIL="travis@travis-ci.org"
|
2017-06-14 16:56:03 +03:00
|
|
|
readonly AUTOCOMMIT_BRANCH="temp"
|
2017-06-13 12:37:11 +03:00
|
|
|
|
|
|
|
log() {
|
|
|
|
echo "$@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_preconditions_met() {
|
2017-06-14 14:22:25 +03:00
|
|
|
if [ -z "${TRAVIS_PULL_REQUEST_BRANCH}" ]; then
|
|
|
|
log "Job is CI for a push, skipping creation of production build"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ "${TRAVIS_BRANCH}_${TRAVIS_PULL_REQUEST_BRANCH}" != "${TARGET_BRANCH}_${SOURCE_BRANCH}" ]; then
|
2017-06-13 12:37:11 +03:00
|
|
|
log "Skipping creation of production build"
|
2017-06-14 14:22:25 +03:00
|
|
|
log "We only create production builds for pull requests from '${SOURCE_BRANCH}' to '${TARGET_BRANCH}'"
|
|
|
|
log "but this pull request is from '${TRAVIS_PULL_REQUEST BRANCH}' to '${TRAVIS_BRANCH}'"
|
2017-06-13 12:37:11 +03:00
|
|
|
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() {
|
2017-06-15 11:18:27 +03:00
|
|
|
yarn build
|
2017-06-13 12:37:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_git() {
|
2017-06-14 14:22:25 +03:00
|
|
|
git config user.name "${AUTOCOMMIT_NAME}"
|
|
|
|
git config user.email "${AUTOCOMMIT_EMAIL}"
|
2017-06-13 12:37:11 +03:00
|
|
|
git remote add origin-travis "https://${GITHUB_TOKEN}@github.com/${GITHUB_ORG}/${GITHUB_REPO}.git"
|
|
|
|
}
|
|
|
|
|
|
|
|
commit_build_files() {
|
2017-06-14 16:56:03 +03:00
|
|
|
git checkout -b "${AUTOCOMMIT_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 16:56:03 +03:00
|
|
|
git push origin-travis "${AUTOCOMMIT_BRANCH}:${SOURCE_BRANCH}"
|
2017-06-13 12:37:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ensure_preconditions_met
|
|
|
|
setup_git
|
|
|
|
commit_build_files
|
|
|
|
push_to_github
|