Last active
May 12, 2016 01:42
-
-
Save mathewmariani/eabd92be83da367574069adc4d9ad2d3 to your computer and use it in GitHub Desktop.
Used for deploying to a build repository using Travis-CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit with nonzero exit code if anything fails | |
set -e | |
# set up some variables | |
SOURCE_BRANCH="<source_branch>" | |
TARGET_BRANCH="<target_branch"> | |
GITHUB_REF="github.com/<username>/<repo_name>.git" | |
NAME="<your_name>" | |
EMAIL="<your_email>" | |
BUILD_DIR="<build_dir>" | |
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify | |
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then | |
echo "This commit was made against the ${TRAVIS_BRANCH} and not the ${SOURCE_BRANCH}!" | |
exit 0 | |
fi | |
# change to build directory | |
# eg, Jekyll would build to _site | |
cd ${BUILD_DIR} | |
# create git, and commit | |
git init | |
git config user.name ${NAME} | |
git config user.email ${EMAIL} | |
git add . | |
# add a simple message for the commit | |
git commit -m "Deployed to ${TARGET_BRANCH} - Travis-CI" | |
# push quietly not to leak info like an OAuth token | |
git push --force --quiet "https://${GITHUB_TOKEN}@${GITHUB_REF}" ${SOURCE_BRANCH}:${TARGET_BRANCH} > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment