pvincent
5 years ago
2 changed files with 105 additions and 0 deletions
@ -0,0 +1,104 @@ |
|||
#!/bin/bash |
|||
|
|||
function usage { |
|||
echo 'usage: --major | -M | --minor | -m | --patch | -p' |
|||
exit -1 |
|||
} |
|||
|
|||
function setCommand { |
|||
#arg1 input, #arg2 return value |
|||
declare -n ret=$2 |
|||
|
|||
case $1 in |
|||
-M|--major) |
|||
ret='major' ;; |
|||
-m|--minor) |
|||
ret='minor' ;; |
|||
-p|--patch) |
|||
ret='patch' ;; |
|||
*) # unknown option |
|||
echo |
|||
echo 'unknown option, quitting' |
|||
exit -1 |
|||
;; |
|||
esac |
|||
} |
|||
|
|||
|
|||
############# main |
|||
|
|||
# check more than one argument |
|||
if [[ $# -gt 1 ]];then usage ;fi |
|||
|
|||
# check git covered |
|||
REPOSITORY=`git config --get remote.origin.url` |
|||
if [[ $? -ne 0 ]]; then |
|||
echo 'folder not covered by git' |
|||
exit -1 |
|||
fi |
|||
|
|||
# check latest tagged version |
|||
LAST_TAG=`git rev-list --tags --max-count=1 2>/dev/null` |
|||
if [[ $? -eq 0 ]]; then |
|||
VERSION=`git describe --tags $LAST_TAG` |
|||
else |
|||
echo 'not yet tagged!' |
|||
VERSION=0.0.0 |
|||
fi |
|||
|
|||
# check belongs to git.artcode.re |
|||
if [[ ! ("$REPOSITORY" =~ ^git@artcode.re+) ]]; then |
|||
echo "$REPOSITORY => $VERSION" |
|||
echo 'folder not covered by git.artcode.re, read-only' |
|||
exit -1 |
|||
fi |
|||
|
|||
# split into array |
|||
VERSION_BITS=(${VERSION//./ }) |
|||
MAJOR=${VERSION_BITS[0]} |
|||
MINOR=${VERSION_BITS[1]} |
|||
PATCH=${VERSION_BITS[2]} |
|||
|
|||
REPO_NAME=`basename $REPOSITORY` |
|||
REPO_NAME=${REPO_NAME%.git} |
|||
if [[ $VERSION != '0.0.0' ]];then |
|||
echo "LATEST VERSION of '$REPO_NAME' is '$MAJOR.$MINOR.$PATCH'" |
|||
COMMIT_ID=`git log --format="%H" -n 1` |
|||
if [[ $COMMIT_ID == $LAST_TAG ]]; then |
|||
echo "cannot tag twice the same commit id : $LAST_TAG" |
|||
exit -1 |
|||
fi |
|||
fi |
|||
|
|||
COMMAND="${1:-ask}" |
|||
if [[ $COMMAND == 'ask' ]];then |
|||
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? " |
|||
read -n1 input |
|||
echo |
|||
COMMAND="-$input" |
|||
fi |
|||
|
|||
setCommand $COMMAND COMMAND |
|||
|
|||
case $COMMAND in |
|||
"major") |
|||
let "MAJOR++" |
|||
let "MINOR=0" |
|||
let "PATCH=0" |
|||
;; |
|||
"minor") |
|||
let "MINOR++" |
|||
let "PATCH=0" |
|||
;; |
|||
"patch") |
|||
let "PATCH++" |
|||
;; |
|||
esac |
|||
|
|||
set -e # EXITS when any error occurs |
|||
|
|||
TAG="$MAJOR.$MINOR.$PATCH" |
|||
echo "tagging as $TAG ..." |
|||
git tag $TAG |
|||
git push origin master --tags |
|||
echo done |
Write
Preview
Loading…
Cancel
Save
Reference in new issue