Skip to content

Instantly share code, notes, and snippets.

@ilpaijin
Created October 31, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpaijin/04778dbdea4438327ec85de8edffdd3f to your computer and use it in GitHub Desktop.
Save ilpaijin/04778dbdea4438327ec85de8edffdd3f to your computer and use it in GitHub Desktop.
#!/bin/bash
title=$(tput setaf 7)
flag=$(tput setaf 3)
info=$(tput setaf 7)
text=$(tput setaf 8)
outcome=$(tput setaf 2)
partial=$(tput setaf 3)
error=$(tput setaf 1)
bold=$(tput bold)
cl=$(tput sgr0)
function usage {
echo -e "\n${info} Command usage: ${cl}\n"
echo -e "${title}${bold} ONLY COMMIT${cl}"
echo -e "${outcome} deploy ${flag}-m${cl} ${info}\"my commit message\"${cl}\n";
echo -e "${title}${bold} VERSIONED${cl}"
echo -e "${outcome} deploy ${flag}--bugfix|--minor${cl} ${flag}-m${cl} ${info}\"my commit message\"${cl}";
exit 1
}
get_opts () {
rs='' && rc=0 # return string and return code
while [[ $# -gt 0 ]]; do
shift
[[ "$1" =~ -.* ]] && break || rs="$rs $1" && rc=$((rc + 1))
done
echo "$rs"
}
if [ $# -gt 3 ]; then
usage
fi
while test $# -gt 0; do
case "$1" in
-m)
if test $# -gt 2; then
usage
exit 1
fi
shift
MESSAGE=$1
;;
--bugfix)
eval VERSIONED="bugfix"
;;
--minor)
eval VERSIONED="minor"
;;
*)
usage
exit 1;
;;
esac
shift
done
VERSION=$(git fetch --tags && git describe --abbrev=0)
CURRENT=$(git describe --abbrev=0)
# echo -e "${text}current VERSION is: ${info}$VERSION${cl}"
# echo -e "${text}current MESSAGE is: ${info}$MESSAGE${cl}"
# echo -e "${text}current VERSIONED is: ${info}$VERSIONED${cl}"
#if is tagged deploy
if [ ! -z "$VERSIONED" ]; then
NEW_MINOR="$(( $(echo $CURRENT| cut -d'.' -f2) + 1))"
NEW_PATCH="$(( $(echo $CURRENT| cut -d'.' -f3| cut -d'-' -f1) + 1))"
NEW_MINOR_SUGGESTION="$(echo $CURRENT| cut -d'.' -f1).$NEW_MINOR.0"
NEW_PATCH_SUGGESTION="$(echo $CURRENT| cut -d'.' -f1 -f2).$NEW_PATCH"
echo -e "${text}current tag is: ${info}$CURRENT${cl}"
if [ $VERSIONED == "minor" ]; then
NEWVERSION="$NEW_MINOR_SUGGESTION"
else
NEWVERSION="$NEW_PATCH_SUGGESTION"
fi
echo "${text}new tag (${VERSIONED}) will be: ${cl}${NEWVERSION}"
fi
#repo name
read -p "${text}enter repo name (gitlab): " var
[ -z "${var}" ] && REPO='gitlab'
PULL="$(git pull ${REPO})"
if [ $? -eq 0 ]; then
echo -e "\n${info}pull from remote \n"
COMMIT=$(git add -A && git commit -m "${MESSAGE}" 2>&1)
if [ $? -eq 0 ]; then
echo -e "${info}commit: \n ${outcome}\n $COMMIT"
if [ ! -z "$VERSIONED" ]; then
ADDTAG=$(git tag -a $NEWVERSION -m "" 2>&1)
echo -e "\n${info}tag: ${outcome}$NEWVERSION $ADDTAG"
fi
DEPLOY=$(git push $REPO --follow-tags 2>&1)
if [ $? -eq 0 ]; then
echo -e "\n${info}deploy: \n ${outcome}\n $DEPLOY${cl}"
else
DELETETAG=$(git tag -d $(git describe --abbrev=0) 2>&1)
echo -e "${text}deleted last created tag: $DELETETAG"
echo -e "${text}commit error: \n ${error}\n $DEPLOY"
fi
else
echo -e "${text}commit error: \n ${error}\n $COMMIT"
fi
else
echo -e "${error}error while pulling latest from repo: \n $PULL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment