bump_version.sh 4.1 KB

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