semver_git_tag verify once
This commit is contained in:
+104
-104
@@ -8,110 +8,110 @@ NOVERIFY=false
|
|||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo "$(dirname $0)/$(basename $0) < --major|-M | --minor|-m | --patch|-p > [--no-verify]"
|
echo "$(dirname $0)/$(basename $0) < --major|-M | --minor|-m | --patch|-p > [--no-verify]"
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_options {
|
function parse_options {
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--major | -M)
|
--major | -M)
|
||||||
shift 1
|
shift 1
|
||||||
COMMAND='major'
|
COMMAND='major'
|
||||||
;;
|
;;
|
||||||
--minor | -m)
|
--minor | -m)
|
||||||
shift 1
|
shift 1
|
||||||
COMMAND='minor'
|
COMMAND='minor'
|
||||||
;;
|
;;
|
||||||
--patch | -p)
|
--patch | -p)
|
||||||
shift 1
|
shift 1
|
||||||
COMMAND='patch'
|
COMMAND='patch'
|
||||||
;;
|
;;
|
||||||
--no-verify)
|
--no-verify)
|
||||||
shift 1
|
shift 1
|
||||||
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
|
||||||
|
|
||||||
shift 1 # Move to the next argument
|
shift 1 # Move to the next argument
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask_for_tag {
|
function ask_for_tag {
|
||||||
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
|
||||||
case "$input" in
|
case "$input" in
|
||||||
M)
|
M)
|
||||||
COMMAND='major'
|
COMMAND='major'
|
||||||
;;
|
;;
|
||||||
m)
|
m)
|
||||||
COMMAND='minor'
|
COMMAND='minor'
|
||||||
;;
|
;;
|
||||||
p)
|
p)
|
||||||
COMMAND='patch'
|
COMMAND='patch'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo >&2 "Unknown option: $input"
|
echo >&2 "Unknown option: $input"
|
||||||
exit 3
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function extra_options {
|
function extra_options {
|
||||||
extra=""
|
extra=""
|
||||||
[[ $NOVERIFY == true ]] && extra="$extra --no-verify"
|
[[ $NOVERIFY == true ]] && extra="$extra --no-verify"
|
||||||
echo "$extra"
|
echo "$extra"
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_git_covered {
|
function assert_git_covered {
|
||||||
REPOSITORY=$(git config --get remote.origin.url)
|
REPOSITORY=$(git config --get remote.origin.url)
|
||||||
if [[ "$?" -ne 0 ]]; then
|
if [[ "$?" -ne 0 ]]; then
|
||||||
echo 'no remote origin defined yet, please perform: git remote add'
|
echo 'no remote origin defined yet, please perform: git remote add'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_git_clean {
|
function assert_git_clean {
|
||||||
[[ -n $(git status -s) ]] &&
|
[[ -n $(git status -s) ]] &&
|
||||||
echo >&2 "git commit required, please do so before processing further" &&
|
echo >&2 "git commit required, please do so before processing further" &&
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_git_pull {
|
function assert_git_pull {
|
||||||
git remote update
|
git remote update
|
||||||
[[ -n $(git status -su no) ]] &&
|
[[ -n $(git status -su no) ]] &&
|
||||||
echo >&2 "git pull required, please do so before processing further" &&
|
echo >&2 "git pull required, please do so before processing further" &&
|
||||||
exit 3
|
exit 3
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_push {
|
function git_push {
|
||||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
push_needed=$(git rev-list --branches --not --remotes | wc -l)
|
push_needed=$(git rev-list --branches --not --remotes | wc -l)
|
||||||
if [[ $push_needed -ne 0 ]]; then
|
if [[ $push_needed -ne 0 ]]; then
|
||||||
echo 'git push needed'
|
echo 'git push needed'
|
||||||
git push --set-upstream origin "$current_branch" $(extra_options)
|
git push --set-upstream origin "$current_branch" $(extra_options)
|
||||||
echo 'git push done'
|
echo 'git push done'
|
||||||
echo '-------------'
|
echo '-------------'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function latest_tagged_version {
|
function latest_tagged_version {
|
||||||
LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null)
|
LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null)
|
||||||
if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then
|
if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then
|
||||||
echo "LAST=${LAST_TAG}"
|
echo "LAST=${LAST_TAG}"
|
||||||
VERSION=$(git describe --tags $LAST_TAG)
|
VERSION=$(git describe --tags $LAST_TAG)
|
||||||
echo "current is: $VERSION"
|
echo "current is: $VERSION"
|
||||||
else
|
else
|
||||||
echo 'not yet tagged!'
|
echo 'not yet tagged!'
|
||||||
VERSION=0.0.0
|
VERSION=0.0.0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
############# main
|
############# main
|
||||||
@@ -134,27 +134,27 @@ PATCH=${VERSION_BITS[2]:=0}
|
|||||||
REPO_NAME=$(basename $REPOSITORY)
|
REPO_NAME=$(basename $REPOSITORY)
|
||||||
REPO_NAME=${REPO_NAME%.git}
|
REPO_NAME=${REPO_NAME%.git}
|
||||||
if [[ $VERSION != '0.0.0' ]]; then
|
if [[ $VERSION != '0.0.0' ]]; then
|
||||||
echo "LATEST VERSION of '$REPO_NAME' is '$MAJOR.$MINOR.$PATCH'"
|
echo "LATEST VERSION of '$REPO_NAME' is '$MAJOR.$MINOR.$PATCH'"
|
||||||
COMMIT_ID=$(git log --format="%H" -n 1)
|
COMMIT_ID=$(git log --format="%H" -n 1)
|
||||||
if [[ $COMMIT_ID == $LAST_TAG ]]; then
|
if [[ $COMMIT_ID == $LAST_TAG ]]; then
|
||||||
echo "cannot tag twice the same commit id : $LAST_TAG"
|
echo "cannot tag twice the same commit id : $LAST_TAG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $COMMAND in
|
case $COMMAND in
|
||||||
"major")
|
"major")
|
||||||
let "MAJOR++"
|
let "MAJOR++"
|
||||||
let "MINOR=0"
|
let "MINOR=0"
|
||||||
let "PATCH=0"
|
let "PATCH=0"
|
||||||
;;
|
;;
|
||||||
"minor")
|
"minor")
|
||||||
let "MINOR++"
|
let "MINOR++"
|
||||||
let "PATCH=0"
|
let "PATCH=0"
|
||||||
;;
|
;;
|
||||||
"patch")
|
"patch")
|
||||||
let "PATCH++"
|
let "PATCH++"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "show TAG"
|
echo "show TAG"
|
||||||
@@ -163,22 +163,22 @@ echo "new TAG $TAG"
|
|||||||
|
|
||||||
# check if tag exists already!
|
# check if tag exists already!
|
||||||
if [[ -n $(git tag -l $TAG) ]]; then
|
if [[ -n $(git tag -l $TAG) ]]; then
|
||||||
echo "WARNING: ${TAG} already exists!"
|
echo "WARNING: ${TAG} already exists!"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check whether NPM project detected, containing package.json on root project
|
# check whether NPM project detected, containing package.json on root project
|
||||||
GIT_ROOT_FOLDER=$(dirname $(git rev-parse --git-dir))
|
GIT_ROOT_FOLDER=$(dirname $(git rev-parse --git-dir))
|
||||||
if [[ -f "${GIT_ROOT_FOLDER}/package.json" ]]; then
|
if [[ -f "${GIT_ROOT_FOLDER}/package.json" ]]; then
|
||||||
|
|
||||||
echo "package.json detected, version replaced with new tag <${TAG}>"
|
echo "package.json detected, version replaced with new tag <${TAG}>"
|
||||||
if ! command -v yq &>/dev/null; then
|
if ! command -v yq &>/dev/null; then
|
||||||
echo 'command <yq> not found, hint: go and fetch latest release from https://github.com/mikefarah/yq'
|
echo 'command <yq> not found, hint: go and fetch latest release from https://github.com/mikefarah/yq'
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yq -i ".version=\"$TAG\"" "${GIT_ROOT_FOLDER}/package.json"
|
yq -i ".version=\"$TAG\"" "${GIT_ROOT_FOLDER}/package.json"
|
||||||
git add ${GIT_ROOT_FOLDER}/package.json
|
git add ${GIT_ROOT_FOLDER}/package.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $TAG >${GIT_ROOT_FOLDER}/.semver_git_tag
|
echo $TAG >${GIT_ROOT_FOLDER}/.semver_git_tag
|
||||||
@@ -186,5 +186,5 @@ git add ${GIT_ROOT_FOLDER}/.semver_git_tag
|
|||||||
echo "tagging as $TAG ..."
|
echo "tagging as $TAG ..."
|
||||||
git commit -am "tagged as ${TAG}"
|
git commit -am "tagged as ${TAG}"
|
||||||
git tag $TAG
|
git tag $TAG
|
||||||
git push origin "$current_branch" --tags $(extra_options)
|
git push origin --no-verify "$current_branch" --tags $(extra_options)
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|||||||
Reference in New Issue
Block a user