imapfilter convenience wrapper

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. # MKit - simple install helper
  3. # See LICENSE file for copyright and license details.
  4. mkit_import ini
  5. mkit_import facts
  6. __bump_version() {
  7. #
  8. # Bump version on stdin by level $1 (x, y or z)
  9. #
  10. local rlevel=$1 # release level
  11. local old # old version
  12. local oldx # ... X
  13. local oldz # ... Z
  14. local oldy # ... Y
  15. local tmpy # Y parsing cache
  16. local new # bumped version
  17. read -r old
  18. oldx=${old%.*.*}
  19. oldz=${old#*.*.}
  20. tmpy=${old%.*}
  21. oldy=${tmpy#*.}
  22. case $rlevel in
  23. x) new="$((oldx+MKIT_BUMPSIZE)).0.0" ;;
  24. y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0" ;;
  25. z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))" ;;
  26. *) die "invalid release level: $1" ;;
  27. esac
  28. echo "$new"
  29. }
  30. __relck() {
  31. #
  32. # Die if blocking condition $1 is detected
  33. #
  34. local condition=$1 # condition name
  35. local oracle # expected value
  36. case "$condition" in
  37. git_present)
  38. git rev-parse HEAD >&/dev/null\
  39. || die "cannot do this outside git repo"
  40. ;;
  41. at_relsrc)
  42. oracle=$(ini 1value project:relsrc)
  43. git_fact current_branch \
  44. | grep -qFxe "$oracle" \
  45. || die "you are not on release source branch: $oracle"
  46. ;;
  47. not_dirty)
  48. git diff --shortstat 2>/dev/null \
  49. | grep -q . \
  50. && die "tree is dirty!"
  51. ;;
  52. tags_ok)
  53. git_fact latest_tag \
  54. | grep -q . \
  55. || die "cannot find latest tag"
  56. ;;
  57. vbump_hot)
  58. git diff-tree --no-commit-id --name-only -r HEAD \
  59. | grep -qFx mkit.ini \
  60. || die "last change must be version bump in mkit.ini"
  61. ;;
  62. no_wip)
  63. git_fact reldiff \
  64. | grep '^....... WIP ' \
  65. && die "WIP commit since $(git_fact latest_tag)"
  66. ;;
  67. ini_version)
  68. oracle=$(git_fact latest_version | __bump_version "$rlevel")
  69. ini 1value project:version \
  70. | grep -qFxe "$oracle" \
  71. || die "new version not in mkit.ini: $oracle"
  72. ;;
  73. *)
  74. die "unknown release check: $condition"
  75. ;;
  76. esac
  77. }
  78. __release() {
  79. #
  80. # Prepare release
  81. #
  82. # Span release routines: make a signed tag, check branch
  83. # and update release branch
  84. #
  85. # FIXME: Using project:prerl as build.sh:semver() does may not be
  86. # compatible with this release strategy
  87. #
  88. local rlevel=$1 # release level (x, y or z)
  89. local newtag # new tag
  90. local relsrc # release source branch (if any)
  91. local reldst # release destination branch (if any)
  92. __relck git_present
  93. __relck at_relsrc
  94. __relck not_dirty
  95. __relck tags_ok
  96. __relck vbump_hot
  97. __relck no_wip
  98. __relck ini_version
  99. newtag=$(git_fact latest_version | __bump_version "$rlevel" | git_ver2tag )
  100. set -e
  101. debug_var newtag
  102. $MKIT_DRY && return
  103. git tag -m "$(__release_msg)" "$newtag"
  104. relsrc=$(ini 1value project:relsrc)
  105. reldst=$(ini 1value project:reldst)
  106. debug_var relsrc reldst
  107. if test -n "$reldst" && test "$reldst" != "$relsrc"; then
  108. git branch -f "$reldst" "$newtag"
  109. fi
  110. }
  111. __release_msg() {
  112. #
  113. # Generate message for annotated tag
  114. #
  115. # The last commit before issuing a release must be "Bump version" commit
  116. # suggested by _vbump_gitmsg() and manually edited by user. Since the
  117. # commit contains changelog, this function just uses the message body.
  118. #
  119. # The sort message (first line) is replaced with a nicer one (with project
  120. # name, codename and version).
  121. #
  122. echo "$(ini 1value project:name) $newtag - $(ini 1value project:codename)"
  123. echo
  124. git show -s --format=%B \
  125. | tail -n +3
  126. }
  127. __vbump() {
  128. #
  129. # Do version bump at level $1
  130. #
  131. # Perform checks, compute new version, update mkit.ini and initiate
  132. # 'Bump version' commit with changelog template.
  133. #
  134. local rlevel=$1 # bump level (x, y or z)
  135. local nextver # version after the bump
  136. local cache # cache for the message
  137. __relck git_present
  138. __relck at_relsrc
  139. __relck not_dirty
  140. nextver=$(ini 1value project:version | __bump_version "$rlevel")
  141. debug_var nextver
  142. $MKIT_DRY && return
  143. update_version "$nextver" mkit.ini \
  144. || die "failed to update version in mkit.ini"
  145. git add mkit.ini \
  146. || die "failed to add mkit.ini to the index"
  147. cache=$(mktemp -t "mkit._vbump_gitmsg.XXXXXXXX")
  148. _vbump_gitmsg "$nextver" > "$cache"
  149. git commit -e -F "$cache" # note: reading from stdin will break vim
  150. rm "$cache"
  151. }
  152. _vbump_gitmsg() {
  153. #
  154. # Compose git message template for 'Bump version' commit
  155. #
  156. local nextver=$1
  157. echo "Bump version to $nextver"
  158. echo ""
  159. echo "Overview of changes:"
  160. echo ""
  161. git_fact reldiff \
  162. | sed '
  163. s/^[a-f0-9]\{7\} /\n * &/; t PATHS
  164. s/^/ /
  165. :PATHS
  166. '
  167. }
  168. release() {
  169. #
  170. # Perform release on Z level
  171. #
  172. __release z
  173. }
  174. release_x() {
  175. #
  176. # Perform release on X level
  177. #
  178. __release x
  179. }
  180. release_y() {
  181. #
  182. # Perform release on Y level
  183. #
  184. __release y
  185. }
  186. release_z() {
  187. #
  188. # Perform release on Z level
  189. #
  190. __release z
  191. }
  192. vbump() {
  193. #
  194. # Perform version bump on Z level
  195. #
  196. __vbump z
  197. }
  198. vbump_x() {
  199. #
  200. # Perform version bump on X level
  201. #
  202. __vbump x
  203. }
  204. vbump_y() {
  205. #
  206. # Perform version bump on Y level
  207. #
  208. __vbump y
  209. }
  210. vbump_z() {
  211. #
  212. # Perform version bump on Z level
  213. #
  214. __vbump z
  215. }