bump_version.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/bash -e
  2. prompt_for() {
  3. local prompt_text=$1
  4. local pattern=$2
  5. local default_value=$3
  6. local tmp=
  7. while true; do
  8. read -p "$prompt_text [$default_value]: " tmp
  9. if [ -z "$tmp" ]; then
  10. echo "$default_value"; return
  11. elif echo "$tmp" | grep -qE "^(${pattern})\$"; then
  12. echo "$tmp"; return
  13. fi
  14. done
  15. }
  16. # Reads current versions
  17. # out: VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_IS_DEV CURRENT_VERSION
  18. read_versions() {
  19. VERSION_MAJOR=$(grep -oE '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  20. VERSION_MINOR=$(grep -oE '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  21. VERSION_PATCH=$(grep -oE '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9)
  22. VERSION_IS_DEV=$(grep -oE '^set\(DEVELOPMENT_BUILD [A-Z]+\)$' CMakeLists.txt)
  23. # Make sure they all exist
  24. [ -n "$VERSION_MAJOR" ]
  25. [ -n "$VERSION_MINOR" ]
  26. [ -n "$VERSION_PATCH" ]
  27. [ -n "$VERSION_IS_DEV" ]
  28. if echo "$VERSION_IS_DEV" | grep -q ' TRUE'; then
  29. VERSION_IS_DEV=1
  30. else
  31. VERSION_IS_DEV=0
  32. fi
  33. CURRENT_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
  34. echo "Current Minetest version: $CURRENT_VERSION"
  35. }
  36. # Retrieves protocol version from header
  37. # in: $1
  38. read_proto_ver() {
  39. local ref=$1
  40. git show "$ref":src/network/networkprotocol.h | grep -oE 'LATEST_PROTOCOL_VERSION [0-9]+' | tr -dC 0-9
  41. }
  42. ## Prompts for new version
  43. # in: VERSION_{MAJOR,MINOR,PATCH} DO_PATCH_REL
  44. # out: NEXT_VERSION NEXT_VERSION_{MAJOR,MINOR,PATCH}
  45. bump_version() {
  46. NEXT_VERSION_MAJOR=$VERSION_MAJOR
  47. if [ "$DO_PATCH_REL" -eq 1 ]; then
  48. NEXT_VERSION_MINOR=$VERSION_MINOR
  49. NEXT_VERSION_PATCH=$(expr $VERSION_PATCH + 1)
  50. else
  51. NEXT_VERSION_MINOR=$(expr $VERSION_MINOR + 1)
  52. NEXT_VERSION_PATCH=0
  53. fi
  54. NEXT_VERSION_MAJOR=$(prompt_for "Set next major" '[0-9]+' $NEXT_VERSION_MAJOR)
  55. if [ "$NEXT_VERSION_MAJOR" != "$VERSION_MAJOR" ]; then
  56. NEXT_VERSION_MINOR=0
  57. NEXT_VERSION_PATCH=0
  58. fi
  59. NEXT_VERSION_MINOR=$(prompt_for "Set next minor" '[0-9]+' $NEXT_VERSION_MINOR)
  60. if [ "$NEXT_VERSION_MINOR" != "$VERSION_MINOR" ]; then
  61. NEXT_VERSION_PATCH=0
  62. fi
  63. NEXT_VERSION_PATCH=$(prompt_for "Set next patch" '[0-9]+' $NEXT_VERSION_PATCH)
  64. NEXT_VERSION="$NEXT_VERSION_MAJOR.$NEXT_VERSION_MINOR.$NEXT_VERSION_PATCH"
  65. echo
  66. echo "New version: $NEXT_VERSION"
  67. }
  68. ## Toggles development build
  69. # in: $1
  70. set_dev_build() {
  71. local is_dev=$1
  72. # Update CMakeList.txt versions
  73. if [ "$is_dev" -eq 1 ]; then
  74. sed -i -re 's/^set\(DEVELOPMENT_BUILD [A-Z]+\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt
  75. else
  76. sed -i -re 's/^set\(DEVELOPMENT_BUILD [A-Z]+\)$/set(DEVELOPMENT_BUILD FALSE)/' CMakeLists.txt
  77. fi
  78. git add -f CMakeLists.txt android/build.gradle
  79. }
  80. ## Writes new version to the right files
  81. # in: NEXT_VERSION NEXT_VERSION_{MAJOR,MINOR,PATCH}
  82. write_new_version() {
  83. # Update CMakeList.txt versions
  84. sed -i -re "s/^set\(VERSION_MAJOR [0-9]+\)$/set(VERSION_MAJOR $NEXT_VERSION_MAJOR)/" CMakeLists.txt
  85. sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEXT_VERSION_MINOR)/" CMakeLists.txt
  86. sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEXT_VERSION_PATCH)/" CMakeLists.txt
  87. # Update Android versions
  88. sed -i -re "s/set\(\"versionMajor\", [0-9]+\)/set(\"versionMajor\", $NEXT_VERSION_MAJOR)/" android/build.gradle
  89. sed -i -re "s/set\(\"versionMinor\", [0-9]+\)/set(\"versionMinor\", $NEXT_VERSION_MINOR)/" android/build.gradle
  90. sed -i -re "s/set\(\"versionPatch\", [0-9]+\)/set(\"versionPatch\", $NEXT_VERSION_PATCH)/" android/build.gradle
  91. # Update doc versions
  92. sed -i -re '1s/[0-9]+\.[0-9]+\.[0-9]+/'"$NEXT_VERSION"'/g' doc/menu_lua_api.md
  93. sed -i -re '1s/[0-9]+\.[0-9]+\.[0-9]+/'"$NEXT_VERSION"'/g' doc/client_lua_api.md
  94. git add -f CMakeLists.txt android/build.gradle doc/menu_lua_api.md doc/client_lua_api.md
  95. }
  96. ## Create release commit and tag
  97. # in: $1
  98. perform_release() {
  99. local release_version=$1
  100. RELEASE_DATE=$(date +%Y-%m-%d)
  101. sed -i '/\<release/s/\(version\)="[^"]*"/\1="'"$release_version"'"/' misc/net.minetest.minetest.metainfo.xml
  102. sed -i 's/\(<release date\)="[^"]*"/\1="'"$RELEASE_DATE"'"/' misc/net.minetest.minetest.metainfo.xml
  103. git add -f misc/net.minetest.minetest.metainfo.xml
  104. git commit -m "Bump version to $release_version"
  105. echo "Tagging $release_version"
  106. git tag -a "$release_version" -m "$release_version"
  107. }
  108. ## Create after-release commit
  109. # in: NEXT_VERSION
  110. back_to_devel() {
  111. echo 'Creating "return back to development" commit'
  112. git commit -m "Continue with $NEXT_VERSION-dev"
  113. }
  114. #######################
  115. # Start of main logic:
  116. #######################
  117. # Switch to top minetest directory
  118. cd ${0%/*}/..
  119. # Determine old versions
  120. read_versions
  121. # Double-check what we're doing
  122. if [ "$VERSION_IS_DEV" -eq 1 ]; then
  123. echo "You are on the development branch and about to make a major or minor release."
  124. DO_PATCH_REL=0
  125. else
  126. echo "You are on the stable/backport branch and about to make a patch release."
  127. DO_PATCH_REL=1
  128. fi
  129. if [[ "$(prompt_for "Is this correct?" '[Yy][Ee][Ss]|[Nn][Oo]|' no)" != [Yy][Ee][Ss] ]]; then
  130. echo "Aborting"
  131. exit 1
  132. fi
  133. if [ "$DO_PATCH_REL" -eq 0 ]; then
  134. # On a regular release the version moves from 5.7.0-dev -> 5.7.0 (new tag) -> 5.8.0-dev
  135. old_proto=$(read_proto_ver origin/stable-5)
  136. new_proto=$(read_proto_ver HEAD)
  137. [ -n "$old_proto" ]
  138. [ -n "$new_proto" ]
  139. echo "Protocol versions: $old_proto (last release) -> $new_proto (now)"
  140. if [ "$new_proto" -le "$old_proto" ]; then
  141. echo "The protocol version has not been increased since last release, refusing to continue."
  142. exit 1
  143. fi
  144. set_dev_build 0
  145. perform_release "$CURRENT_VERSION"
  146. bump_version
  147. set_dev_build 1
  148. write_new_version
  149. back_to_devel
  150. else
  151. # On a patch release the version moves from 5.7.0 -> 5.7.1 (new tag)
  152. bump_version
  153. write_new_version
  154. perform_release "$NEXT_VERSION"
  155. fi