Guest User

Untitled

a guest
Nov 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Script to initiate a merge from master into
  4. # production branch in preparation for a release
  5.  
  6. usage() {
  7. echo "options"
  8. echo "-f|--force ignore test failures on master"
  9. echo "-m merge commit message"
  10. exit 1
  11. }
  12.  
  13. echo "Preparing a branch to merge master into production branch."
  14.  
  15. while [[ $# > 0 ]]; do
  16. case $1 in
  17. -f|--force)
  18. FORCE=true
  19. ;;
  20. -m)
  21. MESSAGE="$2"
  22. shift
  23. ;;
  24. -l)
  25. LOGFILE="$2"
  26. shift
  27. ;;
  28. *)
  29. usage
  30. ;;
  31. esac
  32. shift
  33. done
  34.  
  35. if [[ -z "$MESSAGE" ]]; then
  36. usage
  37. fi
  38.  
  39. BRANCH=release-$(date -u +'%Y-%m-%d-%H%M%S')
  40.  
  41. if [[ -z "$LOGFILE" ]]; then
  42. LOGFILE="start_release.$BRANCH.log"
  43. fi
  44.  
  45. echo "Logging to $LOGFILE"
  46.  
  47. echo "Currently in ${PWD}"
  48.  
  49. STATUS=$($(find . -name "bamboo-ctl.js") status --branch master)
  50. if [[ "$STATUS" == *"Failed"* ]]; then
  51. if [[ $FORCE == true ]]; then
  52. echo "Master is red, but going ahead anyway!"
  53. else
  54. echo "$STATUS"
  55. echo
  56. echo "Master is red. Use --force to push anyway"
  57.  
  58. exit 1
  59. fi
  60. fi
  61.  
  62. git status >> $LOGFILE
  63.  
  64. echo "Checking out $BRANCH from production"
  65. git checkout -b $BRANCH --no-track origin/production >> $LOGFILE
  66. if [[ $? != 0 ]]; then
  67. echo "checkout $BRANCH failed"
  68. exit 1
  69. fi
  70.  
  71. echo "Merging master into $BRANCH"
  72. git merge -s recursive -X theirs origin/master -m "$MESSAGE" >> $LOGFILE
  73. if [[ $? != 0 ]]; then
  74. echo "Merge failed. Exiting..."
  75. exit 1
  76. fi
  77.  
  78. echo "Sanity checking branch"
  79.  
  80. SANITY=$(git diff $BRANCH..origin/master)
  81. if [[ -n "$SANITY" ]]; then
  82. echo "$SANITY"
  83. echo
  84. echo "Something went wrong with the merge. Fix the diff by hand. Exiting..."
  85. exit 1
  86. fi
  87.  
  88. echo "Pushing $BRANCH"
  89. git push origin $BRANCH
Add Comment
Please, Sign In to add comment