Files
AstrBot/scripts/release/release_constants_loader.py
T
エイカク 3d1c3946f6 feat(ci): add nightly prerelease release flow and updater support (#5744)
* feat: add nightly prerelease release flow and updater support

* feat(ci): auto-generate nightly release notes from latest stable tag

* fix(ci): correct nightly release notes heredoc YAML indentation

* fix(ci): align nightly notes heredoc terminator

* fix(ci): remove heredoc body indentation in nightly notes script

* fix: align nightly release metadata and prerelease rules

* fix: harden nightly release flow and updater release resolution

* fix: improve nightly branch resolution and updater logging

* fix: simplify updater target resolution and nightly release assets

* fix: avoid inputs lookup on non-dispatch release events

* fix: split nightly release fetch and simplify updater flow

* refactor: simplify updater target resolvers and nightly error checks

* fix: type release fetch errors and streamline updater resolution

* refactor: simplify updater target branching and release artifacts

* refactor: simplify release fetching and harden nightly git diagnostics

* fix: validate release payload shape before parsing

* refactor: harden prerelease handling and nightly constants

* refactor: derive archive urls and enrich fetch errors

* refactor: simplify update target resolution flow

* refactor: linearize update target resolution

* refactor: validate update target inputs and sync nightly tag source

* refactor: simplify updater mode resolution and prerelease tests

* refactor: simplify update target resolution flow

* fix: avoid package import when resolving nightly tag

* refactor: simplify updater resolution and centralize release constants

* fix: harden nightly release notes generation in workflow

* refactor: streamline update target resolution and errors

* refactor: simplify updater target resolution and nightly handling

* refactor: simplify updater errors and package release scripts

* refactor: centralize release api constants and loader

* fix(ci): resolve dispatch fallback tag from stable releases
2026-03-05 01:23:49 +09:00

61 lines
1.6 KiB
Python

from __future__ import annotations
import importlib.machinery
import importlib.util
from functools import lru_cache
from pathlib import Path
from types import ModuleType
def _constants_file() -> Path:
return (
Path(__file__).resolve().parents[2]
/ "astrbot"
/ "core"
/ "release_constants.py"
)
@lru_cache(maxsize=1)
def _release_constants_module() -> ModuleType:
constants_path = _constants_file()
module_name = "astrbot_core_release_constants_loader"
loader = importlib.machinery.SourceFileLoader(module_name, str(constants_path))
spec = importlib.util.spec_from_loader(module_name, loader)
if spec is None:
raise RuntimeError(f"Failed to load spec for {constants_path}")
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
def load_release_constants(*names: str) -> dict[str, str]:
module = _release_constants_module()
values: dict[str, str] = {}
missing: list[str] = []
for name in names:
value = getattr(module, name, None)
if not isinstance(value, str):
missing.append(name)
continue
value = value.strip()
if not value:
missing.append(name)
continue
values[name] = value
if missing:
missing_str = ", ".join(missing)
raise RuntimeError(
f"Failed to parse {missing_str} from astrbot/core/release_constants.py",
)
return values
def load_release_constant(name: str) -> str:
return load_release_constants(name)[name]