Browse Source

tools/semver_git_tag with --no-verify

main
pvincent 5 days ago
parent
commit
736f90402d
  1. 118
      tools/semver_git_tag

118
tools/semver_git_tag

@ -8,8 +8,7 @@ NOVERIFY=false
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo 'usage: < --major | -M | --minor | -m | --patch | -p > [--no-verify]'
exit 1
echo "$(dirname $0)/$(basename $0) < --major|-M | --minor|-m | --patch|-p > [--no-verify]"
} }
function parse_options { function parse_options {
@ -32,13 +31,11 @@ function parse_options {
NOVERIFY=true NOVERIFY=true
;; ;;
--help | -h) --help | -h)
usage
exit 0
usage && exit 0
;; ;;
*) *)
echo "Unknown option: $1" echo "Unknown option: $1"
usage
exit 2
usage && exit 2
;; ;;
esac esac
@ -46,6 +43,28 @@ function parse_options {
done done
} }
function ask_for_tag {
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? "
read -rn1 input
echo
case "$input" in
M)
COMMAND='major'
;;
m)
COMMAND='minor'
;;
p)
COMMAND='patch'
;;
*)
echo >&2 "Unknown option: $input"
exit 3
;;
esac
echo COMMAND=$COMMAND && exit 5
}
function extra_options { function extra_options {
extra="" extra=""
[[ $NOVERIFY == true ]] && extra="$extra --no-verify" [[ $NOVERIFY == true ]] && extra="$extra --no-verify"
@ -61,46 +80,50 @@ function assert_git_covered {
} }
function assert_git_clean { 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"
[[ -n $(git status -s) ]] &&
echo >&2 "git commit required, please do so before processing further" &&
exit 2 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 fi
} }
############# main
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
}
parse_options $*
############# main
assert_git_covered assert_git_covered
assert_git_clean assert_git_clean
assert_git_pull
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
parse_options $*
[[ -z $COMMAND ]] && ask_for_tag
git_push
latest_tagged_version
# split into array # split into array
VERSION_BITS=(${VERSION//./ }) VERSION_BITS=(${VERSION//./ })
@ -119,27 +142,6 @@ if [[ $VERSION != '0.0.0' ]]; then
fi fi
fi fi
if [[ -z $COMMAND ]]; then
echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? "
read -rn1 input
echo
case "$input" in
M)
COMMAND='major'
;;
m)
COMMAND='minor'
;;
p)
COMMAND='patch'
;;
*)
echo >&2 "Unknown option: $input"
exit 3
;;
esac
fi
case $COMMAND in case $COMMAND in
"major") "major")
let "MAJOR++" let "MAJOR++"

Loading…
Cancel
Save