Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
meltmedia/meltconsole / melt-deploy.sh
Size: Mime:
#!/bin/bash

# Parse arguments with `=`
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
for i in "$@"
do
    case $i in
        --env=*)
        ENVIRONMENT="${i#*=}"
        shift # past argument=value
        ;;
        --branch=*)
        BRANCH="${i#*=}"
        shift # past argument=value
        ;;
        *)
            # unknown option
        ;;
    esac
done

# Set message variables
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
PROMPT_MESSAGE="Deploy code to ${BRANCH}-build branch on ${ENVIRONMENT} environment. Is this correct? [n/Y]"
BUILD_BRANCH=${BRANCH}-build

# Exit if no environment was detected
if [ -z "${ENVIRONMENT}" ] || [ -z "${BRANCH}" ]; then
    echo "Value for --env or --branch missing."
    exit 1
fi

# Prompt to ensure user is chose the right environment and branch
while true; do
    read -p "$PROMPT_MESSAGE" yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) break;; # defaults to yes
    esac
done

# Determine whether or not to use Acquia BLT to deploy artifact.
USE_BLT=false
while true; do
    read -p "Would you like to deploy using BLT artifact? Do this if using Acquia. (y/N)" yn
    case $yn in
        [Yy]* )
        USE_BLT=true
        break;;
        [Nn]* ) break;;
        * ) break;; # defaults to yes
    esac
done

if [ "${USE_BLT}" = true ]; then
    echo "Deploying code to ${BRANCH}-build using BLT, this will take a while..."
    blt artifact:deploy --commit-msg "${COMMIT_MESSAGE}" --branch "${BRANCH}-build" --no-interaction
    echo "You're the most patient person on the planet!! Ok, updating ${ENVIRONMENT^^} environment with latest code..."
else
        CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
        git checkout -B ${BUILD_BRANCH}
        git reset --hard ${CURRENT_BRANCH_NAME}
        git push -f origin ${BUILD_BRANCH}
        git checkout ${CURRENT_BRANCH_NAME}
fi

# Pull in the latest changes from git
drush @melt.${ENVIRONMENT} ssh "git checkout -B ${BUILD_BRANCH} && git reset --hard origin/${BUILD_BRANCH}"

# Remove the `vendor` directory and re-install dependencies just in case a new module was added.
if [ "${USE_BLT}" != true ]; then
    echo "Re-installing dependencies..."
    drush @melt.${ENVIRONMENT} ssh "rm -rf vendor && lando composer install && lando drush cr"
fi

echo "Deploy complete!"