Change the way we find the latest tag
We used to find the latest tag with git describe but it's not always
accurate because alpha, beta, or rc tags are not what we are looking
for. Instead, we find the the latest tag by parsing the current tag and
matching the list of all references against the pattern.
Test: updater.sh check python/cpython3
Change-Id: Ia8ab1848bc245ff5f94b4a75a97e030759544914
diff --git a/github_archive_updater.py b/github_archive_updater.py
index cb43d8a..a282cea 100644
--- a/github_archive_updater.py
+++ b/github_archive_updater.py
@@ -24,7 +24,6 @@
import git_utils
# pylint: disable=import-error
import updater_utils
-
GITHUB_URL_PATTERN: str = (r'^https:\/\/github.com\/([-\w]+)\/([-\w]+)\/' +
r'(releases\/download\/|archive\/)')
GITHUB_URL_RE: re.Pattern = re.compile(GITHUB_URL_PATTERN)
@@ -118,17 +117,13 @@
if current_remote_url is None:
git_utils.add_remote(self._proj_path, self.UPSTREAM_REMOTE_NAME, homepage)
- branch = git_utils.detect_default_branch(self._proj_path,
- self.UPSTREAM_REMOTE_NAME)
-
- git_utils.fetch(self._proj_path, self.UPSTREAM_REMOTE_NAME, branch)
+ git_utils.fetch(self._proj_path, self.UPSTREAM_REMOTE_NAME)
def _fetch_latest_tag(self) -> Tuple[str, List[str]]:
"""We want to avoid hitting GitHub API rate limit by using alternative solutions."""
- branch = git_utils.detect_default_branch(self._proj_path,
- self.UPSTREAM_REMOTE_NAME)
- tag = git_utils.get_most_recent_tag(
- self._proj_path, self.UPSTREAM_REMOTE_NAME + '/' + branch)
+ tags = git_utils.list_remote_tags(self._proj_path, self.UPSTREAM_REMOTE_NAME)
+ parsed_tags = [updater_utils.parse_remote_tag(tag) for tag in tags]
+ tag = updater_utils.get_latest_version(self._old_identifier.version, parsed_tags)
return tag, []
def _fetch_latest_version(self) -> None: