feat: add check before building

This commit is contained in:
Oskar Manhart 2025-05-17 13:59:43 +02:00
parent 5414c19122
commit d39cc8c1c7
3 changed files with 88 additions and 3 deletions

View file

@ -0,0 +1,37 @@
#/usr/bin/env python3
import os
import re
import sys
import requests
def get_github_version(repository: str) -> str:
res = requests.get(f"https://api.github.com/repos/{repository}/releases/latest").json()
return res["tag_name"].removeprefix("v")
def does_pypi_version_exist(base_url: str, package: str, version: str) -> bool:
base_url = base_url.removesuffix("/")
version = version.replace(".", "\\.")
body = requests.get(f"{base_url}/simple/{package}").text
return len(re.findall(rf"<a href=\".+\">{package}-{version}-.+</a>", body, re.MULTILINE)) > 0
def main():
repository = os.environ["REPOSITORY"]
package = os.environ["PACKAGE"]
base_url = os.environ["FORGEJO_URL"]
version = get_github_version(repository)
if does_pypi_version_exist(base_url, package, version):
sys.exit(0)
print(f"version=v{version}")
if __name__ == "__main__":
main()