release.sh 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. local level=$1
  25. git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
  26. local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
  27. local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
  28. local changelog="$(git log --oneline $lasttag..HEAD)"
  29. local curbranch=$(git rev-parse --abbrev-ref HEAD)
  30. local dirt="$(git diff --shortstat 2>/dev/null)"
  31. local newver=$(__make_ver $level ${lasttag#v})
  32. local newtag=v$newver
  33. local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
  34. test "$newtag" = "$higher" || die "generated tag looks older: $oldtag<$newtag"
  35. grep -qw "$newver" config.mk || die "new version not in config.mk: $newver"
  36. test -n "$lasttag" || die "cannot find last tag"
  37. grep '^....... WIP ' <<<"$changelog" && die "WIP commit since $lasttag"
  38. grep -qw "$curbranch" <<<"$RELSRC" || die "you are not on RELSRC branch: $RELSRC"
  39. test -z "$dirt" || die "tree is dirty: $dirt"
  40. # FIXME: Have user prepare proper message with changelog
  41. set -e
  42. git tag -m "$MKIT_PROJNAME $newtag-$STAGE - $CODENAME" $newtag
  43. git branch -f $RELDST $newtag
  44. }
  45. release_x() {
  46. __release x
  47. }
  48. release_y() {
  49. __release y
  50. }
  51. release_z() {
  52. __release z
  53. }