summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2018-07-16 12:52:25 -0400
committerziggys <ziggys@autistici.org>2018-07-16 12:52:25 -0400
commit7fc9058e7307e85c6dc93d7fc2410e96661dc73d (patch)
treea59b7056db62b9c401b0eb23e346dfa6e2ced5f1
parent5c60796fb92b1c4420297740e2517d702dcc9549 (diff)
downloadsnippets-7fc9058e7307e85c6dc93d7fc2410e96661dc73d.zip
snippets-7fc9058e7307e85c6dc93d7fc2410e96661dc73d.tar
Move bump-version
-rwxr-xr-xbump-version.sh176
1 files changed, 0 insertions, 176 deletions
diff --git a/bump-version.sh b/bump-version.sh
deleted file mode 100755
index 5ffb5d9..0000000
--- a/bump-version.sh
+++ /dev/null
@@ -1,176 +0,0 @@
-#!/bin/sh
-# -*- ENCODING: UTF-8 -*-
-# bump-version.sh - script name
-# a script to update version numbers in git projects
-# Author: ziggys
-# This piece of software is released to Public Domain
-
-# scriptinfo
-SCRIPTNAME="${0##*/}"
-SCRIPTNAME="${SCRIPTNAME%%.sh}"
-VERSION="0.0.3" # Check if pwd is git repo
-AUTHOR="ziggys"
-LICENSE="Public Domain"
-
-# usage
-usage () {
-test "$#" = 0 || printf "%s %s\\n" "${SCRIPTNAME}" "$@"
-cat << EOF | fold -s
-${SCRIPTNAME} version ${VERSION}
- by ${AUTHOR}
- License: ${LICENSE}
-
-${SCRIPTNAME} is a shellscript to bump version numbers in git projects.
-
-Usage: ${SCRIPTNAME} [option] <args>
-Usage: ${SCRIPTNAME} [-p|-u|-r] version_file -m "message"
- or: ${SCRIPTNAME} -h
-
-Options
- -p version file Bump to new patch version
- -u version_file Bump to new minor/updated version
- -r version_file Bump to new mayor release version
- -h HELP Print this help and exit
-
-For more details about this script go to
-Official Repository: https://git.p4g.club/git/${SCRIPTNAME}.git
-Mirror Repository: https://gitgud.io/ziggys/${SCRIPTNAME}.git
-EOF
-exit 0
-}
-
-# use a file to describe new version
-describe_usefile () {
-DESCRIBEF="$(mktemp -p "${TMPDIR}")"
-printf "\\n/* Write a version description, save the file and close %s\\n \
- /* Description will be added to VERSION notice in %s\\n \
- /* Lines starting with '/*' will be ignored\\n \
- /* Leave it 'blank' if you won't like a version description\\n" \
- "${EDITOR:=vim}" "${VFILE}" > "${DESCRIBEF}"
-
- sed -i 's/^ *//g' "${DESCRIBEF}"
- ${EDITOR} "${DESCRIBEF}"
- DESCRIPTION="$(sed '/^\/\*/ d' "${DESCRIBEF}")"
-
- test -z "${DESCRIPTION}" \
- && printf "Version will be described from default" \
- && DESCRIPTION="version ${NEXT}"
-}
-
-isgit () {
- git rev-parse > /dev/null
- test "$?" -ne 0 \
- && printf "Working directory is not a git repository, exiting..." \
- && exit 0
-}
-
-# obtain current version
-TMPDIR="$(mktemp -d)"
-VFILE="$2"
-CURRENT="$(sed '/^VERSION=/ !d; s/VERSION="//; s/".*$//' "${VFILE}")"
-
-if [ -z "${CURRENT}" ]; then
- printf "%s couldn't find version number in %s\\n" "${SCRIPTNAME}" "${VFILE}"
- printf "Please, edit %s or use a file containing a valid string VERSION=\"x.y.z\"" "${VFILE}"
- exit 0
-else
- printf "Current version is: %s\\n" "${CURRENT}"
-fi
-
-# calculate new version
-case "$1" in
- -p | --patch)
- NEXT="$(echo "${CURRENT}" | \
- awk '{split($0,a,".");
- a[3]++;
- b=a[1]"."a[2]"."a[3]}
- END{OFS="."; print b}
- ')"
-
- printf "Patch version will be: %s\\n" "${NEXT}"
- ;;
-
- -u | --update)
- NEXT="$(echo "${CURRENT}" | \
- awk '{split($0,a,".");
- a[2]++;
- b=a[1]"."a[2]"."0}
- END{OFS="."; print b}
- ')"
-
- printf "Update version will be: %s\\n" "${NEXT}"
- ;;
-
- -r | --release)
- NEXT="$(echo "${CURRENT}" | \
- awk '{split($0,a,".");
- a[1]++;
- b=a[1]"."0"."0}
- END{OFS="."; print b}
- ')"
-
- NTAG="v${NEXT}"
-
- printf "Release version will be: %s\\n" "${NEXT}"
- printf "Release tag will be: %s\\n" "${NTAG}"
- ;;
-
- -c | --custom)
- printf "Please, provide a valid version number (x.y.z): "
- read -r CNEXT
-
- NEXT="${CNEXT}"
- printf "Next version will be: %s\\n" "${NEXT}"
- ;;
-
- *) usage "$@" ;;
-esac
-
-# describe new version for commit and tag
-case "$3" in
- -m | --message ) DESCRIPTION="$4" ;;
- *) describe_usefile ;;
-esac
-
-# bump version
-sed -i '/^VERSION=/ s/'"${CURRENT}"'/'"${NEXT}"'/' "${VFILE}"
-sed -i '/^VERSION=/ s/# .*$/# '"${DESCRIPTION}"'/' "${VFILE}"
-
-# commit changes
-printf "Would you like to commit changes in %s? (yes/all/no): " "${VFILE}"
-read -r CCOMMIT
-
-case "${CCOMMIT}" in
- y | yes | Y | YES | Yes )
- isgit
- printf "\\nAdding %s to stage and commiting changes" "${VFILE}"
- git add "${VFILE}"
- git commit -m "${DESCRIPTION}"
- ISTAG="${NTAG}"
- ;;
- a | all | A | ALL | All )
- isgit
- FILES="$(find . | grep -v "git" | sed 's/.\///g; 1 d')"
- for file in $FILES; do
- sed -i '/^VERSION=/ s/'"${CURRENT}"'/'"${NEXT}"'/' "${file}"
- sed -i '/^VERSION=/ s/# .*$/# '"${DESCRIPTION}"'/' "${file}"
- done
-
- printf "\\nAdding\\n%s\\nto stage and commiting changes\\n" "${FILES}"
- git add .
- git commit -m "${DESCRIPTION}"
- ISTAG="${NTAG}"
- ;;
- n | no | N | NO | No )
- printf "\\nNo files will be added to stage nor commited"
- ;;
-esac
-
-# tag if needed
-if [ ! -z "${ISTAG}" ]; then
- CHASH="$(git log --pretty=format:'%h' -n 1)"
- git tag -a "${NTAG}" "${CHASH}" -m "${DESCRIPTION}"
-fi
-
-rm -rf "${TMPDIR}"
-exit 0