release.sh 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "$newtag" = "$higher" \
  38. || die "generated tag looks older: $oldtag<$newtag"
  39. grep -qw "$newver" config.mk \
  40. || die "new version not in config.mk: $newver"
  41. test -n "$lasttag" \
  42. || die "cannot find last tag"
  43. grep '^....... WIP ' <<<"$changelog" \
  44. && die "WIP commit since $lasttag"
  45. grep -qw "$curbranch" <<<"$RELSRC" \
  46. || die "you are not on RELSRC branch: $RELSRC"
  47. test -z "$dirt" \
  48. || die "tree is dirty: $dirt"
  49. # FIXME: Have user prepare proper message with changelog
  50. set -e
  51. git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" $newtag
  52. git branch -f $RELDST $newtag
  53. }
  54. release_x() {
  55. __release x
  56. }
  57. release_y() {
  58. __release y
  59. }
  60. release_z() {
  61. __release z
  62. }