Last active
January 20, 2017 20:24
-
-
Save zouppen/c67bcaff1db6c85a8786873d3fde10df to your computer and use it in GitHub Desktop.
Git autodeployment script
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/sh -eu | |
# | |
# Idea taken from http://stackoverflow.com/a/38994123/514723 | |
# Fetching new commits | |
cd /PATH/TO/REPO | |
git fetch | |
# Save the local changes, keep a reference to them | |
stashed_commit=`git stash create` | |
# Reset working tree to the sandbox branch on server | |
git reset --hard origin/sandbox | |
# If there were local changes, then restore them | |
if test -n "$stashed_commit"; then | |
if ! git stash apply "$stashed_commit"; then | |
# Autodeployment failed. Reverting. | |
git reset --hard "$stashed_commit" | |
git reset HEAD^ | |
echo 'Autodeployment FAILED! Local changes on sandbox server? You need to resolve manually.' | |
exit 1 | |
fi | |
fi | |
# Add here some other tasks to do after deployment, such as compiling locales etc. | |
echo Successfully deployed to https://sandbox.example.com |
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/sh -eu | |
# | |
# Deploy the stuff into sandbox if the branch in question is "sandbox" | |
# Modeled after http://stackoverflow.com/a/13057643/514723 | |
for refname in "$@"; do | |
branch=`git rev-parse --symbolic --abbrev-ref "$refname"` | |
if test sandbox = "$branch"; then | |
ssh -T YOUR_SANDBOX_SERVER | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment