release.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. _relck git_present
  85. _relck at_relsrc
  86. _relck not_dirty
  87. _relck tags_ok
  88. _relck vbump_hot
  89. _relck no_wip
  90. _relck ini_version
  91. newtag=$(git_fact latest_version | _bump_version "$rlevel" | git_ver2tag )
  92. set -e
  93. debug_var newtag
  94. $MKIT_DRY && return
  95. git tag -m "$(ini 1value project:name) $newtag - $CODENAME" "$newtag"
  96. git branch -f "$(ini 1value project:reldst)" "$newtag"
  97. }
  98. _vbump() {
  99. local rlevel="$1"
  100. local lastver # current from mkit.ini
  101. local nextver # after the bump
  102. _relck git_present
  103. _relck at_relsrc
  104. _relck not_dirty
  105. nextver=$(ini 1value project:version | _bump_version "$rlevel")
  106. debug_var lastver nextver
  107. $MKIT_DRY && return
  108. update_version "$nextver" mkit.ini \
  109. || die "failed to update version in mkit.ini"
  110. git add mkit.ini \
  111. || die "failed to add mkit.ini to the index"
  112. git commit -e -m "$(_vbump_gitmsg)"
  113. }
  114. _vbump_gitmsg() {
  115. echo "Bump version"
  116. echo ""
  117. echo "Overview of changes:"
  118. echo ""
  119. git_fact reldiff \
  120. | sed '
  121. s/^[a-f0-9]\{7\} / * &/; t PATHS
  122. s/^/ /
  123. :PATHS
  124. '
  125. }
  126. release_x() {
  127. _release x
  128. }
  129. release_y() {
  130. _release y
  131. }
  132. release_z() {
  133. _release z
  134. }
  135. vbump_x() {
  136. _vbump x
  137. }
  138. vbump_y() {
  139. _vbump y
  140. }
  141. vbump_z() {
  142. _vbump z
  143. }