From 9f0d88407d9dadb1a8cf8c03131eda034f2f19e1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 21 Oct 2022 17:09:44 +0200 Subject: [PATCH] Revise bump_version.sh script to address shortcomings (#12789) --- CMakeLists.txt | 2 +- util/bump_version.sh | 294 ++++++++++++++++++++++++++++--------------- 2 files changed, 191 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4ecda37b..9f788c30d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(GCC_MINIMUM_VERSION "5.1") set(CLANG_MINIMUM_VERSION "3.5") -# Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing +# You should not need to edit these manually, use util/bump_version.sh set(VERSION_MAJOR 5) set(VERSION_MINOR 7) set(VERSION_PATCH 0) diff --git a/util/bump_version.sh b/util/bump_version.sh index 271886d68..909e94a1b 100755 --- a/util/bump_version.sh +++ b/util/bump_version.sh @@ -1,144 +1,230 @@ #!/bin/bash -e -prompt_for_number() { +prompt_for() { local prompt_text=$1 - local default_value=$2 - local tmp="" + local pattern=$2 + local default_value=$3 + local tmp= while true; do read -p "$prompt_text [$default_value]: " tmp - if [ "$tmp" = "" ]; then + if [ -z "$tmp" ]; then echo "$default_value"; return - elif echo "$tmp" | grep -q -E '^[0-9]+$'; then + elif echo "$tmp" | grep -qE "^(${pattern})\$"; then echo "$tmp"; return fi done } -# On a release the following actions are performed -# * DEVELOPMENT_BUILD is set to false -# * android versionCode is bumped -# * appdata release version and date are updated -# * Commit the changes -# * Tag with current version -perform_release() { - RELEASE_DATE=$(date +%Y-%m-%d) +# Reads current versions +# out: VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_IS_DEV CURRENT_VERSION ANDROID_VERSION_CODE +read_versions() { + VERSION_MAJOR=$(grep -oE '^set\(VERSION_MAJOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) + VERSION_MINOR=$(grep -oE '^set\(VERSION_MINOR [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) + VERSION_PATCH=$(grep -oE '^set\(VERSION_PATCH [0-9]+\)$' CMakeLists.txt | tr -dC 0-9) + VERSION_IS_DEV=$(grep -oE '^set\(DEVELOPMENT_BUILD [A-Z]+\)$' CMakeLists.txt) + ANDROID_VERSION_CODE=$(grep -oE '\("versionCode", [0-9]+\)' android/build.gradle | tr -dC 0-9) - sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt + # Make sure they all exist + [ -n "$VERSION_MAJOR" ] + [ -n "$VERSION_MINOR" ] + [ -n "$VERSION_PATCH" ] + [ -n "$VERSION_IS_DEV" ] + [ -n "$ANDROID_VERSION_CODE" ] - sed -i 's/project.ext.set("versionExtra", "-dev")/project.ext.set("versionExtra", "")/' android/build.gradle - sed -i 's/project.ext.set("developmentBuild", 1)/project.ext.set("developmentBuild", 0)/' android/build.gradle - sed -i -re "s/\"versionCode\", [0-9]+/\"versionCode\", $NEW_ANDROID_VERSION_CODE/" android/build.gradle + if echo "$VERSION_IS_DEV" | grep -q ' TRUE'; then + VERSION_IS_DEV=1 + else + VERSION_IS_DEV=0 + fi + CURRENT_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" - sed -i '/\ 5.7.0 (new tag) -> 5.8.0-dev -if [ "$NEXT_VERSION_MINOR" != "$VERSION_MINOR" ]; then - NEXT_VERSION_PATCH=0 + old_proto=$(read_proto_ver origin/stable-5) + new_proto=$(read_proto_ver HEAD) + [ -n "$old_proto" ] + [ -n "$new_proto" ] + echo "Protocol versions: $old_proto (last release) -> $new_proto (now)" + if [ "$new_proto" -le "$old_proto" ]; then + echo "The protocol version has not been increased since last release, refusing to continue." + exit 1 + fi + + bump_android_ver + write_android_version + set_dev_build 0 + + perform_release "$CURRENT_VERSION" + + bump_version + set_dev_build 1 + write_new_version + + back_to_devel +else + # On a patch release the version moves from 5.7.0 -> 5.7.1 (new tag) + + bump_android_ver + write_android_version + bump_version + write_new_version + + perform_release "$NEXT_VERSION" fi - -NEXT_VERSION_PATCH=$(prompt_for_number "Set next patch" $NEXT_VERSION_PATCH) - -NEXT_VERSION="$NEXT_VERSION_MAJOR.$NEXT_VERSION_MINOR.$NEXT_VERSION_PATCH" - -echo -echo "New version: $NEXT_VERSION" - -######################## -# Return back to devel -######################## - -back_to_devel