Skip to content

Commit

Permalink
Merge pull request #2837 from jaimergp/gh-releases
Browse files Browse the repository at this point in the history
Add a `GithubReleases` version provider
  • Loading branch information
beckermr authored Jul 15, 2024
2 parents 1d38942 + eadad40 commit e41d28e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions conda_forge_tick/update_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,36 @@ def get_url(self, meta_yaml) -> Optional[str]:
return f"https://github.com/{package_owner}/{gh_package_name}/releases.atom"


class GithubReleases(AbstractSource):
name = "GithubReleases"

def get_url(self, meta_yaml) -> Optional[str]:
if "github.com" not in meta_yaml["url"]:
return None
# might be namespaced
owner, repo = meta_yaml["url"].split("/")[3:5]
return f"https://github.com/{owner}/{repo}/releases/latest"

def get_version(self, url: str) -> Optional[str]:
r = requests.get(url)
if not r.ok:
return False
# "/releases/latest" redirects to "/releases/tag/<tag name>"
url_components = r.url.split("/")
latest = "/".join(url_components[url_components.index("releases") + 2 :])
# If it is a pre-release don't give back the pre-release version
if not len(latest) or latest == "latest" or parse_version(latest).is_prerelease:
return False
for prefix in ("v", "release-", "releases/"):
if latest.startswith(prefix):
latest = latest[len(prefix) :]
break
# Extract version number starting at the first digit.
if match := re.search(r"(\d+[^\s]*)", latest):
latest = match.group(0)
return latest


class LibrariesIO(VersionFromFeed):
name = "LibrariesIO"

Expand Down
2 changes: 2 additions & 0 deletions conda_forge_tick/update_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
NVIDIA,
AbstractSource,
Github,
GithubReleases,
IncrementAlphaRawURL,
PyPI,
RawURL,
Expand Down Expand Up @@ -417,6 +418,7 @@ def all_version_sources():
ROSDistro(),
RawURL(),
Github(),
GithubReleases(),
IncrementAlphaRawURL(),
NVIDIA(),
)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
NVIDIA,
AbstractSource,
Github,
GithubReleases,
PyPI,
RawURL,
next_version,
Expand Down Expand Up @@ -1257,6 +1258,7 @@ def test_update_upstream_versions_no_packages_to_update(
"ROSDistro",
"RawURL",
"Github",
"GithubReleases",
"IncrementAlphaRawURL",
"NVIDIA",
)
Expand Down Expand Up @@ -1694,3 +1696,25 @@ def test_github_version_prefix(url, version, version_prefix, tmpdir):
assert gh.version_prefix is None
else:
assert gh.version_prefix == version_prefix


@pytest.mark.parametrize(
"url, feedstock_version",
[
("https://github.com/spglib/spglib/archive/v2.3.0.tar.gz", "2.3.0"),
],
)
@flaky
def test_github_releases(tmpdir, url, feedstock_version):
meta_yaml = LazyJson(os.path.join(tmpdir, "cf-scripts-test.json"))
with meta_yaml as _meta_yaml:
_meta_yaml.update(
{
"version": feedstock_version,
"url": url,
}
)

ghr = GithubReleases()
url = ghr.get_url(meta_yaml)
assert VersionOrder(ghr.get_version(url)) > VersionOrder(feedstock_version)

0 comments on commit e41d28e

Please sign in to comment.