2
0

bump_version.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash -e
  2. prompt_for_number() {
  3. local prompt_text=$1
  4. local default_value=$2
  5. local tmp=""
  6. while true; do
  7. read -p "$prompt_text [$default_value]: " tmp
  8. if [ "$tmp" = "" ]; then
  9. echo "$default_value"; return
  10. elif echo "$tmp" | grep -q -E '^[0-9]+$'; then
  11. echo "$tmp"; return
  12. fi
  13. done
  14. }
  15. # On a release the following actions are performed
  16. # * DEVELOPMENT_BUILD is set to false
  17. # * android versionCode is bumped
  18. # * Commit the changes
  19. # * Tag with current version
  20. perform_release() {
  21. sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt
  22. sed -i -re "s/versionCode [0-9]+$/versionCode $NEW_ANDROID_VERSION_CODE/" build/android/build.gradle
  23. git add -f CMakeLists.txt build/android/build.gradle
  24. git commit -m "Bump version to $RELEASE_VERSION"
  25. echo "Tagging $RELEASE_VERSION"
  26. git tag -a "$RELEASE_VERSION" -m "$RELEASE_VERSION"
  27. }
  28. # After release
  29. # * Set DEVELOPMENT_BUILD to true
  30. # * Bump version in CMakeLists and docs
  31. # * Commit the changes
  32. back_to_devel() {
  33. echo 'Creating "return back to development" commit'
  34. sed -i -re 's/^set\(DEVELOPMENT_BUILD FALSE\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt
  35. sed -i -re "s/^set\(VERSION_MAJOR [0-9]+\)$/set(VERSION_MAJOR $NEXT_VERSION_MAJOR)/" CMakeLists.txt
  36. sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEXT_VERSION_MINOR)/" CMakeLists.txt
  37. sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEXT_VERSION_PATCH)/" CMakeLists.txt
  38. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/g" doc/menu_lua_api.txt
  39. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/g" doc/client_lua_api.md
  40. git add -f CMakeLists.txt doc/menu_lua_api.txt doc/client_lua_api.md
  41. git commit -m "Continue with $NEXT_VERSION-dev"
  42. }
  43. ##################################
  44. # Switch to top minetest directory
  45. ##################################
  46. cd ${0%/*}/..
  47. #######################
  48. # Determine old version
  49. #######################
  50. # Make sure all the files we need exist
  51. grep -q -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt
  52. grep -q -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt
  53. grep -q -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt
  54. grep -q -E 'versionCode [0-9]+$' build/android/build.gradle
  55. VERSION_MAJOR=$(grep -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  56. VERSION_MINOR=$(grep -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  57. VERSION_PATCH=$(grep -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  58. ANDROID_VERSION_CODE=$(grep -E 'versionCode [0-9]+$' build/android/build.gradle | tr -dC 0-9)
  59. RELEASE_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
  60. echo "Current Minetest version: $RELEASE_VERSION"
  61. echo "Current Android version code: $ANDROID_VERSION_CODE"
  62. NEW_ANDROID_VERSION_CODE=$(expr $ANDROID_VERSION_CODE + 1)
  63. NEW_ANDROID_VERSION_CODE=$(prompt_for_number "Set android version code" $NEW_ANDROID_VERSION_CODE)
  64. echo
  65. echo "New android version code: $NEW_ANDROID_VERSION_CODE"
  66. ########################
  67. # Perform release
  68. ########################
  69. perform_release
  70. ########################
  71. # Prompt for next version
  72. ########################
  73. NEXT_VERSION_MAJOR=$VERSION_MAJOR
  74. NEXT_VERSION_MINOR=$VERSION_MINOR
  75. NEXT_VERSION_PATCH=$(expr $VERSION_PATCH + 1)
  76. NEXT_VERSION_MAJOR=$(prompt_for_number "Set next major" $NEXT_VERSION_MAJOR)
  77. if [ "$NEXT_VERSION_MAJOR" != "$VERSION_MAJOR" ]; then
  78. NEXT_VERSION_MINOR=0
  79. NEXT_VERSION_PATCH=0
  80. fi
  81. NEXT_VERSION_MINOR=$(prompt_for_number "Set next minor" $NEXT_VERSION_MINOR)
  82. if [ "$NEXT_VERSION_MINOR" != "$VERSION_MINOR" ]; then
  83. NEXT_VERSION_PATCH=0
  84. fi
  85. NEXT_VERSION_PATCH=$(prompt_for_number "Set next patch" $NEXT_VERSION_PATCH)
  86. NEXT_VERSION="$NEXT_VERSION_MAJOR.$NEXT_VERSION_MINOR.$NEXT_VERSION_PATCH"
  87. echo
  88. echo "New version: $NEXT_VERSION"
  89. ########################
  90. # Return back to devel
  91. ########################
  92. back_to_devel