feat: improve updater flow and release channels
Some checks failed
Desktop Dev Pre-release / prerelease (push) Failing after 2m18s
Some checks failed
Desktop Dev Pre-release / prerelease (push) Failing after 2m18s
- added dedicated GUI updater executable and integrated launch path from main app - added stable/beta update channel selection with persisted settings and checker support - expanded CI/release validation to include updater and full test discovery
This commit is contained in:
@@ -104,12 +104,26 @@ class AutoUpdateService:
|
||||
"if %ERRORLEVEL% EQU 0 (",
|
||||
" set /a WAIT_LOOPS+=1",
|
||||
" if %WAIT_LOOPS% GEQ 180 (",
|
||||
" echo Timeout waiting for process %TARGET_PID% to exit >> \"%UPDATE_LOG%\"",
|
||||
" goto :backup",
|
||||
" echo Timeout waiting for process %TARGET_PID%, attempting force stop >> \"%UPDATE_LOG%\"",
|
||||
" taskkill /PID %TARGET_PID% /T /F >nul 2>&1",
|
||||
" timeout /t 2 /nobreak >nul",
|
||||
" tasklist /FI \"PID eq %TARGET_PID%\" | find \"%TARGET_PID%\" >nul",
|
||||
" if %ERRORLEVEL% EQU 0 goto :pid_still_running",
|
||||
" goto :wait_image_unlock",
|
||||
" )",
|
||||
" timeout /t 1 /nobreak >nul",
|
||||
" goto :wait_for_exit",
|
||||
")",
|
||||
":wait_image_unlock",
|
||||
"set /a IMG_LOOPS=0",
|
||||
":check_image",
|
||||
"tasklist /FI \"IMAGENAME eq %EXE_NAME%\" | find /I \"%EXE_NAME%\" >nul",
|
||||
"if %ERRORLEVEL% EQU 0 (",
|
||||
" set /a IMG_LOOPS+=1",
|
||||
" if %IMG_LOOPS% GEQ 60 goto :image_still_running",
|
||||
" timeout /t 1 /nobreak >nul",
|
||||
" goto :check_image",
|
||||
")",
|
||||
":backup",
|
||||
"timeout /t 1 /nobreak >nul",
|
||||
"mkdir \"%BACKUP_DIR%\" >nul 2>&1",
|
||||
@@ -134,6 +148,12 @@ class AutoUpdateService:
|
||||
":backup_error",
|
||||
"echo Auto-update failed during backup. Code %RC% >> \"%UPDATE_LOG%\"",
|
||||
"exit /b %RC%",
|
||||
":pid_still_running",
|
||||
"echo Auto-update aborted: process %TARGET_PID% is still running after force stop. >> \"%UPDATE_LOG%\"",
|
||||
"exit /b 4",
|
||||
":image_still_running",
|
||||
"echo Auto-update aborted: %EXE_NAME% still running and file lock may remain. >> \"%UPDATE_LOG%\"",
|
||||
"exit /b 5",
|
||||
]
|
||||
with open(script_path, "w", encoding="utf-8", newline="\r\n") as f:
|
||||
f.write("\r\n".join(script_lines) + "\r\n")
|
||||
@@ -152,6 +172,40 @@ class AutoUpdateService:
|
||||
creationflags=creation_flags,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def launch_gui_updater(app_exe, source_dir, work_dir, target_pid, version=""):
|
||||
app_dir = os.path.dirname(app_exe)
|
||||
exe_name = os.path.basename(app_exe)
|
||||
updater_exe = os.path.join(app_dir, "AnabasisUpdater.exe")
|
||||
if not os.path.exists(updater_exe):
|
||||
raise RuntimeError("Файл AnabasisUpdater.exe не найден в папке приложения.")
|
||||
|
||||
creation_flags = 0
|
||||
if hasattr(subprocess, "CREATE_NEW_PROCESS_GROUP"):
|
||||
creation_flags |= subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
if hasattr(subprocess, "DETACHED_PROCESS"):
|
||||
creation_flags |= subprocess.DETACHED_PROCESS
|
||||
|
||||
subprocess.Popen(
|
||||
[
|
||||
updater_exe,
|
||||
"--app-dir",
|
||||
app_dir,
|
||||
"--source-dir",
|
||||
source_dir,
|
||||
"--exe-name",
|
||||
exe_name,
|
||||
"--target-pid",
|
||||
str(target_pid),
|
||||
"--version",
|
||||
str(version or ""),
|
||||
"--work-dir",
|
||||
str(work_dir or ""),
|
||||
],
|
||||
cwd=work_dir,
|
||||
creationflags=creation_flags,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def prepare_update(cls, download_url, checksum_url, download_name):
|
||||
work_dir = tempfile.mkdtemp(prefix="anabasis_update_")
|
||||
|
||||
@@ -38,6 +38,75 @@ def _sanitize_repo_url(value):
|
||||
return f"{parsed.scheme}://{parsed.netloc}{clean_path}"
|
||||
|
||||
|
||||
def _normalize_update_channel(value):
|
||||
channel = (value or "").strip().lower()
|
||||
if channel in ("beta", "betas", "pre", "prerelease", "pre-release"):
|
||||
return "beta"
|
||||
return "stable"
|
||||
|
||||
|
||||
def _select_release_from_list(releases):
|
||||
for item in releases:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
if item.get("draft"):
|
||||
continue
|
||||
tag_name = (item.get("tag_name") or item.get("name") or "").strip()
|
||||
if not tag_name:
|
||||
continue
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
def _extract_release_payload(release_data, repository_url, current_version):
|
||||
parsed = urlparse(repository_url)
|
||||
base_url = f"{parsed.scheme}://{parsed.netloc}"
|
||||
repo_path = parsed.path.strip("/")
|
||||
releases_url = f"{base_url}/{repo_path}/releases"
|
||||
|
||||
latest_tag = release_data.get("tag_name") or release_data.get("name") or ""
|
||||
latest_version = latest_tag.lstrip("vV").strip()
|
||||
html_url = release_data.get("html_url") or releases_url
|
||||
assets = release_data.get("assets") or []
|
||||
download_url = ""
|
||||
download_name = ""
|
||||
checksum_url = ""
|
||||
for asset in assets:
|
||||
url = asset.get("browser_download_url", "")
|
||||
if url.lower().endswith(".zip"):
|
||||
download_url = url
|
||||
download_name = asset.get("name", "")
|
||||
break
|
||||
if not download_url and assets:
|
||||
download_url = assets[0].get("browser_download_url", "")
|
||||
download_name = assets[0].get("name", "")
|
||||
|
||||
for asset in assets:
|
||||
name = asset.get("name", "").lower()
|
||||
if not name:
|
||||
continue
|
||||
is_checksum_asset = name.endswith(".sha256") or name.endswith(".sha256.txt") or name in ("checksums.txt", "sha256sums.txt")
|
||||
if not is_checksum_asset:
|
||||
continue
|
||||
if download_name and (download_name.lower() in name or name in (f"{download_name.lower()}.sha256", f"{download_name.lower()}.sha256.txt")):
|
||||
checksum_url = asset.get("browser_download_url", "")
|
||||
break
|
||||
if not checksum_url:
|
||||
checksum_url = asset.get("browser_download_url", "")
|
||||
|
||||
return {
|
||||
"repository_url": repository_url,
|
||||
"latest_version": latest_version,
|
||||
"current_version": current_version,
|
||||
"latest_tag": latest_tag,
|
||||
"release_url": html_url,
|
||||
"download_url": download_url,
|
||||
"download_name": download_name,
|
||||
"checksum_url": checksum_url,
|
||||
"has_update": _is_newer_version(latest_version, current_version),
|
||||
}
|
||||
|
||||
|
||||
def detect_update_repository_url(configured_url="", configured_repo=""):
|
||||
env_url = _sanitize_repo_url(os.getenv("ANABASIS_UPDATE_URL", ""))
|
||||
if env_url:
|
||||
@@ -74,11 +143,12 @@ class UpdateChecker(QObject):
|
||||
check_finished = Signal(dict)
|
||||
check_failed = Signal(str)
|
||||
|
||||
def __init__(self, repository_url, current_version, request_timeout=8):
|
||||
def __init__(self, repository_url, current_version, request_timeout=8, channel="stable"):
|
||||
super().__init__()
|
||||
self.repository_url = repository_url
|
||||
self.current_version = current_version
|
||||
self.request_timeout = request_timeout
|
||||
self.channel = _normalize_update_channel(channel)
|
||||
|
||||
def run(self):
|
||||
if not self.repository_url:
|
||||
@@ -92,10 +162,17 @@ class UpdateChecker(QObject):
|
||||
self.check_failed.emit("Некорректный URL репозитория обновлений.")
|
||||
return
|
||||
|
||||
use_beta_channel = self.channel == "beta"
|
||||
if parsed.netloc.lower().endswith("github.com"):
|
||||
api_url = f"https://api.github.com/repos/{repo_path}/releases/latest"
|
||||
if use_beta_channel:
|
||||
api_url = f"https://api.github.com/repos/{repo_path}/releases"
|
||||
else:
|
||||
api_url = f"https://api.github.com/repos/{repo_path}/releases/latest"
|
||||
else:
|
||||
api_url = f"{base_url}/api/v1/repos/{repo_path}/releases/latest"
|
||||
if use_beta_channel:
|
||||
api_url = f"{base_url}/api/v1/repos/{repo_path}/releases"
|
||||
else:
|
||||
api_url = f"{base_url}/api/v1/repos/{repo_path}/releases/latest"
|
||||
releases_url = f"{base_url}/{repo_path}/releases"
|
||||
request = urllib.request.Request(
|
||||
api_url,
|
||||
@@ -106,7 +183,7 @@ class UpdateChecker(QObject):
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=self.request_timeout) as response:
|
||||
release_data = json.loads(response.read().decode("utf-8"))
|
||||
response_data = json.loads(response.read().decode("utf-8"))
|
||||
except urllib.error.HTTPError as e:
|
||||
self.check_failed.emit(f"Ошибка HTTP при проверке обновлений: {e.code}")
|
||||
return
|
||||
@@ -117,47 +194,20 @@ class UpdateChecker(QObject):
|
||||
self.check_failed.emit(f"Не удалось проверить обновления: {e}")
|
||||
return
|
||||
|
||||
latest_tag = release_data.get("tag_name") or release_data.get("name") or ""
|
||||
latest_version = latest_tag.lstrip("vV").strip()
|
||||
html_url = release_data.get("html_url") or releases_url
|
||||
assets = release_data.get("assets") or []
|
||||
download_url = ""
|
||||
download_name = ""
|
||||
checksum_url = ""
|
||||
for asset in assets:
|
||||
url = asset.get("browser_download_url", "")
|
||||
if url.lower().endswith(".zip"):
|
||||
download_url = url
|
||||
download_name = asset.get("name", "")
|
||||
break
|
||||
if not download_url and assets:
|
||||
download_url = assets[0].get("browser_download_url", "")
|
||||
download_name = assets[0].get("name", "")
|
||||
|
||||
for asset in assets:
|
||||
name = asset.get("name", "").lower()
|
||||
if not name:
|
||||
continue
|
||||
is_checksum_asset = name.endswith(".sha256") or name.endswith(".sha256.txt") or name in ("checksums.txt", "sha256sums.txt")
|
||||
if not is_checksum_asset:
|
||||
continue
|
||||
if download_name and (download_name.lower() in name or name in (f"{download_name.lower()}.sha256", f"{download_name.lower()}.sha256.txt")):
|
||||
checksum_url = asset.get("browser_download_url", "")
|
||||
break
|
||||
if not checksum_url:
|
||||
checksum_url = asset.get("browser_download_url", "")
|
||||
|
||||
self.check_finished.emit(
|
||||
{
|
||||
"repository_url": self.repository_url,
|
||||
"latest_version": latest_version,
|
||||
"current_version": self.current_version,
|
||||
"latest_tag": latest_tag,
|
||||
"release_url": html_url,
|
||||
"download_url": download_url,
|
||||
"download_name": download_name,
|
||||
"checksum_url": checksum_url,
|
||||
"has_update": _is_newer_version(latest_version, self.current_version),
|
||||
}
|
||||
)
|
||||
release_data = response_data
|
||||
if use_beta_channel:
|
||||
if not isinstance(response_data, list):
|
||||
self.check_failed.emit("Сервер вернул некорректный ответ списка релизов.")
|
||||
return
|
||||
release_data = _select_release_from_list(response_data)
|
||||
if not release_data:
|
||||
self.check_failed.emit("В канале beta не найдено доступных релизов.")
|
||||
return
|
||||
elif not isinstance(response_data, dict):
|
||||
self.check_failed.emit("Сервер вернул некорректный ответ релиза.")
|
||||
return
|
||||
|
||||
payload = _extract_release_payload(release_data, self.repository_url, self.current_version)
|
||||
payload["release_channel"] = self.channel
|
||||
payload["releases_url"] = releases_url
|
||||
self.check_finished.emit(payload)
|
||||
|
||||
Reference in New Issue
Block a user