release.sh 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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+1)).0.0" ;;
  18. y) new="$oldx.$((oldy+1)).0" ;;
  19. z) new="$oldx.$oldy.$((oldz+1))" ;;
  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 - $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 lastver # current from mkit.ini
  107. local nextver # after the bump
  108. _relck git_present
  109. _relck at_relsrc
  110. _relck not_dirty
  111. nextver=$(ini 1value project:version | _bump_version "$rlevel")
  112. debug_var lastver nextver
  113. $MKIT_DRY && return
  114. update_version "$nextver" mkit.ini \
  115. || die "failed to update version in mkit.ini"
  116. git add mkit.ini \
  117. || die "failed to add mkit.ini to the index"
  118. git commit -e -m "$(_vbump_gitmsg)"
  119. }
  120. _vbump_gitmsg() {
  121. echo "Bump version"
  122. echo ""
  123. echo "Overview of changes:"
  124. echo ""
  125. git_fact reldiff \
  126. | sed '
  127. s/^[a-f0-9]\{7\} / * &/; t PATHS
  128. s/^/ /
  129. :PATHS
  130. '
  131. }
  132. release_x() {
  133. _release x
  134. }
  135. release_y() {
  136. _release y
  137. }
  138. release_z() {
  139. _release z
  140. }
  141. vbump_x() {
  142. _vbump x
  143. }
  144. vbump_y() {
  145. _vbump y
  146. }
  147. vbump_z() {
  148. _vbump z
  149. }