add .post support to rpm/deb version munger (#42444)

(cherry picked from commit a2bc0129f0)
This commit is contained in:
Matt Davis 2018-07-08 21:45:34 -07:00 committed by Matt Clay
parent bcd724d05c
commit 0f3a22cb13
2 changed files with 22 additions and 10 deletions

View file

@ -9,6 +9,7 @@ from versionhelper.version_helper import AnsibleVersionMunger
@pytest.mark.parametrize('version,revision,codename,output_propname,expected', [
('2.5.0.dev1', None, None, 'raw', '2.5.0.dev1'),
('2.5.0a0.post0', None, None, 'raw', '2.5.0a0.post0'),
('2.5.0', None, None, 'raw', '2.5.0'),
('2.5.0.dev1', None, None, 'major_version', '2.5'),
('2.5.0', None, None, 'major_version', '2.5'),
@ -17,11 +18,13 @@ from versionhelper.version_helper import AnsibleVersionMunger
('2.5.0.dev1', None, None, 'deb_version', '2.5.0~dev1'),
('2.5.0b1', None, None, 'deb_version', '2.5.0~b1'),
('2.5.0b1.dev1', None, None, 'deb_version', '2.5.0~b1~dev1'),
('2.5.0b1.post0', None, None, 'deb_version', '2.5.0~b1~post0'),
('2.5.0', None, None, 'deb_version', '2.5.0'),
('2.5.0.dev1', None, None, 'deb_release', '1'),
('2.5.0b1', 2, None, 'deb_release', '2'),
('2.5.0.dev1', None, None, 'rpm_release', '0.1.dev1'),
('2.5.0a1', None, None, 'rpm_release', '0.101.a1'),
('2.5.0a1.post0', None, None, 'rpm_release', '0.101.a1.post0'),
('2.5.0b1', None, None, 'rpm_release', '0.201.b1'),
('2.5.0rc1', None, None, 'rpm_release', '0.1001.rc1'),
('2.5.0rc1', '0.99', None, 'rpm_release', '0.99.rc1'),

View file

@ -31,21 +31,25 @@ class AnsibleVersionMunger(object):
match = self._parsed_regex_match
# treat dev as prerelease for now
if v.is_prerelease or match.group('dev'):
# treat dev/post as prerelease for now; treat dev/post as equivalent and disallow together
if v.is_prerelease or match.group('dev') or match.group('post'):
if match.group('dev') and match.group('post'):
raise Exception("dev and post may not currently be used together")
if match.group('pre'):
tag_value = match.group('pre')
tag_type = match.group('pre_l')
if match.group('dev'):
tag_value += ('~%s' % match.group('dev').strip('.'))
if match.group('post'):
tag_value += ('~%s' % match.group('post').strip('.'))
elif match.group('dev'):
tag_type = "dev"
tag_value = match.group('dev').strip('.')
elif match.group('post'):
tag_type = "dev"
tag_value = match.group('post').strip('.')
else:
raise Exception("unknown prerelease type for version {0}".format(self._raw_version))
elif v.is_postrelease:
raise Exception("post-release identifiers are not supported")
else:
tag_type = None
tag_value = ''
@ -66,23 +70,28 @@ class AnsibleVersionMunger(object):
v = self._parsed_version
match = self._parsed_regex_match
# treat presence of dev as prerelease for now
if v.is_prerelease or match.group('dev'):
# treat presence of dev/post as prerelease for now; treat dev/post the same and disallow together
if v.is_prerelease or match.group('dev') or match.group('post'):
if match.group('dev') and match.group('post'):
raise Exception("dev and post may not currently be used together")
if match.group('pre'):
tag_value = match.group('pre')
tag_type = match.group('pre_l')
tag_ver = match.group('pre_n')
if match.group('dev'):
tag_value += match.group('dev')
if match.group('post'):
tag_value += match.group('post')
elif match.group('dev'):
tag_type = "dev"
tag_value = match.group('dev')
tag_ver = match.group('dev_n')
elif match.group('post'):
tag_type = "dev"
tag_value = match.group('post')
tag_ver = match.group('post_n')
else:
raise Exception("unknown prerelease type for version {0}".format(self._raw_version))
elif v.is_postrelease:
raise Exception("post-release identifiers are not supported")
else:
tag_type = None
tag_value = ''