imapfilter convenience wrapper

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. . "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
  3. . "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
  4. _bump_version() {
  5. #
  6. # Bump version on stdin by level $1 (x, y or z)
  7. #
  8. local rlevel=$1
  9. local old
  10. read -r old
  11. local oldx=${old%.*.*}
  12. local oldz=${old#*.*.}
  13. local tmpy=${old%.*}
  14. local oldy=${tmpy#*.}
  15. local new=""
  16. case $rlevel in
  17. x) new="$((oldx+MKIT_BUMPSIZE)).0.0" ;;
  18. y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0" ;;
  19. z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))" ;;
  20. *) die "invalid release level: $1" ;;
  21. esac
  22. echo "$new"
  23. }
  24. _relck() {
  25. #
  26. # Die if blocking condition $1 is detected
  27. #
  28. local condition="$1"
  29. local x
  30. case "$condition" in
  31. git_present)
  32. git rev-parse HEAD >&/dev/null\
  33. || die "cannot do this outside git repo"
  34. ;;
  35. at_relsrc)
  36. local relsrc=$(ini 1value project:relsrc)
  37. git_fact current_branch \
  38. | grep -qFx "$relsrc" \
  39. || die "you are not on release source branch: $relsrc"
  40. ;;
  41. not_dirty)
  42. git diff --shortstat 2>/dev/null \
  43. | grep -q . \
  44. && die "tree is dirty: $dirt"
  45. ;;
  46. tags_ok)
  47. git_fact latest_tag \
  48. | grep -q . \
  49. || die "cannot find latest tag"
  50. ;;
  51. vbump_hot)
  52. git diff-tree --no-commit-id --name-only -r HEAD \
  53. | grep -qFx mkit.ini \
  54. || die "last change must be version bump in mkit.ini"
  55. ;;
  56. no_wip)
  57. git_fact reldiff \
  58. | grep '^....... WIP ' \
  59. && die "WIP commit since $(git_fact latest_tag)"
  60. ;;
  61. ini_version)
  62. local oracle=$(git_fact latest_version | _bump_version "$rlevel")
  63. ini 1value project:version \
  64. | grep -qFx "$oracle" \
  65. || die "new version not in mkit.ini: $oracle"
  66. ;;
  67. *)
  68. die "unknown release check: $condition"
  69. ;;
  70. esac
  71. }
  72. _release() {
  73. #
  74. # Prepare release
  75. #
  76. # Span release routines: make a signed tag, check branch
  77. # and update release branch
  78. #
  79. # FIXME: Using project:prerl as build.sh:semver() does may not be
  80. # compatible with this release strategy
  81. #
  82. local rlevel=$1
  83. local newtag
  84. local reldst
  85. _relck git_present
  86. _relck at_relsrc
  87. _relck not_dirty
  88. _relck tags_ok
  89. _relck vbump_hot
  90. _relck no_wip
  91. _relck ini_version
  92. newtag=$(git_fact latest_version | _bump_version "$rlevel" | git_ver2tag )
  93. set -e
  94. debug_var newtag
  95. $MKIT_DRY && return
  96. git tag -m "$(ini 1value project:name) $newtag - $(ini 1value project:codename)" "$newtag"
  97. reldst=$(ini 1value project:reldst)
  98. debug_var reldst
  99. if test -n "$reldst";
  100. then
  101. git branch -f "$reldst" "$newtag"
  102. fi
  103. }
  104. _vbump() {
  105. local rlevel="$1"
  106. local nextver # after the bump
  107. _relck git_present
  108. _relck at_relsrc
  109. _relck not_dirty
  110. nextver=$(ini 1value project:version | _bump_version "$rlevel")
  111. debug_var nextver
  112. $MKIT_DRY && return
  113. update_version "$nextver" mkit.ini \
  114. || die "failed to update version in mkit.ini"
  115. git add mkit.ini \
  116. || die "failed to add mkit.ini to the index"
  117. git commit -e -m "$(_vbump_gitmsg)"
  118. }
  119. _vbump_gitmsg() {
  120. echo "Bump version"
  121. echo ""
  122. echo "Overview of changes:"
  123. echo ""
  124. git_fact reldiff \
  125. | sed '
  126. s/^[a-f0-9]\{7\} / * &/; t PATHS
  127. s/^/ /
  128. :PATHS
  129. '
  130. }
  131. release_x() {
  132. _release x
  133. }
  134. release_y() {
  135. _release y
  136. }
  137. release_z() {
  138. _release z
  139. }
  140. vbump_x() {
  141. _vbump x
  142. }
  143. vbump_y() {
  144. _vbump y
  145. }
  146. vbump_z() {
  147. _vbump z
  148. }