Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -o nounset -o pipefail -o errexit
- cd "$(dirname "$0")/../.."
- ################################################################################
- # Master one liner interaction with deploying files
- #
- # Build the assets, then add and commit the files to git
- # Then uploads the current branch to the live site, staging site and to GitLab
- #
- # USAGE:
- # Default usage - ./scripts/deploy/build.sh
- #
- # This will add and commit files to git with the message
- # Committing changes, and then push the changes to gitlab and
- # staging
- #
- # Remove push - ./scripts/deploy/build.sh -g -s
- #
- # There are two flags with which you can stop pushing to
- # their respective remotes
- #
- # -g means don't push to gitlab
- # -s means don't push to staging
- #
- # Deploy to live - ./scripts/deploy/build.sh -l
- #
- # This is the same behaviour as the default, except it will
- # also push to the live site
- #
- # Build assets - ./scripts/deploy/build.sh -b
- #
- # This is the same behaviour as the default, except it will
- # also run the builder (normally gulp) before adding the files
- # to git
- #
- # Custom Message - ./scripts/deploy/build.sh -m "Custom message"
- #
- # This is the same behaviour as the default, except it will
- # also add a custom git commit message instead of the default
- #
- # Note: all these flags are combinable, example below with every flag
- #
- # ./scripts/deploy/build.sh -b -m "Custom message" -gsl
- #
- # Note: If dotfiles are installed, you can also run a command instead of
- #
- # ./scripts/deploy/build.sh
- #
- # which is as follows:
- #
- # t deploy build
- #
- #
- ################################################################################
- message="Committing changes"
- build="false"
- gitlab="true"
- staging="true"
- live="false"
- colour="\e[32m" # Green
- reset="\e[0m"
- # Add remotes if they don't already exist
- source "scripts/deploy/_config.sh"
- gitlaburl="($(git config remote.origin.url))"
- stagingurl="($(git config remote.staging.url))"
- liveurl="($(git config remote.live.url))"
- # Get all the flags for the script,
- # loop through them and then do override the necessary variables
- while getopts "bm:gslc:" flag; do
- case "${flag}" in
- b) build="true" ;;
- m) message="${OPTARG}" ;;
- g) gitlab="false" ;;
- s) staging="false" ;;
- l) live="true" ;;
- c) colour="${OPTARG}" ;;
- *) error "Unexpected option ${flag}" ;;
- esac
- done
- #---------------------------------------
- # Run gulp build
- #---------------------------------------
- if [ ! -z "$build" -a "$build" != "false" ]; then
- gulp build
- fi
- #---------------------------------------
- # Add the files to git
- #---------------------------------------
- git add .
- #---------------------------------------
- # Commit the files to git
- #---------------------------------------
- git commit -m "$message"
- #-------------------------------------------------------------------------------
- # Deploy the changes to gitlab, staging and live depending on flags
- #
- # Defaults to all
- #-------------------------------------------------------------------------------
- #---------------------------------------
- # GitLab
- #---------------------------------------
- if [ ! -z "$gitlab" -a "$gitlab" != "false" ]; then
- echo -en "${colour}Deploying to origin ${gitlaburl}...${reset}\n"
- git push origin HEAD
- echo
- fi
- #---------------------------------------
- # Staging
- #---------------------------------------
- if [ ! -z "$staging" -a "$staging" != "false" ]; then
- echo -en "${colour}Deploying to staging ${stagingurl}...${reset}\n"
- git push staging HEAD
- fi
- #---------------------------------------
- # Live
- #---------------------------------------
- if [ ! -z "$live" -a "$live" != "false" ]; then
- echo -en "${colour}Deploying to live ${liveurl}...${reset}\n"
- git push live HEAD
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement