12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. __make_ver() {
  3. local level=$1
  4. local old=$2
  5. local oldx=${old%.*.*}
  6. local oldz=${old#*.*.}
  7. local tmpy=${old%.*}
  8. local oldy=${tmpy#*.}
  9. case $level in
  10. x) new="$((oldx+1)).0.0" ;;
  11. y) new="$oldx.$((oldy+1)).0" ;;
  12. z) new="$oldx.$oldy.$((oldz+1))" ;;
  13. *) die "invalid release level: $1" ;;
  14. esac
  15. echo "$new"
  16. }
  17. __release() {
  18. #
  19. # Prepare release
  20. #
  21. # Span release routines: make a signed tag, check branch
  22. # and update release branch
  23. #
  24. # FIXME: Using PRERELEASE as build.sh:get_version() does may not be
  25. # compatible with this release strategy
  26. #
  27. local level=$1
  28. git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
  29. local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
  30. local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
  31. local changelog="$(git log --oneline "$lasttag..HEAD")"
  32. local curbranch=$(git rev-parse --abbrev-ref HEAD)
  33. local dirt="$(git diff --shortstat 2>/dev/null)"
  34. local newver=$(__make_ver "$level" "${lasttag#v}")
  35. local newtag=v$newver
  36. local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
  37. test "$lastfile" = config.mk \
  38. || die "last change must be version bump in config.mk"
  39. test -n "$lasttag" \
  40. || die "cannot find last tag"
  41. test "$newtag" = "$higher" \
  42. || die "generated tag looks older: $oldtag<$newtag"
  43. grep -qw "$newver" config.mk \
  44. || die "new version not in config.mk: $newver"
  45. grep '^....... WIP ' <<<"$changelog" \
  46. && die "WIP commit since $lasttag"
  47. grep -qw "$curbranch" <<<"$RELSRC" \
  48. || die "you are not on RELSRC branch: $RELSRC"
  49. test -z "$dirt" \
  50. || die "tree is dirty: $dirt"
  51. # FIXME: Have user prepare proper message with changelog
  52. set -e
  53. git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
  54. git branch -f "$RELDST" "$newtag"
  55. }
  56. release_x() {
  57. __release x
  58. }
  59. release_y() {
  60. __release y
  61. }
  62. release_z() {
  63. __release z
  64. }