Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Script to initiate a merge from master into
- # production branch in preparation for a release
- usage() {
- echo "options"
- echo "-f|--force ignore test failures on master"
- echo "-m merge commit message"
- exit 1
- }
- echo "Preparing a branch to merge master into production branch."
- while [[ $# > 0 ]]; do
- case $1 in
- -f|--force)
- FORCE=true
- ;;
- -m)
- MESSAGE="$2"
- shift
- ;;
- -l)
- LOGFILE="$2"
- shift
- ;;
- *)
- usage
- ;;
- esac
- shift
- done
- if [[ -z "$MESSAGE" ]]; then
- usage
- fi
- BRANCH=release-$(date -u +'%Y-%m-%d-%H%M%S')
- if [[ -z "$LOGFILE" ]]; then
- LOGFILE="start_release.$BRANCH.log"
- fi
- echo "Logging to $LOGFILE"
- echo "Currently in ${PWD}"
- STATUS=$($(find . -name "bamboo-ctl.js") status --branch master)
- if [[ "$STATUS" == *"Failed"* ]]; then
- if [[ $FORCE == true ]]; then
- echo "Master is red, but going ahead anyway!"
- else
- echo "$STATUS"
- echo
- echo "Master is red. Use --force to push anyway"
- exit 1
- fi
- fi
- git status >> $LOGFILE
- echo "Checking out $BRANCH from production"
- git checkout -b $BRANCH --no-track origin/production >> $LOGFILE
- if [[ $? != 0 ]]; then
- echo "checkout $BRANCH failed"
- exit 1
- fi
- echo "Merging master into $BRANCH"
- git merge -s recursive -X theirs origin/master -m "$MESSAGE" >> $LOGFILE
- if [[ $? != 0 ]]; then
- echo "Merge failed. Exiting..."
- exit 1
- fi
- echo "Sanity checking branch"
- SANITY=$(git diff $BRANCH..origin/master)
- if [[ -n "$SANITY" ]]; then
- echo "$SANITY"
- echo
- echo "Something went wrong with the merge. Fix the diff by hand. Exiting..."
- exit 1
- fi
- echo "Pushing $BRANCH"
- git push origin $BRANCH
Add Comment
Please, Sign In to add comment