Skip to content

Instantly share code, notes, and snippets.

@lucasmotta
Last active December 11, 2015 17:39
Show Gist options
  • Save lucasmotta/4636472 to your computer and use it in GitHub Desktop.
Save lucasmotta/4636472 to your computer and use it in GitHub Desktop.
Post-commit deploy to server using Dandelion: https://github.com/scttnlsn/dandelion
#!/bin/sh
#
# Script to deploy to FTP after a commit using dandelion
# This hook will look for any of those tags on your commit message: #deploy, #stage, #production and #dev
# If found, it's going to deploy to the given server.
#
# The following commit message would deploy to the Production and Stage servers:
# git commit -m "Fixed bugs on the header #production #stage"
#
# But you need to have the dandelion config file with the same name of the tag.
# On the previous example, you would need to have the "stage.yml" and "production.yml" configured on your repo.
message=$(git log -1 --all --pretty=format:"\"%s\" - %cN")
tags=("#deploy" "#stage" "#production" "#dev")
deployed=false
for tag in "${tags[@]}"
do
if [[ "$message" = *"$tag"* ]]; then
deployed=true
if [[ "$tag" = "#deploy" ]]
then
echo "\033[0;37m╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳\033[0m"
echo "\033[1;34mDeploying...\033[0m"
dandelion deploy -f
echo "\033[1;34mCompleted.\033[0m"
elif [ -f "${tag:1}.yml" ]
then
echo "\033[0;37m╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳\033[0m"
echo "\033[1;34mDeploying to\033[0m \033[1;33m${tag:1}...\033[0m"
dandelion --config=${tag:1}.yml deploy -f
echo "\033[1;34mCompleted.\033[0m"
else
echo "\033[0;37m╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳\033[0m"
echo "\033[1;31mError: The file ${tag:1}.yml is missing.\033[0m"
fi
fi
done
if $deployed; then
echo "\033[0;37m╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳╳\033[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment