Browse Source

package.json aware

master 0.9.0
pvincent 4 years ago
parent
commit
13aa27b928
  1. 66
      tools/semver_git_tag

66
tools/semver_git_tag

@ -33,22 +33,38 @@ 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'
echo 'no remote origin defined yet, please perform: `git remote add`'
exit -1
fi
# check if dirty status
changed=$(git status -s | wc -l)
if [[ ! $changed -eq 0 ]]; then
echo "git commit required, please do so before processing further"
exit 2
fi
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
# 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
git push --set-upstream origin master
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 ]]; then
if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then
echo "LAST=${LAST_TAG}"
VERSION=`git describe --tags $LAST_TAG`
else
echo 'not yet tagged!'
@ -56,17 +72,17 @@ else
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
#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]}
MAJOR=${VERSION_BITS[0]:=0}
MINOR=${VERSION_BITS[1]:=0}
PATCH=${VERSION_BITS[2]:=0}
REPO_NAME=`basename $REPOSITORY`
REPO_NAME=${REPO_NAME%.git}
@ -104,9 +120,35 @@ case $COMMAND in
;;
esac
set -e # EXITS when any error occurs
TAG="$MAJOR.$MINOR.$PATCH"
# check if tag exists already!
if [[ -n $(git tag -l $TAG) ]];then
echo "WARNING: ${TAG} already exists!"
exit 4
fi
# check whether NPM project detected, containing package.json on root project
GIT_ROOT_FOLDER=$(dirname $(git rev-parse --git-dir))
if [[ -f "${GIT_ROOT_FOLDER}/package.json" ]]; then
echo "package.json detected, version replaced with new tag <${TAG}>"
if ! command -v jq &> /dev/null
then
echo 'command <jq> not found, hint: `sudo apt install jq`'
exit 5
fi
tmp=$(mktemp)
jq '.version = $TAG' --arg TAG $TAG "${GIT_ROOT_FOLDER}/package.json" > "$tmp" && mv "$tmp" "${GIT_ROOT_FOLDER}/package.json"
git commit -am "tagged as ${TAG}"
git push
fi
set -e # EXITS when any error occurs
echo "tagging as $TAG ..."
git tag $TAG
git push origin master --tags

Loading…
Cancel
Save