123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #!/bin/bash
-
- __die_if() {
- #
- # Die if blocking condition $1 is detected
- #
- local condition="$1"
- local x
- case "$condition" in
- nogit)
- git rev-parse HEAD >&/dev/null\
- || die "cannot do this outside git repo"
- ;;
- norelbr)
- __git_info curbranch \
- | grep -qFx "$RELSRC" \
- || die "you are not on RELSRC branch: $RELSRC"
- ;;
- dirty)
- git diff --shortstat 2>/dev/null \
- | grep -q . \
- && die "tree is dirty: $dirt"
- ;;
- novertag)
- __git_info lasttag \
- | grep -q . \
- || die "cannot find last tag"
- ;;
- nobump)
- git diff-tree --no-commit-id --name-only -r HEAD \
- | grep -qFx config.mk \
- || die "last change must be version bump in config.mk"
- ;;
- wip)
- __git_info reldiff \
- | grep '^....... WIP ' \
- && die "WIP commit since $(__git_info lasttag)"
- ;;
- old_c)
- x=$(__ver_info nextver_g)
- __ver_info currver_c \
- | grep -qFx "$x" \
- || die "new version not in config.mk: $x"
- ;;
- esac
- }
-
- __git_info() {
- #
- # Get git info $1
- #
- local info="$1"
- case "$info" in
- lasttag) git tag | grep ^v | sort -V | tail -n1 ;;
- curbranch) git rev-parse --abbrev-ref HEAD ;;
- reldiff) git log --oneline "$(__git_info lasttag)..HEAD" ;;
- esac
- }
-
- __ver_info() {
- #
- # Get git info $1
- #
- local info="$1"
- case "$info" in
- lastver_g) __git_info lasttag | sed s/^v// ;;
- nextver_g) __make_ver "$level" "$(__ver_info lastver_g)" ;;
- currver_c) grep -m 1 -w VERSION config.mk \
- | sed 's/ *= */=/' | cut -d = -f 2 | xargs echo ;;
- nextver_c) __make_ver "$level" "$(__ver_info currver_c)" ;;
- esac
- }
-
- __make_ver() {
- local level=$1
- local old=$2
- local oldx=${old%.*.*}
- local oldz=${old#*.*.}
- local tmpy=${old%.*}
- local oldy=${tmpy#*.}
- case $level in
- x) new="$((oldx+1)).0.0" ;;
- y) new="$oldx.$((oldy+1)).0" ;;
- z) new="$oldx.$oldy.$((oldz+1))" ;;
- *) die "invalid release level: $1" ;;
- esac
- echo "$new"
- }
-
- __release() {
- #
- # Prepare release
- #
- # Span release routines: make a signed tag, check branch
- # and update release branch
- #
- # FIXME: Using PRERELEASE as build.sh:get_version() does may not be
- # compatible with this release strategy
- #
- local level=$1
- local newtag
-
- __die_if nogit
- __die_if norelbr
- __die_if dirty
- __die_if novertag
- __die_if nobump
- __die_if wip
- __die_if old_c
-
- newtag=v$(__ver_info nextver_g)
- set -e
- debug_var newtag
- $MKIT_DRY && return
- git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
- git branch -f "$RELDST" "$newtag"
- }
-
- __git_msg_vbump() {
- echo "Bump version"
- echo ""
- __git_info reldiff | sed 's/^/ * /'
- }
-
- __vbump() {
- local level="$1"
- local lastver # current from config.mk
- local nextver # after the bump
- __die_if nogit
- __die_if norelbr
- __die_if dirty
- lastver=$(__ver_info currver_c)
- nextver=$(__ver_info nextver_c)
- debug_var lastver nextver
- $MKIT_DRY && return
- sed -i "s/$lastver/$nextver/" config.mk \
- || die "failed to update config.mk"
- git add config.mk \
- || die "failed to add config.mk to the index"
- git commit -e -m "$(__git_msg_vbump)"
- }
-
- vbump_x() {
- __vbump x
- }
-
- vbump_y() {
- __vbump y
- }
-
- vbump_z() {
- __vbump z
- }
-
- release_x() {
- __release x
- }
-
- release_y() {
- __release y
- }
-
- release_z() {
- __release z
- }
|