Skip to content

Instantly share code, notes, and snippets.

@sproogen
Last active June 29, 2018 12:19
Show Gist options
  • Save sproogen/7f55b2f9ed515713093f18ae625aaa62 to your computer and use it in GitHub Desktop.
Save sproogen/7f55b2f9ed515713093f18ae625aaa62 to your computer and use it in GitHub Desktop.
A simple bash script for a Travis CI build to merge changes to the downstream develop branch or create a PR with conflicts
#!/bin/bash
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
git remote set-branches --add origin develop;
git fetch origin develop;
git checkout develop;
git merge master;
if [[ ("$?" -ne "0") ]]; then
git merge --abort;
git reset --hard;
git checkout master;
CONFLICT_BRANCH_NAME=merge-conflict-$(date | md5sum | head -c 6);
git checkout -b $CONFLICT_BRANCH_NAME;
git push "https://${GITHUB_TOKEN}@${GITHUB_REPO}" $CONFLICT_BRANCH_NAME;
curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"title":"Automatic merge failure", "base":"develop", "head":"'$CONFLICT_BRANCH_NAME'"}' "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/pulls";
else
git push "https://${GITHUB_TOKEN}@${GITHUB_REPO}" develop;
fi
git checkout master;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment