Skip to content

Instantly share code, notes, and snippets.

@dblencowe
Created March 28, 2016 12:07
Show Gist options
  • Select an option

  • Save dblencowe/c3f18b8f3bb908a0d8f0 to your computer and use it in GitHub Desktop.

Select an option

Save dblencowe/c3f18b8f3bb908a0d8f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
###
# Check that we have the correct working directory.
###
if [ ! -d "web" ]
then
echo "Please run this script from the main web directory."
exit
fi
###
# Stop if there are uncommitted changes
###
if [[ -n $(git status -s) ]]
then
echo "Please review and commit your changes before continuing."
exit
fi
###
# Create a temporary branch
###
exists=`git show-ref refs/heads/deploy`
if [ -n "$exists" ]
then
git branch -D deploy
fi
git checkout --orphan deploy
git rm --cached -r .
###
# Create a temporary wp-content directory to match the original WP structure
# Then move the items we want in our repo over
###
mkdir wp-content
cp web/app/{themes,plugins} ./wp-content/
###
# Commit new structure into git, and push to remote.
###
git add wp-content
git commit -am "Deploy build from: $(git log -1 HEAD --pretty=format:%s)$(git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/")"
echo "Pushing to repository..."
git push -u origin deploy --force
git checkout master --force
rm -rf wp-content
git branch -D deploy
echo "Successfully deployed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment