Skip to content

Commit

Permalink
Merge pull request #60 from sublimelsp/workflow/log_prelease_gracefully
Browse files Browse the repository at this point in the history
Workflow/log prelease gracefully
  • Loading branch information
TerminalFi authored Jun 23, 2023
2 parents 183119a + c9f647d commit f440571
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions scripts/compare_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import json
import os
from typing import Literal
from typing import Literal, Tuple

import urllib.request
from urllib.error import URLError
Expand All @@ -21,9 +21,9 @@ def get_tags(self) -> list:
print(f"Error while fetching tags from GitHub API: {e}")
exit(1)

def get_latest_version(self, tags: list) -> str:
def get_latest_version(self, tags: list) -> Tuple[str, bool]:
for tag in tags:
if tag["name"].startswith("gopls/v"):
if tag["tag_name"].startswith("gopls/v"):
unparsed_version = tag["name"].split("v")[1]
version = re.search(r"(\d+\.\d+\.\d+)-?(\w+\.\d+)?", unparsed_version)
if not version:
Expand All @@ -32,10 +32,10 @@ def get_latest_version(self, tags: list) -> str:

if version.group(2) is not None:
print(f'[get_latest_version] Version is {version.group(1)}-{version.group(2)}')
return f'{version.group(1)}-{version.group(2)}'
return f'{version.group(1)}-{version.group(2)}', True

print(f'[get_latest_version] Version is {version.group(1)}')
return version.group(1)
return version.group(1), False
print("[get_latest_version] Could not find latest version from tags.")
exit(1)

Expand Down Expand Up @@ -66,8 +66,13 @@ def compare_semantic_versions(self, v1: str, v2: str) -> Literal[0, 1]:

def check_for_update(self):
tags = self.get_tags()
latest_version = self.get_latest_version(tags)
latest_version, prelease = self.get_latest_version(tags)
local_version = self.get_version_locally()
if prelease:
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"REQUIRES_UPDATE=0", file=fh)
print(f"LATEST_VERSION={latest_version}", file=fh)
return

# Check if update is required
requires_update = self.compare_semantic_versions(local_version, latest_version)
Expand All @@ -79,5 +84,5 @@ def check_for_update(self):
print(f"BRANCH_NAME={branch_name}", file=fh)


url = "https://api.github.com/repos/golang/tools/tags"
url = "https://api.github.com/repos/golang/tools/releases"
VersionChecker(url=url).check_for_update()

0 comments on commit f440571

Please sign in to comment.