#!/bin/bash __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 git rev-parse HEAD >&/dev/null || die "cannot release outside git repo" local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD) local lasttag=$(git tag | grep ^v | sort -V | tail -n1) local changelog="$(git log --oneline "$lasttag..HEAD")" local curbranch=$(git rev-parse --abbrev-ref HEAD) local dirt="$(git diff --shortstat 2>/dev/null)" local newver=$(__make_ver "$level" "${lasttag#v}") local newtag=v$newver local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1) test "$lastfile" = config.mk \ || die "last change must be version bump in config.mk" test -n "$lasttag" \ || die "cannot find last tag" test "$newtag" = "$higher" \ || die "generated tag looks older: $oldtag<$newtag" grep -qw "$newver" config.mk \ || die "new version not in config.mk: $newver" grep '^....... WIP ' <<<"$changelog" \ && die "WIP commit since $lasttag" grep -qw "$curbranch" <<<"$RELSRC" \ || die "you are not on RELSRC branch: $RELSRC" test -z "$dirt" \ || die "tree is dirty: $dirt" # FIXME: Have user prepare proper message with changelog set -e git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag" git branch -f "$RELDST" "$newtag" } release_x() { __release x } release_y() { __release y } release_z() { __release z }