Skip to content

Instantly share code, notes, and snippets.

@frecklebit
Last active August 27, 2021 20:42
Show Gist options
  • Save frecklebit/df3ef6cdd59516762b8132fb50494769 to your computer and use it in GitHub Desktop.
Save frecklebit/df3ef6cdd59516762b8132fb50494769 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Deploys current branch to Zoro team environment
# e.g. deploy-qa browse-d
deploy-qa() {
# Make sure current directory is clean
if [[ -n "$(git status --untracked-files=no --porcelain)" ]]; then
echo "Please commit your work before deploying to QA"
return 1
fi
# Store arguments to variables
env=$1
if [[ -z "$env" ]]; then
read -p "Which team environment are you deploying to? " env
fi
# Update the environment variable
env="env/$env"
# Determine paths
current_path=$(pwd)
zoro_path="$WORKING_DIR/zoro"
if [ "$current_path" != "$zoro_path" ]; then
echo "Changing to Zoro's working directory.."
cd $zoro_path
fi
# Get the current git branch
branch=$(git_current_branch)
# Make sure branch isn't master or development
if [[ $branch =~ ^(master|develop|development)$ ]]; then
read -p "Which branch would you like to deploy to $env? " branch
fi
echo "Deploying branch '$branch' to environment '$env'..."
# Checkout environment branch
git checkout $env
# Hard reset branch
git reset --hard $branch
# Push code to origin
git push origin $env --force
# Switch back to working branch
git checkout $branch
echo "Done!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment