123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- #!/bin/bash
-
-
-
- mkit_import ini
- mkit_import facts
-
- __bump_version() {
-
-
-
- local rlevel=$1
- local old
- local oldx
- local oldz
- local oldy
- local tmpy
- local new
- read -r old
- oldx=${old%.*.*}
- oldz=${old#*.*.}
- tmpy=${old%.*}
- oldy=${tmpy#*.}
- case $rlevel in
- x) new="$((oldx+MKIT_BUMPSIZE)).0.0" ;;
- y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0" ;;
- z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))" ;;
- *) die "invalid release level: $1" ;;
- esac
- echo "$new"
- }
-
- __relck() {
-
-
-
- local condition=$1
- local oracle
- case "$condition" in
- git_present)
- git rev-parse HEAD >&/dev/null\
- || die "cannot do this outside git repo"
- ;;
- at_relsrc)
- oracle=$(ini 1value project:relsrc)
- git_fact current_branch \
- | grep -qFx "$oracle" \
- || die "you are not on release source branch: $oracle"
- ;;
- not_dirty)
- git diff --shortstat 2>/dev/null \
- | grep -q . \
- && die "tree is dirty!"
- ;;
- tags_ok)
- git_fact latest_tag \
- | grep -q . \
- || die "cannot find latest tag"
- ;;
- vbump_hot)
- git diff-tree --no-commit-id --name-only -r HEAD \
- | grep -qFx mkit.ini \
- || die "last change must be version bump in mkit.ini"
- ;;
- no_wip)
- git_fact reldiff \
- | grep '^....... WIP ' \
- && die "WIP commit since $(git_fact latest_tag)"
- ;;
- ini_version)
- oracle=$(git_fact latest_version | __bump_version "$rlevel")
- ini 1value project:version \
- | grep -qFx "$oracle" \
- || die "new version not in mkit.ini: $oracle"
- ;;
- *)
- die "unknown release check: $condition"
- ;;
- esac
- }
-
- __release() {
-
-
-
-
-
-
-
-
-
- local rlevel=$1
- local newtag
- local relsrc
- local reldst
-
- __relck git_present
- __relck at_relsrc
- __relck not_dirty
- __relck tags_ok
- __relck vbump_hot
- __relck no_wip
- __relck ini_version
-
- newtag=$(git_fact latest_version | __bump_version "$rlevel" | git_ver2tag )
- set -e
- debug_var newtag
- $MKIT_DRY && return
- git tag -m "$(__release_msg)" "$newtag"
-
- relsrc=$(ini 1value project:relsrc)
- reldst=$(ini 1value project:reldst)
- debug_var relsrc reldst
- if test -n "$reldst" && test "$reldst" != "$relsrc"; then
- git branch -f "$reldst" "$newtag"
- fi
- }
-
- __release_msg() {
-
-
-
-
-
-
-
-
-
-
- echo "$(ini 1value project:name) $newtag - $(ini 1value project:codename)"
- echo
- git show -s --format=%B \
- | tail -n +3
- }
-
- __vbump() {
-
-
-
-
-
-
- local rlevel=$1
- local nextver
- local cache
- __relck git_present
- __relck at_relsrc
- __relck not_dirty
- nextver=$(ini 1value project:version | __bump_version "$rlevel")
- debug_var nextver
- $MKIT_DRY && return
- update_version "$nextver" mkit.ini \
- || die "failed to update version in mkit.ini"
- git add mkit.ini \
- || die "failed to add mkit.ini to the index"
- cache=$(mktemp -t "mkit._vbump_gitmsg.XXXXXXXX")
- _vbump_gitmsg > "$cache"
- git commit -e -F "$cache"
- rm "$cache"
- }
-
- _vbump_gitmsg() {
-
-
-
- echo "Bump version"
- echo ""
- echo "Overview of changes:"
- echo ""
- git_fact reldiff \
- | sed '
- s/^[a-f0-9]\{7\} /\n * &/; t PATHS
- s/^/ /
- :PATHS
- '
- }
-
- release() {
-
-
-
- __release z
- }
-
- release_x() {
-
-
-
- __release x
- }
-
- release_y() {
-
-
-
- __release y
- }
-
- release_z() {
-
-
-
- __release z
- }
-
- vbump() {
-
-
-
- __vbump z
- }
-
- vbump_x() {
-
-
-
- __vbump x
- }
-
- vbump_y() {
-
-
-
- __vbump y
- }
-
- vbump_z() {
-
-
-
- __vbump z
- }
|