release.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. __git_info curbranch \
  15. | grep -qFx "$RELSRC" \
  16. || die "you are not on RELSRC branch: $RELSRC"
  17. ;;
  18. dirty)
  19. git diff --shortstat 2>/dev/null \
  20. | grep -q . \
  21. && die "tree is dirty: $dirt"
  22. ;;
  23. novertag)
  24. __git_info lasttag \
  25. | grep -q . \
  26. || die "cannot find last tag"
  27. ;;
  28. nobump)
  29. git diff-tree --no-commit-id --name-only -r HEAD \
  30. | grep -qFx config.mk \
  31. || die "last change must be version bump in config.mk"
  32. ;;
  33. wip)
  34. __git_info reldiff \
  35. | grep '^....... WIP ' \
  36. && die "WIP commit since $(__git_info lasttag)"
  37. ;;
  38. old_c)
  39. x=$(__ver_info nextver_g)
  40. __ver_info currver_c \
  41. | grep -qFx "$x" \
  42. || die "new version not in config.mk: $x"
  43. ;;
  44. esac
  45. }
  46. __git_info() {
  47. #
  48. # Get git info $1
  49. #
  50. local info="$1"
  51. case "$info" in
  52. lasttag) git tag | grep ^v | sort -V | tail -n1 ;;
  53. curbranch) git rev-parse --abbrev-ref HEAD ;;
  54. reldiff) git log --oneline "$(__git_info lasttag)..HEAD" ;;
  55. esac
  56. }
  57. __ver_info() {
  58. #
  59. # Get git info $1
  60. #
  61. local info="$1"
  62. case "$info" in
  63. lastver_g) __git_info lasttag | sed s/^v// ;;
  64. nextver_g) __make_ver "$level" "$(__ver_info lastver_g)" ;;
  65. currver_c) grep -m 1 -w VERSION config.mk \
  66. | sed 's/ *= */=/' | cut -d = -f 2 | xargs echo ;;
  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 PRERELEASE 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_PROJNAME $newtag - $CODENAME" "$newtag"
  109. git branch -f "$RELDST" "$newtag"
  110. }
  111. __git_msg_vbump() {
  112. echo "Bump version"
  113. echo ""
  114. __git_info reldiff | sed 's/^/ * /'
  115. }
  116. __vbump() {
  117. local level="$1"
  118. local lastver # current from config.mk
  119. local nextver # after the bump
  120. __die_if nogit
  121. __die_if norelbr
  122. __die_if dirty
  123. lastver=$(__ver_info currver_c)
  124. nextver=$(__ver_info nextver_c)
  125. debug_var lastver nextver
  126. $MKIT_DRY && return
  127. sed -i "s/$lastver/$nextver/" config.mk \
  128. || die "failed to update config.mk"
  129. git add config.mk \
  130. || die "failed to add config.mk to the index"
  131. git commit -e -m "$(__git_msg_vbump)"
  132. }
  133. vbump_x() {
  134. __vbump x
  135. }
  136. vbump_y() {
  137. __vbump y
  138. }
  139. vbump_z() {
  140. __vbump z
  141. }
  142. release_x() {
  143. __release x
  144. }
  145. release_y() {
  146. __release y
  147. }
  148. release_z() {
  149. __release z
  150. }