Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deploying from TravisCI Tag Builds #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions bin/gh-pages-travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,52 @@ if [ -n "$TRAVIS_BUILD_ID" ]; then
echo SSH_KEY: $SSH_KEY
echo GIT_NAME: $GIT_NAME
echo GIT_EMAIL: $GIT_EMAIL
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Travis should not deploy from pull requests"
exit 0
fi

# Check if tag build - on Tag Builds TravisCI applies the tag name to both TRAVIS_TAG and TRAVIS_BRANCH therefore if they are equal it is a Tag Build
if [ "$TRAVIS_BRANCH" != "$TRAVIS_TAG" ]; then
# Not Tag build - check branch
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
# Branch build, wrong branch - don't deploy
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch, not the current TRAVIS_BRANCH ($TRAVIS_BRANCH) branch"
exit 0
else
# Branch build, correct branch - fall through to deploy
echo "Branch Build"
fi
else
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Travis should not deploy from pull requests"
# Get the branch name this tag is on - this should return "* branchname"
TRAVIS_TAG_BRANCH=$(git branch --contains tags/$TRAVIS_TAG)
# This will always return the checked-out branch, so remove the "* "
TRAVIS_TAG_BRANCH=${TRAVIS_TAG_BRANCH#"* "}

if [ "$TRAVIS_TAG_BRANCH" != "$DEPLOY_BRANCH" ]; then
# Tag build with wrong branch - don't deploy
echo "Travis should only deploy from TRAVIS_TAG ($TRAVIS_TAG) on the ($DEPLOY_BRANCH) branch, not the current ($TRAVIS_TAG_BRANCH) branch"
exit 0
else
# switch both git and https protocols as we don't know which travis
# is using today (it changed!)
REPO=${REPO/git:\/\/github.com\//[email protected]:}
REPO=${REPO/https:\/\/github.com\//[email protected]:}

chmod 600 $SSH_KEY
eval `ssh-agent -s`
ssh-add $SSH_KEY
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
# Tag build with correct branch - fall through to deploy
echo "Tag Build"
fi
fi
fi


# switch both git and https protocols as we don't know which travis
# is using today (it changed!)
REPO=${REPO/git:\/\/github.com\//[email protected]:}
REPO=${REPO/https:\/\/github.com\//[email protected]:}

chmod 600 $SSH_KEY
eval `ssh-agent -s`
ssh-add $SSH_KEY
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"

# deploy to the specified branch
REPO_NAME=$(basename $REPO)
TARGET_DIR=$(mktemp -d /tmp/$REPO_NAME.XXXX)
REV=$(git rev-parse HEAD)
Expand Down