Last active
January 1, 2016 01:19
-
-
Save jclausen/8072280 to your computer and use it in GitHub Desktop.
Basic Shell Script to Deploy Git Repository Using Middleman Local Repo
Accepts -branch parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Staging Server Deployment script for Cygwin | |
branch=${parameter:-'HEAD'} | |
repo_dir="/srv/local-repos/myrepo.git" | |
dest_dir="/home/my-deployment-directory/wwwroot" | |
server_name="My Staging Server" | |
echo -e "Pulling latest repository updates from branch ${branch}...\n" | |
# Change to staging directory and update | |
# pull changes | |
PULLED=`cd $repo_dir && git pull` | |
echo $PULLED | |
echo -e "\nLocal Repository Sucessfully Updated.\n" | |
echo -e "\nApplying Changes to $server_name\n" | |
# Stash any local changes so pull operations can run | |
echo -e "Stashing Local Changes...\n" | |
stashed=`cd $dest_dir && git stash save 'predeployment stash'` | |
echo $stashed | |
echo -e "\nStashed!\n" | |
echo -e "\nMerging Updated Files in to $server_name site...\n" | |
merged=`cd $dest_dir && git pull origin ${branch}` | |
echo $merged | |
echo -e "\nMerged!\n" | |
echo -e "\nReapplying stashed changes...\n" | |
reapply=`cd $dest_dir && git stash apply stash@{0}` | |
echo reapply | |
echo -e "\nStashed changes reapplied!\n" | |
# Clean Up | |
echo -e "Cleaning stashes...\n" | |
cleared=`cd $dest_dir && git stash clear` | |
echo $cleared | |
echo -e "\nFinished\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment