bump_version.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. die() { echo "$@" 1>&2 ; exit 1; }
  3. prompt_for_number() {
  4. local prompt_text=$1
  5. local default_value=$2
  6. local tmp=""
  7. while true; do
  8. read -p "$prompt_text [$default_value]: " tmp
  9. if [ "$tmp" = "" ]; then
  10. echo "$default_value"; return
  11. elif echo "$tmp" | grep -q -E '^[0-9]+$'; then
  12. echo "$tmp"; return
  13. fi
  14. done
  15. }
  16. ##################################
  17. # Switch to top minetest directory
  18. ##################################
  19. cd ${0%/*}/..
  20. #######################
  21. # Determine old version
  22. #######################
  23. # Make sure all the files we need exist
  24. grep -q -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt"
  25. grep -q -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt"
  26. grep -q -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt || die "error: Could not find CMakeLists.txt"
  27. grep -q -E '^ANDROID_VERSION_CODE = [0-9]+$' build/android/Makefile || die "error: Could not find build/android/Makefile"
  28. VERSION_MAJOR=$(grep -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  29. VERSION_MINOR=$(grep -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  30. VERSION_PATCH=$(grep -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  31. ANDROID_VERSION_CODE=$(grep -E '^ANDROID_VERSION_CODE = [0-9]+$' build/android/Makefile | tr -dC 0-9)
  32. echo "Current Minetest version: $VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
  33. echo "Current Android version code: $ANDROID_VERSION_CODE"
  34. ########################
  35. # Prompt for new version
  36. ########################
  37. NEW_VERSION_MAJOR=$VERSION_MAJOR
  38. NEW_VERSION_MINOR=$VERSION_MINOR
  39. NEW_VERSION_PATCH=$(expr $VERSION_PATCH + 1)
  40. NEW_VERSION_MAJOR=$(prompt_for_number "Set major" $NEW_VERSION_MAJOR)
  41. if [ "$NEW_VERSION_MAJOR" != "$VERSION_MAJOR" ]; then
  42. NEW_VERSION_MINOR=0
  43. NEW_VERSION_PATCH=0
  44. fi
  45. NEW_VERSION_MINOR=$(prompt_for_number "Set minor" $NEW_VERSION_MINOR)
  46. if [ "$NEW_VERSION_MINOR" != "$VERSION_MINOR" ]; then
  47. NEW_VERSION_PATCH=0
  48. fi
  49. NEW_VERSION_PATCH=$(prompt_for_number "Set patch" $NEW_VERSION_PATCH)
  50. NEW_ANDROID_VERSION_CODE=$(expr $ANDROID_VERSION_CODE + 1)
  51. NEW_ANDROID_VERSION_CODE=$(prompt_for_number "Set android version code" $NEW_ANDROID_VERSION_CODE)
  52. NEW_VERSION="$NEW_VERSION_MAJOR.$NEW_VERSION_MINOR.$NEW_VERSION_PATCH"
  53. echo
  54. echo "New version: $NEW_VERSION"
  55. echo "New android version code: $NEW_ANDROID_VERSION_CODE"
  56. #######################################
  57. # Replace version everywhere and commit
  58. #######################################
  59. sed -i -re "s/^set\(VERSION_MAJOR [0-9]+\)$/set(VERSION_MAJOR $NEW_VERSION_MAJOR)/" CMakeLists.txt || die "Failed to update VERSION_MAJOR"
  60. sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEW_VERSION_MINOR)/" CMakeLists.txt || die "Failed to update VERSION_MINOR"
  61. sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEW_VERSION_PATCH)/" CMakeLists.txt || die "Failed to update VERSION_PATCH"
  62. sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt || die "Failed to unset DEVELOPMENT_BUILD"
  63. sed -i -re "s/^ANDROID_VERSION_CODE = [0-9]+$/ANDROID_VERSION_CODE = $NEW_ANDROID_VERSION_CODE/" build/android/Makefile || die "Failed to update ANDROID_VERSION_CODE"
  64. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/lua_api.txt || die "Failed to update doc/lua_api.txt"
  65. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/menu_lua_api.txt || die "Failed to update doc/menu_lua_api.txt"
  66. git add -f CMakeLists.txt build/android/Makefile doc/lua_api.txt doc/menu_lua_api.txt || die "git add failed"
  67. git commit -m "Bump version to $NEW_VERSION" || die "git commit failed"
  68. ############
  69. # Create tag
  70. ############
  71. echo "Tagging $NEW_VERSION"
  72. git tag -a "$NEW_VERSION" -m "$NEW_VERSION" || die 'Adding tag failed'
  73. ######################
  74. # Create revert commit
  75. ######################
  76. echo 'Creating "revert to development" commit'
  77. sed -i -re 's/^set\(DEVELOPMENT_BUILD FALSE\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt || die 'Failed to set DEVELOPMENT_BUILD'
  78. git add -f CMakeLists.txt || die 'git add failed'
  79. git commit -m "Continue with $NEW_VERSION-dev" || die 'git commit failed'