bump_version.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. # * appdata release version and date are updated
  19. # * Commit the changes
  20. # * Tag with current version
  21. perform_release() {
  22. RELEASE_DATE=$(date +%Y-%m-%d)
  23. sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt
  24. sed -i 's/project.ext.set("versionExtra", "-dev")/project.ext.set("versionExtra", "")/' android/build.gradle
  25. sed -i -re "s/\"versionCode\", [0-9]+/\"versionCode\", $NEW_ANDROID_VERSION_CODE/" android/build.gradle
  26. sed -i '/\<release/s/\(version\)="[^"]*"/\1="'"$RELEASE_VERSION"'"/' misc/net.minetest.minetest.appdata.xml
  27. sed -i 's/\(<release date\)="[^"]*"/\1="'"$RELEASE_DATE"'"/' misc/net.minetest.minetest.appdata.xml
  28. git add -f CMakeLists.txt android/build.gradle misc/net.minetest.minetest.appdata.xml
  29. git commit -m "Bump version to $RELEASE_VERSION"
  30. echo "Tagging $RELEASE_VERSION"
  31. git tag -a "$RELEASE_VERSION" -m "$RELEASE_VERSION"
  32. }
  33. # After release
  34. # * Set DEVELOPMENT_BUILD to true
  35. # * Bump version in CMakeLists and docs
  36. # * Commit the changes
  37. back_to_devel() {
  38. echo 'Creating "return back to development" commit'
  39. # Update CMakeList.txt versions
  40. sed -i -re 's/^set\(DEVELOPMENT_BUILD FALSE\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt
  41. sed -i -re "s/^set\(VERSION_MAJOR [0-9]+\)$/set(VERSION_MAJOR $NEXT_VERSION_MAJOR)/" CMakeLists.txt
  42. sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEXT_VERSION_MINOR)/" CMakeLists.txt
  43. sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEXT_VERSION_PATCH)/" CMakeLists.txt
  44. # Update Android versions
  45. sed -i 's/set("versionExtra", "")/set("versionExtra", "-dev")/' android/build.gradle
  46. sed -i -re "s/set\(\"versionMajor\", [0-9]+\)/set(\"versionMajor\", $NEXT_VERSION_MAJOR)/" android/build.gradle
  47. sed -i -re "s/set\(\"versionMinor\", [0-9]+\)/set(\"versionMinor\", $NEXT_VERSION_MINOR)/" android/build.gradle
  48. sed -i -re "s/set\(\"versionPatch\", [0-9]+\)/set(\"versionPatch\", $NEXT_VERSION_PATCH)/" android/build.gradle
  49. # Update doc versions
  50. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/g" doc/menu_lua_api.txt
  51. sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEXT_VERSION/g" doc/client_lua_api.txt
  52. # Commit
  53. git add -f CMakeLists.txt android/build.gradle doc/menu_lua_api.txt doc/client_lua_api.txt
  54. git commit -m "Continue with $NEXT_VERSION-dev"
  55. }
  56. ##################################
  57. # Switch to top minetest directory
  58. ##################################
  59. cd ${0%/*}/..
  60. #######################
  61. # Determine old version
  62. #######################
  63. # Make sure all the files we need exist
  64. grep -q -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt
  65. grep -q -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt
  66. grep -q -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt
  67. grep -q -E '\("versionCode", [0-9]+\)' android/build.gradle
  68. VERSION_MAJOR=$(grep -E '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  69. VERSION_MINOR=$(grep -E '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  70. VERSION_PATCH=$(grep -E '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  71. ANDROID_VERSION_CODE=$(grep -E '"versionCode", [0-9]+' android/build.gradle | tr -dC 0-9)
  72. RELEASE_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
  73. echo "Current Minetest version: $RELEASE_VERSION"
  74. echo "Current Android version code: $ANDROID_VERSION_CODE"
  75. # +1 for ARM and +1 for ARM64 APKs
  76. NEW_ANDROID_VERSION_CODE=$(expr $ANDROID_VERSION_CODE + 2)
  77. NEW_ANDROID_VERSION_CODE=$(prompt_for_number "Set android version code" $NEW_ANDROID_VERSION_CODE)
  78. echo
  79. echo "New android version code: $NEW_ANDROID_VERSION_CODE"
  80. ########################
  81. # Perform release
  82. ########################
  83. perform_release
  84. ########################
  85. # Prompt for next version
  86. ########################
  87. NEXT_VERSION_MAJOR=$VERSION_MAJOR
  88. NEXT_VERSION_MINOR=$VERSION_MINOR
  89. NEXT_VERSION_PATCH=$(expr $VERSION_PATCH + 1)
  90. NEXT_VERSION_MAJOR=$(prompt_for_number "Set next major" $NEXT_VERSION_MAJOR)
  91. if [ "$NEXT_VERSION_MAJOR" != "$VERSION_MAJOR" ]; then
  92. NEXT_VERSION_MINOR=0
  93. NEXT_VERSION_PATCH=0
  94. fi
  95. NEXT_VERSION_MINOR=$(prompt_for_number "Set next minor" $NEXT_VERSION_MINOR)
  96. if [ "$NEXT_VERSION_MINOR" != "$VERSION_MINOR" ]; then
  97. NEXT_VERSION_PATCH=0
  98. fi
  99. NEXT_VERSION_PATCH=$(prompt_for_number "Set next patch" $NEXT_VERSION_PATCH)
  100. NEXT_VERSION="$NEXT_VERSION_MAJOR.$NEXT_VERSION_MINOR.$NEXT_VERSION_PATCH"
  101. echo
  102. echo "New version: $NEXT_VERSION"
  103. ########################
  104. # Return back to devel
  105. ########################
  106. back_to_devel