修复并调整构建产物的生命周期
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-28 00:35:03 +08:00
parent 4bfcc9b41c
commit 7d0d53bead
2 changed files with 20 additions and 7 deletions

View File

@ -50,7 +50,14 @@ class ArtifactDepends:
tasks = set()
for f in self.callbacks:
tasks.add(f(downloaded))
return await asyncio.gather(*tasks, return_exceptions=True)
result = await asyncio.gather(*tasks, return_exceptions=True)
for r in result:
if isinstance(r, BaseException):
logger.warning("完成了二进制文件的下载,但是有未捕捉的错误")
logger.exception(r)
return result
class Config(BaseModel):
@ -73,12 +80,7 @@ async def _():
async def _task(artifact: ArtifactDepends):
async with semaphore:
downloaded = await ensure_artifact(artifact)
result = await artifact._finished(downloaded)
for r in result:
if isinstance(r, BaseException):
logger.warning("完成了二进制文件的下载,但是有未捕捉的错误")
logger.exception(r)
await ensure_artifact(artifact)
tasks: set[asyncio.Task] = set()
for a in artifact_list:
@ -116,9 +118,16 @@ async def download_artifact(artifact: ArtifactDepends):
f"下载到的二进制的 sha256 与需求不同 TARGET={artifact.target} REQUESTED={artifact.sha256} ACTUAL={m.hexdigest()}"
)
await artifact._finished(True)
async def ensure_artifact(artifact: ArtifactDepends) -> bool:
"""
确保所需的二进制存在。返回是否下载了这个二进制文件。
"""
if not artifact.is_corresponding_platform():
logger.debug(f"所需求的平台不是当前平台,跳过二进制下载 artifact={artifact}")
return False
if not artifact.target.exists():
@ -136,6 +145,7 @@ async def ensure_artifact(artifact: ArtifactDepends) -> bool:
artifact.target.unlink()
await download_artifact(artifact)
return True
await artifact._finished(False)
return False

View File

@ -41,6 +41,7 @@ bin_path: Path | None = None
@arti_typst_linux.on_finished
async def _(downloaded: bool):
logger.debug("安装好了 Linux 版本的 Typst")
global bin_path
tar_path = arti_typst_linux.target
@ -71,6 +72,7 @@ async def _(downloaded: bool):
@arti_typst_windows.on_finished
async def _(downloaded: bool):
logger.debug("安装好了 Windows 版本的 Typst")
global bin_path
zip_path = arti_typst_windows.target
bin_path = BINARY_PATH / "typst.exe"
@ -160,6 +162,7 @@ async def _(
# 对于本地机器,一般不会在应用启动时自动下载,这里再保证存在
await ensure_artifact(arti_typst_linux)
await ensure_artifact(arti_typst_windows)
if bin_path is None or not bin_path.exists():
logger.warning("当前环境不存在 Typst但仍然调用了")
return