Use fallible version parsing for tags.

This corrects an error in Version construction for hotfix releases,
and makes parsing of tags more robust to error by ignoring tags that
do not conform to the standard Zcash patterns such as `v4.7.0-gitian`
and some of the tags from the upstream `bitcoin/bitcoin` repository.
This commit is contained in:
Kris Nuttycombe 2022-04-26 09:54:57 -06:00
parent 1b967fcae2
commit ed91377c20
1 changed files with 21 additions and 9 deletions

View File

@ -145,7 +145,9 @@ def verify_tags(releaseprev, releasefrom):
for tag in sh_out('git', 'tag', '--list').splitlines():
if candidatergx.match(tag):
candidates.append(Version.parse_arg(tag))
v = Version.parse(tag)
if v is not None:
candidates.append(v)
candidates.sort()
try:
@ -198,6 +200,7 @@ def verify_version(release, releaseprev, hotfix):
releaseprev.minor,
releaseprev.patch + 1,
releaseprev.betarc,
None
)
if release != expected:
raise SystemExit(
@ -225,7 +228,7 @@ def initialize_git(release, hotfix):
),
)
logging.info('Pulling to latest master.')
logging.info('Ensuring we are up to date with the branch to be released...')
sh_log('git', 'pull', '--ff-only')
branch = 'release-' + release.vtext
@ -487,15 +490,10 @@ class Version (object):
)
@staticmethod
def parse_arg(text):
def parse(text):
m = Version.RGX.match(text)
if m is None:
raise argparse.ArgumentTypeError(
'Could not parse version {!r} against regex {}'.format(
text,
Version.RGX.pattern,
),
)
return None
else:
[major, minor, patch, _, betarc, hyphen] = m.groups()
return Version(
@ -506,6 +504,19 @@ class Version (object):
int(hyphen) if hyphen is not None else None,
)
@staticmethod
def parse_arg(text):
v = Version.parse(text)
if v is None:
raise argparse.ArgumentTypeError(
'Could not parse version {!r} against regex {}'.format(
text,
Version.RGX.pattern,
),
)
else:
return v
def __init__(self, major, minor, patch, betarc, hyphen):
for i in [major, minor, patch]:
assert type(i) is int, i
@ -646,6 +657,7 @@ class TestVersion (unittest.TestCase):
'v07.0.0',
'v1.0.03',
'v1.2.3-0',
'v1.2.3-foobar',
'v1.2.3~0',
'v1.2.3+0',
'1.2.3',