123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. __die_if() {
  3. #
  4. # Die if blocking condition $1 is detected
  5. #
  6. local condition="$1"
  7. local x
  8. case "$condition" in
  9. nogit)
  10. git rev-parse HEAD >&/dev/null\
  11. || die "cannot do this outside git repo"
  12. ;;
  13. norelbr)
  14. local relsrc=$(ini 1value project:relsrc)
  15. __git_info curbranch \
  16. | grep -qFx "$relsrc" \
  17. || die "you are not on release source branch: $relsrc"
  18. ;;
  19. dirty)
  20. git diff --shortstat 2>/dev/null \
  21. | grep -q . \
  22. && die "tree is dirty: $dirt"
  23. ;;
  24. novertag)
  25. __git_info lasttag \
  26. | grep -q . \
  27. || die "cannot find last tag"
  28. ;;
  29. nobump)
  30. git diff-tree --no-commit-id --name-only -r HEAD \
  31. | grep -qFx mkit.ini \
  32. || die "last change must be version bump in mkit.ini"
  33. ;;
  34. wip)
  35. __git_info reldiff \
  36. | grep '^....... WIP ' \
  37. && die "WIP commit since $(__git_info lasttag)"
  38. ;;
  39. old_c)
  40. x=$(__ver_info nextver_g)
  41. __ver_info currver_c \
  42. | grep -qFx "$x" \
  43. || die "new version not in mkit.ini: $x"
  44. ;;
  45. esac
  46. }
  47. __git_info() {
  48. #
  49. # Get git info $1
  50. #
  51. local info="$1"
  52. case "$info" in
  53. lasttag) git tag | grep ^v | sort -V | tail -n1 ;;
  54. curbranch) git rev-parse --abbrev-ref HEAD ;;
  55. reldiff) git log --oneline "$(__git_info lasttag)..HEAD" --name-only ;;
  56. esac
  57. }
  58. __ver_info() {
  59. #
  60. # Get git info $1
  61. #
  62. local info="$1"
  63. case "$info" in
  64. lastver_g) __git_info lasttag | sed s/^v// ;;
  65. nextver_g) __make_ver "$level" "$(__ver_info lastver_g)" ;;
  66. currver_c) ini 1value project:version ;;
  67. nextver_c) __make_ver "$level" "$(__ver_info currver_c)" ;;
  68. esac
  69. }
  70. __make_ver() {
  71. local level=$1
  72. local old=$2
  73. local oldx=${old%.*.*}
  74. local oldz=${old#*.*.}
  75. local tmpy=${old%.*}
  76. local oldy=${tmpy#*.}
  77. case $level in
  78. x) new="$((oldx+1)).0.0" ;;
  79. y) new="$oldx.$((oldy+1)).0" ;;
  80. z) new="$oldx.$oldy.$((oldz+1))" ;;
  81. *) die "invalid release level: $1" ;;
  82. esac
  83. echo "$new"
  84. }
  85. __release() {
  86. #
  87. # Prepare release
  88. #
  89. # Span release routines: make a signed tag, check branch
  90. # and update release branch
  91. #
  92. # FIXME: Using project:prerl as build.sh:get_version() does may not be
  93. # compatible with this release strategy
  94. #
  95. local level=$1
  96. local newtag
  97. __die_if nogit
  98. __die_if norelbr
  99. __die_if dirty
  100. __die_if novertag
  101. __die_if nobump
  102. __die_if wip
  103. __die_if old_c
  104. newtag=v$(__ver_info nextver_g)
  105. set -e
  106. debug_var newtag
  107. $MKIT_DRY && return
  108. git tag -m "$MKIT_PROJ_NAME $newtag - $CODENAME" "$newtag"
  109. git branch -f "$(ini 1value project:reldst)" "$newtag"
  110. }
  111. __git_msg_vbump() {
  112. echo "Bump version"
  113. echo ""
  114. echo "Overview of changes:"
  115. echo ""
  116. __git_info reldiff \
  117. | sed '
  118. s/^[a-f0-9]\{7\} / * &/; t PATHS
  119. s/^/ /
  120. :PATHS
  121. '
  122. }
  123. __vbump() {
  124. local level="$1"
  125. local lastver # current from mkit.ini
  126. local nextver # after the bump
  127. __die_if nogit
  128. __die_if norelbr
  129. __die_if dirty
  130. lastver=$(__ver_info currver_c)
  131. nextver=$(__ver_info nextver_c)
  132. debug_var lastver nextver
  133. $MKIT_DRY && return
  134. update_version "$nextver" mkit.ini \
  135. || die "failed to update version in mkit.ini"
  136. git add mkit.ini \
  137. || die "failed to add mkit.ini to the index"
  138. git commit -e -m "$(__git_msg_vbump)"
  139. }
  140. vbump_x() {
  141. __vbump x
  142. }
  143. vbump_y() {
  144. __vbump y
  145. }
  146. vbump_z() {
  147. __vbump z
  148. }
  149. release_x() {
  150. __release x
  151. }
  152. release_y() {
  153. __release y
  154. }
  155. release_z() {
  156. __release z
  157. }