Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin should support increments even if version ends with alpha chars #15

Open
VenomVendor opened this issue Aug 7, 2018 · 2 comments
Labels
enhancement New feature or request needs 👍 +5 Need at least 5 thumbs up to be prioritised question Further information is requested

Comments

@VenomVendor
Copy link

Is your feature request related to a problem? Please describe.
According to Semantic Versioning 2.0.0 the below version patterns are valid.

  • 3.0.0-rc1
  • 3.0.0-rc.1
  • 3.0.0-beta1
  • 3.0.1-beta

The above versioning should be supported.

Expected Results

Current After Execution
3.0.0 3.0.1
3.0.0-rc1 3.0.0-rc2
3.0.0-rc.1 3.0.0-rc.2
3.0.0-beta1 3.0.0-beta2
3.0.0-beta 3.0.1-beta
@FranRiadigos FranRiadigos added enhancement New feature or request question Further information is requested labels Aug 7, 2018
@FranRiadigos
Copy link
Collaborator

Hi @VenomVendor, thanks for your feedback!

It's a good idea and I think projects will benefit from this suffix.

I started talking about it with @xvelx and I suggested to save the suffix as part of the created version tag as well.
We can add an extra option to the versioning { } block like tagSuffix where a developer can put a static string or a custom function that generates the expected value.

What do you think?

@VenomVendor
Copy link
Author

VenomVendor commented Aug 8, 2018

We should try to resolve without additional input from users.

Describe the solution you'd like

  • Split existing version by .
  • Incase of major/minor update, we can directly increment.
  • If patch, then split by digit \D+
    • reverse loop
    • increment first digit
    • break

Python Code

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re

# Current & Expected
version_map = {
    '0.0.29': '0.0.30',
    '2.0.0-rc.1': '2.0.0-rc.2',
    '0.0.22beta': '0.0.23beta',
    '0.0.22rc-1': '0.0.22rc-2',
    '0.0.22d1201': '0.0.22d1202'
}


def get_next_version(in_version):
    global remaining
    semantic = re.split("\.", in_version, 2)
    major = semantic[0]
    minor = semantic[1]

    increment_patch = True  # hardcoded runtime value.

    if len(semantic) > 2 and increment_patch:
        remaining = re.split('(\D+)', semantic[2])[::-1]

    for i, val in enumerate(remaining):
        if val.isdigit():
            remaining[i] = int(val) + 1
            break

    remaining = remaining[::-1]
    incremented_patch = ''.join(map(str, remaining))

    return "{}.{}.{}".format(major, minor, incremented_patch)


for current_version, next_version in version_map.items():
    actual_next_version = get_next_version(current_version)
    assert actual_next_version == next_version, \
        "Expected `{}`, but actual `{}`".format(next_version, actual_next_version)

print "All Tests passed."

@FranRiadigos FranRiadigos added the needs 👍 +5 Need at least 5 thumbs up to be prioritised label Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs 👍 +5 Need at least 5 thumbs up to be prioritised question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants