Skip to content

Instantly share code, notes, and snippets.

@whitethunder
Last active December 11, 2015 00:08
Show Gist options
  • Save whitethunder/4514239 to your computer and use it in GitHub Desktop.
Save whitethunder/4514239 to your computer and use it in GitHub Desktop.
#!/bin/bash
function today {
echo `date +"%Y%m%d"`
}
function last_tag_today {
output=`git tag`
local last_today=''
for LINE in ${output} ; do
if [[ $LINE =~ $(today) ]] ; then
last_today=${LINE}
fi
done
echo $last_today
}
function new_tag_name {
git fetch --tags
last_today=$(last_tag_today)
if [ "$last_today" ] ; then
tag_date=$((${last_today/#release-/}+1))
echo 'release-'$tag_date
else
echo 'release-'$(today)'01'
fi
}
function tag_master {
new_tag=$(new_tag_name)
echo 'Creating '$new_tag'...'
git tag -a $new_tag -m 'Creating '$new_tag
echo 'Pushing tag...'
git push origin $new_tag
echo 'Tag '$new_tag' created and pushed.'
}
function destination {
case "$1" in
'1')
echo 'i cap staging deploy -s revision='
;;
'2')
echo 'i cap staging deploy:migrations -s revision='
;;
'3')
echo 'cap staging deploy -s revision='
;;
'4')
echo 'cap staging deploy:migrations -s revision='
;;
'5')
echo 'i cap production deploy -s revision='
;;
'6')
echo 'i cap production deploy:migrations -s revision='
;;
'7')
echo 'cap production deploy -s revision='
;;
'8')
echo 'cap production deploy:migrations -s revision='
;;
esac
}
function deploy {
echo 'Deploy to:'
echo '1. Goldstar staging'
echo '2. Goldstar staging with migrations'
echo '3. Fulfillment staging'
echo '4. Fulfillment staging with migrations'
echo '5. Goldstar production'
echo '6. Goldstar production with migrations'
echo '7. Fulfillment production'
echo '8. Fulfillment production with migrations'
echo -n '-> '
read dest
deploy_dest=$(destination $dest)
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
if [ -z "$new_tag" ] ; then
new_tag=$branch_name
fi
echo -n 'Revision to deploy (leave blank for '$new_tag'): '
read dest
if [ -z "$dest" ] ; then
eval $deploy_dest$new_tag
else
eval $deploy_dest$dest
fi
}
echo 'What do you want to do?'
echo '1. Deploy something'
echo '2. Tag master'
echo '3. OMG BOTH'
echo -n '-> '
read dest
case "$dest" in
'1')
deploy
;;
'2')
tag_master
;;
'3')
tag_master
deploy
;;
*)
echo 'THEN GET BACK TO WORK'
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment