feat: add check action
This commit is contained in:
parent
ee1dcf4a21
commit
7d61f93ac1
4 changed files with 32 additions and 83 deletions
37
check.py
Normal file
37
check.py
Normal 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()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue