update-python-libraries.py: Always use ref/tags/ for specifying rev

Avoids situations where a branch and tag share the same
label. Github will silently return a non-valid artifact and
will fail the build.

Since all github releases correspond to an annotated tag, it's
safe to assume that if we found a release for a tag, that the
tag will exist.
This commit is contained in:
Jonathan Ringer 2022-03-08 11:05:10 -08:00 committed by Martin Weinelt
parent 9cb1c5875d
commit 7f5915b048

View File

@ -356,17 +356,19 @@ def _update_package(path, target):
text = _replace_value('hash', sri_hash, text) text = _replace_value('hash', sri_hash, text)
if fetcher == 'fetchFromGitHub': if fetcher == 'fetchFromGitHub':
# in the case of fetchFromGitHub, it's common to see `rev = version;` # in the case of fetchFromGitHub, it's common to see `rev = version;` or `rev = "v${version}";`
# in which no string value is meant to be substituted. # in which no string value is meant to be substituted. However, we can just overwrite the previous value.
# Verify that the attribute is set to a variable regex = '(rev\s+=\s+[^;]*;)'
regex = '(rev\s+=\s+([_a-zA-Z][_a-zA-Z0-9\.]*);)'
regex = re.compile(regex) regex = re.compile(regex)
value = regex.findall(text) matches = regex.findall(text)
n = len(value) n = len(matches)
if n == 0: if n == 0:
# value is set to a string, e.g. `rev = "v${version}";` raise ValueError("Unable to find rev value for {}.".format(pname))
text = _replace_value('rev', f"{prefix}${{version}}", text) else:
# forcefully rewrite rev, incase tagging conventions changed for a release
match = matches[0]
text = text.replace(match, f'rev = "refs/tags/{prefix}${{version}}";')
# incase there's no prefix, just rewrite without interpolation # incase there's no prefix, just rewrite without interpolation
text = text.replace('"${version}";', 'version;') text = text.replace('"${version}";', 'version;')