bump_version.sh 5.8 KB

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