Skip to content

Commit

Permalink
fix dev.tools.publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdelsol committed Mar 7, 2024
1 parent ddc0821 commit f834404
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
18 changes: 9 additions & 9 deletions dev/tools/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ def __init__(self, build: CfgBuild, environments: CfgEnvironments, github: CfgGi
self.all_python_envs = PythonEnvs(environments).all
self.environments = environments

def publish(self, python_env: PythonEnv, version: str) -> None:
def publish(self, python_env: PythonEnv, version: str) -> bool:
exe = self.dist.installer_exe(python_env, version)
exe_str = str(exe.as_posix())
version = version or self.build.version
if url := self.release.create(python_env, version):
if update := AppUpdate.from_exe(url, exe, version):
self.app_latest_update.local_save(update, python_env.bitness)
print(Title("Publish update"), Ok(exe_str), Low(update.md5))
return
print(Warn("Publish update failed"), Ok(exe_str))
print(Title("Release"), Ok(exe.name), Low("-"), Low(update.md5), Low("-"), Low(repr_size(exe)))
return True
return False

def publish_all(self) -> bool:
args = Args().parse_args()
if not args.info:
version = args.version if args.version else self.build.version
published = True
for python_env in PythonEnvs(self.environments, args).asked:
self.publish(python_env, version)
return True
published &= self.publish(python_env, version)
return published
return False

def get_local_version(self, python_env: PythonEnv) -> Optional[Published]:
Expand Down Expand Up @@ -151,7 +151,7 @@ def _show_versions(self, publisheds: Iterator[Published], old: Sequence[Publishe
return all_publisheds

def show_versions(self) -> None:
print(Title("Online"), Ok("published updates"))
print(Title("Online"), Ok("published releases"))
online_versions = self._show_versions(self.get_online_versions())
print(Title("Locally"), Ok("published updates"))
print(Title("Locally"), Ok("published releases"))
self._show_versions(self.get_local_versions(), online_versions)
21 changes: 11 additions & 10 deletions dev/tools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from api_keys import GITHUB_TOKEN

from .env.envs import PythonEnv, PythonEnvs
from .utils.color import Low, Ok, Title, Warn
from .utils.dist import Dist, repr_size
from .utils.color import Ok, Title, Warn
from .utils.dist import Dist
from .utils.protocols import CfgBuild, CfgEnvironments, CfgGithub


Expand All @@ -36,14 +36,14 @@ def get(self, version: str) -> Optional[GitRelease]:
tag = f"{self.dist.build_name}.{version}"
try:
release = self.repo.get_release(tag)
print(Title("Update Release"), Ok(tag))
print(Title("Update Release"), Ok(tag), end=" ", flush=True)
except UnknownObjectException:
try:
release = self.repo.create_git_release(tag=tag, name=tag, message="", target_commitish="master")
print(Title("Create release"), Ok(tag))
print(Title("Create release"), Ok(tag), end=" ", flush=True)
except GithubException:
release = None
print(Warn("Can't create release"), Ok(tag))
print(Warn("Can't create release"), Ok(tag), end=" ", flush=True)
return release


Expand All @@ -55,22 +55,23 @@ def __init__(self, build: CfgBuild, environments: CfgEnvironments, github: CfgGi

def add_installer(self, python_env: PythonEnv, release: Optional[GitRelease], version: str) -> Optional[str]:
exe = self.dist.installer_exe(python_env, version)
print(Ok(f". {exe.name}"), end=" ", flush=True)
if not exe.is_file():
print(Warn(". Missing"), Low(str(exe.name)))
print(Warn(". Missing"))
return None
if not release:
print(Warn(". No release for"), Low(str(exe.name)))
print(Warn(". Has no release"))
return None
existing_assets = {Path(url := asset.browser_download_url).name: url for asset in release.get_assets()}
if url := existing_assets.get(exe.name):
print(Warn(". Already exists"), Low(str(exe.name)))
print(Warn(". Already exists"))
return None
try:
asset = release.upload_asset(path=str(exe.resolve()), name=exe.name)
print(Title(". Add"), Ok(str(exe.name)), Low(repr_size(exe)))
print(Title(". Added"))
return asset.browser_download_url
except GithubException:
print(Warn(". Can't upload"), Low(str(exe.name)))
print(Warn(". Can't upload"))
return None

def create(self, python_env: PythonEnv, version: str) -> Optional[str]:
Expand Down

0 comments on commit f834404

Please sign in to comment.