Add custom binary check-update support for artifacts

This commit is contained in:
crazywhalecc
2026-02-28 13:55:52 +08:00
parent ed5a516004
commit 40e36982d3
6 changed files with 111 additions and 2 deletions

View File

@@ -30,6 +30,9 @@ class Artifact
/** @var array<string, callable> Bind custom binary fetcher callbacks */
protected mixed $custom_binary_callbacks = [];
/** @var array<string, callable> Bind custom binary check-update callbacks */
protected array $custom_binary_check_update_callbacks = [];
/** @var null|callable Bind custom source extract callback (completely takes over extraction) */
protected mixed $source_extract_callback = null;
@@ -433,6 +436,24 @@ class Artifact
$this->custom_binary_callbacks[$target_os] = $callback;
}
/**
* Set custom binary check-update callback for a specific target OS.
*
* @param string $target_os Target OS platform string (e.g. linux-x86_64)
* @param callable $callback Custom binary check-update callback
*/
public function setCustomBinaryCheckUpdateCallback(string $target_os, callable $callback): void
{
ConfigValidator::validatePlatformString($target_os);
$this->custom_binary_check_update_callbacks[$target_os] = $callback;
}
public function getCustomBinaryCheckUpdateCallback(): ?callable
{
$current_platform = SystemTarget::getCurrentPlatformString();
return $this->custom_binary_check_update_callbacks[$current_platform] ?? null;
}
// ==================== Extraction Callbacks ====================
/**

View File

@@ -358,8 +358,13 @@ class ArtifactDownloader
/** @var CheckUpdateInterface $downloader */
$downloader = new $cls();
return $downloader->checkUpdate($artifact_name, $info['config'], $info['version'], $this);
}
throw new WrongUsageException("Artifact '{$artifact_name}' downloader does not support update checking, exit.");
} // custom binary: delegate to registered check-update callback
if (($callback = $artifact->getCustomBinaryCheckUpdateCallback()) !== null) {
return ApplicationContext::invoke($callback, [
ArtifactDownloader::class => $this,
'old_version' => $info['version'],
]);
} throw new WrongUsageException("Artifact '{$artifact_name}' downloader does not support update checking, exit.");
}
public function getRetry(): int