tools/semver_git_tag with --no-verify
This commit is contained in:
+82
-80
@@ -8,8 +8,7 @@ NOVERIFY=false
|
|||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo 'usage: < --major | -M | --minor | -m | --patch | -p > [--no-verify]'
|
echo "$(dirname $0)/$(basename $0) < --major|-M | --minor|-m | --patch|-p > [--no-verify]"
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_options {
|
function parse_options {
|
||||||
@@ -32,13 +31,11 @@ function parse_options {
|
|||||||
NOVERIFY=true
|
NOVERIFY=true
|
||||||
;;
|
;;
|
||||||
--help | -h)
|
--help | -h)
|
||||||
usage
|
usage && exit 0
|
||||||
exit 0
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown option: $1"
|
echo "Unknown option: $1"
|
||||||
usage
|
usage && exit 2
|
||||||
exit 2
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -46,80 +43,7 @@ function parse_options {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function extra_options {
|
function ask_for_tag {
|
||||||
extra=""
|
|
||||||
[[ $NOVERIFY == true ]] && extra="$extra --no-verify"
|
|
||||||
echo "$extra"
|
|
||||||
}
|
|
||||||
|
|
||||||
function assert_git_covered {
|
|
||||||
REPOSITORY=$(git config --get remote.origin.url)
|
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
echo 'no remote origin defined yet, please perform: git remote add'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function assert_git_clean {
|
|
||||||
changed=$(git status -s | wc -l)
|
|
||||||
if [[ ! $changed -eq 0 ]]; then
|
|
||||||
echo "git commit required, please do so before processing further"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
############# main
|
|
||||||
|
|
||||||
parse_options $*
|
|
||||||
|
|
||||||
assert_git_covered
|
|
||||||
assert_git_clean
|
|
||||||
|
|
||||||
git remote update
|
|
||||||
pulled_needed=$(git status -s -u no | wc -l)
|
|
||||||
if [[ ! $changed -eq 0 ]]; then
|
|
||||||
echo "git pull required, please do so before processing further"
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
|
||||||
# check if push needed before tagging
|
|
||||||
push_needed=$(git rev-list --branches --not --remotes | wc -l)
|
|
||||||
if [[ $push_needed -ne 0 ]]; then
|
|
||||||
echo 'git push needed'
|
|
||||||
git push --set-upstream origin "$current_branch" $(extra_options)
|
|
||||||
echo 'git push done'
|
|
||||||
echo '-------------'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check latest tagged version
|
|
||||||
LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null)
|
|
||||||
if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then
|
|
||||||
echo "LAST=${LAST_TAG}"
|
|
||||||
VERSION=$(git describe --tags $LAST_TAG)
|
|
||||||
else
|
|
||||||
echo 'not yet tagged!'
|
|
||||||
VERSION=0.0.0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# split into array
|
|
||||||
VERSION_BITS=(${VERSION//./ })
|
|
||||||
MAJOR=${VERSION_BITS[0]:=0}
|
|
||||||
MINOR=${VERSION_BITS[1]:=0}
|
|
||||||
PATCH=${VERSION_BITS[2]:=0}
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if [[ -z $COMMAND ]]; then
|
|
||||||
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? "
|
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? "
|
||||||
read -rn1 input
|
read -rn1 input
|
||||||
echo
|
echo
|
||||||
@@ -138,6 +62,84 @@ if [[ -z $COMMAND ]]; then
|
|||||||
exit 3
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
echo COMMAND=$COMMAND && exit 5
|
||||||
|
}
|
||||||
|
|
||||||
|
function extra_options {
|
||||||
|
extra=""
|
||||||
|
[[ $NOVERIFY == true ]] && extra="$extra --no-verify"
|
||||||
|
echo "$extra"
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_git_covered {
|
||||||
|
REPOSITORY=$(git config --get remote.origin.url)
|
||||||
|
if [[ "$?" -ne 0 ]]; then
|
||||||
|
echo 'no remote origin defined yet, please perform: git remote add'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_git_clean {
|
||||||
|
[[ -n $(git status -s) ]] &&
|
||||||
|
echo >&2 "git commit required, please do so before processing further" &&
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_git_pull {
|
||||||
|
git remote update
|
||||||
|
[[ -n $(git status -su no) ]] &&
|
||||||
|
echo >&2 "git pull required, please do so before processing further" &&
|
||||||
|
exit 3
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_push {
|
||||||
|
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
push_needed=$(git rev-list --branches --not --remotes | wc -l)
|
||||||
|
if [[ $push_needed -ne 0 ]]; then
|
||||||
|
echo 'git push needed'
|
||||||
|
git push --set-upstream origin "$current_branch" $(extra_options)
|
||||||
|
echo 'git push done'
|
||||||
|
echo '-------------'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function latest_tagged_version {
|
||||||
|
LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null)
|
||||||
|
if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then
|
||||||
|
echo "LAST=${LAST_TAG}"
|
||||||
|
VERSION=$(git describe --tags $LAST_TAG)
|
||||||
|
else
|
||||||
|
echo 'not yet tagged!'
|
||||||
|
VERSION=0.0.0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
############# main
|
||||||
|
|
||||||
|
assert_git_covered
|
||||||
|
assert_git_clean
|
||||||
|
assert_git_pull
|
||||||
|
|
||||||
|
parse_options $*
|
||||||
|
[[ -z $COMMAND ]] && ask_for_tag
|
||||||
|
git_push
|
||||||
|
latest_tagged_version
|
||||||
|
|
||||||
|
# split into array
|
||||||
|
VERSION_BITS=(${VERSION//./ })
|
||||||
|
MAJOR=${VERSION_BITS[0]:=0}
|
||||||
|
MINOR=${VERSION_BITS[1]:=0}
|
||||||
|
PATCH=${VERSION_BITS[2]:=0}
|
||||||
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
case $COMMAND in
|
case $COMMAND in
|
||||||
|
|||||||
Reference in New Issue
Block a user