c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 134 forks source link

Versioning an Android application #253

Open deliberist opened 2 years ago

deliberist commented 2 years ago

Has there been any thought as to how bump2version can be used to change the version of an Android project?

Typically an Android project has a <repo>/app/build.gradle file that has something like:

android {
    defaultConfig {
        versionCode 1
        versionName "1.0"
    }
}

Where android.defaultConfig.versionCode is basically a one-up counter, and android.defaultConfig.versionName usually follows the form {major}.{minor} (rarely does it have a patch element) -- per the Android versioning documentation.

I have not yet tested it, but I believe bump2version should be able to handle versionName (major.minor) but I do not know how it can handle versionCode (one-up counter), if it even could. Initially I would write a config with:

[bumpversion]
current_version = 1.0
commit = True
tag = True
tag_name = v{new_version}
message = Bump version: {current_version} → {new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)
serialize = {major}.{minor}

# The versionCode is a one-up counter.
[bumpversion:file (versionCode):app/build.gradle]
search = versionCode {current_version}
replace = versionCode {new_version}

# The versionName is a {major}.{minor} pair.
[bumpversion:file (versionName):app/build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

But this won't work for versionCode. Any idea how I can finagle something into versionCode to be consistent with how it is normally handled by Android?

olutra commented 1 year ago

This should work:

[bumpversion]
current_version = 1.0
parse = (?P<major>\d+).(?P<minor>\d+)
serialize = 
    {major}.{minor}

[bumpversion:file (versionName):build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

[bumpversion:file (versionCode):build.gradle]
serialize = 
    {major}
search = versionCode {current_version}
replace = versionCode {new_version}
deliberist commented 1 year ago

This should work:

[bumpversion]
current_version = 1.0
parse = (?P<major>\d+).(?P<minor>\d+)
serialize = 
  {major}.{minor}

[bumpversion:file (versionName):build.gradle]
search = versionName "{current_version}"
replace = versionName "{new_version}"

[bumpversion:file (versionCode):build.gradle]
serialize = 
  {major}
search = versionCode {current_version}
replace = versionCode {new_version}

@Maccheroni I do not believe that will work. It will only set versionCode to the major version. The major version (and versionCode in that sample) does not increment when there are minor releases.

If hypothetically we released an Android application starting with 1.0 we'd want to maintain versionName and versionCode consistent with Android conventions:

Bumpversion, as it stands, does not have a way to get a handle on what Android apps need as the versionCode.

Hope that makes sense.

olutra commented 1 year ago

@rbprogrammer the unreleased version 1.0.2-dev has a configuration option indepenent for a part. By default when parent part is bumped, children part is set to its first value, and if part is independent, it retains the previous value. If I understand correctly, you want the part to increment every time the parent part changes.

I added configuration option _alwaysincrement in my fork https://github.com/olutra/bump2version/tree/feature-always-increment You can try to install it with pip install git+https://github.com/olutra/bump2version.git@feature-always-increment and test with config like

[bumpversion]
current_version = '15.4#19'
parse = '(?P<major>\d+).(?P<minor>\d+)\#(?P<counter>\d+)'
serialize = '{major}.{minor}#{counter}'
[bumpversion:file (versionName):build.gradle]
serialize = {major}.{minor}
search = versionName "{current_version}"
replace = versionName "{new_version}"
[bumpversion:file (versionCode):build.gradle]
serialize = {counter}
search = versionCode {current_version}
replace = versionCode {new_version}
[bumpversion:part:counter]
always_increment = True