Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #!/bin/bash
  2. set -o nounset -o pipefail -o errexit
  3. cd "$(dirname "$0")/../.."
  4.  
  5. ################################################################################
  6. # Master one liner interaction with deploying files
  7. #
  8. # Build the assets, then add and commit the files to git
  9. # Then uploads the current branch to the live site, staging site and to GitLab
  10. #
  11. # USAGE:
  12. # Default usage - ./scripts/deploy/build.sh
  13. #
  14. # This will add and commit files to git with the message
  15. # Committing changes, and then push the changes to gitlab and
  16. # staging
  17. #
  18. # Remove push - ./scripts/deploy/build.sh -g -s
  19. #
  20. # There are two flags with which you can stop pushing to
  21. # their respective remotes
  22. #
  23. # -g means don't push to gitlab
  24. # -s means don't push to staging
  25. #
  26. # Deploy to live - ./scripts/deploy/build.sh -l
  27. #
  28. # This is the same behaviour as the default, except it will
  29. # also push to the live site
  30. #
  31. # Build assets - ./scripts/deploy/build.sh -b
  32. #
  33. # This is the same behaviour as the default, except it will
  34. # also run the builder (normally gulp) before adding the files
  35. # to git
  36. #
  37. # Custom Message - ./scripts/deploy/build.sh -m "Custom message"
  38. #
  39. # This is the same behaviour as the default, except it will
  40. # also add a custom git commit message instead of the default
  41. #
  42. # Note: all these flags are combinable, example below with every flag
  43. #
  44. # ./scripts/deploy/build.sh -b -m "Custom message" -gsl
  45. #
  46. # Note: If dotfiles are installed, you can also run a command instead of
  47. #
  48. # ./scripts/deploy/build.sh
  49. #
  50. # which is as follows:
  51. #
  52. # t deploy build
  53. #
  54. #
  55. ################################################################################
  56.  
  57. message="Committing changes"
  58. build="false"
  59. gitlab="true"
  60. staging="true"
  61. live="false"
  62. colour="\e[32m" # Green
  63. reset="\e[0m"
  64.  
  65. # Add remotes if they don't already exist
  66. source "scripts/deploy/_config.sh"
  67.  
  68. gitlaburl="($(git config remote.origin.url))"
  69. stagingurl="($(git config remote.staging.url))"
  70. liveurl="($(git config remote.live.url))"
  71.  
  72. # Get all the flags for the script,
  73. # loop through them and then do override the necessary variables
  74. while getopts "bm:gslc:" flag; do
  75. case "${flag}" in
  76. b) build="true" ;;
  77. m) message="${OPTARG}" ;;
  78. g) gitlab="false" ;;
  79. s) staging="false" ;;
  80. l) live="true" ;;
  81. c) colour="${OPTARG}" ;;
  82. *) error "Unexpected option ${flag}" ;;
  83. esac
  84. done
  85.  
  86. #---------------------------------------
  87. # Run gulp build
  88. #---------------------------------------
  89. if [ ! -z "$build" -a "$build" != "false" ]; then
  90. gulp build
  91. fi
  92.  
  93. #---------------------------------------
  94. # Add the files to git
  95. #---------------------------------------
  96. git add .
  97.  
  98. #---------------------------------------
  99. # Commit the files to git
  100. #---------------------------------------
  101. git commit -m "$message"
  102.  
  103. #-------------------------------------------------------------------------------
  104. # Deploy the changes to gitlab, staging and live depending on flags
  105. #
  106. # Defaults to all
  107. #-------------------------------------------------------------------------------
  108.  
  109. #---------------------------------------
  110. # GitLab
  111. #---------------------------------------
  112. if [ ! -z "$gitlab" -a "$gitlab" != "false" ]; then
  113. echo -en "${colour}Deploying to origin ${gitlaburl}...${reset}\n"
  114. git push origin HEAD
  115. echo
  116. fi
  117.  
  118. #---------------------------------------
  119. # Staging
  120. #---------------------------------------
  121. if [ ! -z "$staging" -a "$staging" != "false" ]; then
  122. echo -en "${colour}Deploying to staging ${stagingurl}...${reset}\n"
  123. git push staging HEAD
  124. fi
  125.  
  126. #---------------------------------------
  127. # Live
  128. #---------------------------------------
  129. if [ ! -z "$live" -a "$live" != "false" ]; then
  130. echo -en "${colour}Deploying to live ${liveurl}...${reset}\n"
  131. git push live HEAD
  132. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement