fixed # 将资源文件迁移到Service仓库中

This commit is contained in:
2026-10-26 18:53:41 +08:00
parent e5ec38e9d9
commit e7c6eac07f
34 changed files with 1335 additions and 52 deletions
+13 -6
View File
@@ -3,8 +3,14 @@
import hashlib
import json
from pathlib import Path
import sys
from zipfile import ZipFile
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'src'))
from farm_core.catalogue_release import parse_manifest
from farm_render.catalogue_bundle import ROOTS
def check(root):
data = Path(root) / 'src/farm_render/data'
@@ -19,12 +25,13 @@ def check(root):
with ZipFile(bundle) as archive:
if set(archive.namelist()) != set(metadata['images']):
raise ValueError('Asset manifest and layout differ')
for source, prefix in (
('github', 'https://raw.githubusercontent.com/Shu-Ying/'
'farm_service/main/assets/assets.zip'),
('gitea', 'https://gitea.diuse.work/Diuse/farm_service/'
'raw/branch/main/assets/assets.zip'),
):
bootstrap = parse_manifest((Path(root) / 'src/farm_core/data/'
'catalogue-manifest.json').read_bytes())
if manifest.get('catalogue_release') != bootstrap['release']:
raise ValueError('Bootstrap and asset release differ')
for name, base in ROOTS.items():
source = name.lower()
prefix = base + '/releases/' + bootstrap['release'] + '/assets.zip'
if manifest['sources'][source] != prefix:
raise ValueError('Asset source must use service repository')
print('Verified external asset manifest and development ZIP')
+27
View File
@@ -0,0 +1,27 @@
"""CI只核对插件初始版本自身,不访问远端或相邻Service开发仓库。"""
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'src'))
from farm_core.catalogue_release import parse_manifest
from farm_render.catalogue_bundle import _validate
def check(root=ROOT):
root = Path(root)
core = root / 'src/farm_core/data'
render = root / 'src/farm_render/data'
manifest = parse_manifest((core / 'catalogue-manifest.json').read_bytes())
content = {'plants.json': (core / 'plants.json').read_bytes(),
**{name: (render / name).read_bytes() for name in (
'metadata.json', 'assets.zip', 'land-soils.zip',
)}}
_validate(content, manifest, None, ())
print('Verified independent catalogue bootstrap ' + manifest['release'])
if __name__ == '__main__':
check()
+12 -2
View File
@@ -37,14 +37,24 @@ def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--source", type=Path,
default=root / "legacy/zhenxun_plugin_farm/resource/db/plant.db",
default=None,
)
parser.add_argument(
"--output", type=Path,
default=root / "src/farm_core/data/plants.json",
default=None,
)
parser.add_argument("--check", action="store_true")
parser.add_argument('--legacy-reference', action='store_true')
args = parser.parse_args()
if args.check and args.source is None:
from check_catalogue_bootstrap import check
check(root)
return
if not args.legacy_reference or args.output is None:
parser.error('Daily updates use sync_catalogue_bootstrap.py; '
'legacy export requires --legacy-reference --output')
if args.source is None:
args.source = root / 'legacy/zhenxun_plugin_farm/resource/db/plant.db'
content = export(args.source)
if args.check:
if not args.output.is_file() or args.output.read_bytes() != content:
+14 -4
View File
@@ -119,9 +119,10 @@ def export(root):
) for theme in ("default", "spring", "summer", "autumn", "winter", "bee")]
paths += list((source / "background/decorateIcon").glob("decorate_*.png"))
layout = json.loads((legacy / "config/soil.json").read_bytes())
catalogue = json.loads((
root / "src/farm_core/data/plants.json"
).read_bytes())
from export_catalogue import export as export_legacy_catalogue
catalogue = json.loads(export_legacy_catalogue(
legacy / 'resource/db/plant.db',
))
metadata = {
"schema": 1, "canvas": [3072, 1872], "soil_size": layout["size"],
"positions": [layout["soil"][str(i)] for i in range(1, 31)],
@@ -188,10 +189,19 @@ def main():
root = Path(__file__).resolve().parents[1]
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true")
parser.add_argument('--legacy-reference', action='store_true')
parser.add_argument('--output', type=Path)
args = parser.parse_args()
if args.check and not args.legacy_reference:
from check_catalogue_bootstrap import check
check(root)
return
if not args.legacy_reference or args.output is None:
parser.error('Daily updates use Service prepare_catalogue.py; '
'legacy export requires --legacy-reference --output')
files = (*zip(("assets.zip", "metadata.json"), export(root)),
('land-soils.zip', export_soils(root)))
destination = root / "src/farm_render/data"
destination = args.output
for name, content in files:
path = destination / name
if args.check:
+59
View File
@@ -0,0 +1,59 @@
"""显式从已验证Service发布目录刷新插件初始版本,不联网。"""
import argparse
import json
from pathlib import Path
import shutil
import sys
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'src'))
from farm_core import Catalogue
from farm_core.catalogue_release import canonical, parse_manifest
from farm_render.catalogue_bundle import ROOTS, _snapshot
def sync(source, root=ROOT):
source, root = Path(source), Path(root)
manifest = parse_manifest((source / 'manifest.json').read_bytes())
release = source / 'releases' / manifest['release']
snapshot = _snapshot(release, manifest, Catalogue.bundled())
destinations = {
'plants.json': root / 'src/farm_core/data/plants.json',
**{name: root / 'src/farm_render/data' / name for name in (
'metadata.json', 'assets.zip', 'land-soils.zip',
)},
}
for name, path in destinations.items():
path.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(release / name, path)
data = root / 'src/farm_core/data'
(data / 'catalogue-manifest.json').write_bytes(canonical(manifest) + b'\n')
asset = {
'schema': 1, 'version': manifest['version'],
'sha256': manifest['files']['assets.zip']['sha256'],
'size_bytes': manifest['files']['assets.zip']['size_bytes'],
'catalogue_release': manifest['release'],
'sources': {
name.lower(): base + '/releases/' + manifest['release']
+ '/assets.zip' for name, base in ROOTS.items()
},
}
asset['sources']['farm_service'] = (
'https://farm.example/v1/catalogue/releases/'
+ manifest['release'] + '/assets.zip'
)
(root / 'src/farm_render/data/asset-manifest.json').write_text(
json.dumps(asset, ensure_ascii=False, indent=2) + '\n',
encoding='utf-8',
)
return snapshot.manifest
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--source', type=Path, required=True,
help='Service catalogue发布目录,不是可编辑source目录')
args = parser.parse_args()
print('Bootstrap synced release=' + sync(args.source)['release'])
+1 -2
View File
@@ -14,8 +14,7 @@ def main():
}
commands = (
[sys.executable, "scripts/check_baseline.py"],
[sys.executable, "scripts/export_catalogue.py", "--check"],
[sys.executable, "scripts/export_render_assets.py", "--check"],
[sys.executable, 'scripts/check_catalogue_bootstrap.py'],
[sys.executable, 'scripts/check_asset_manifest.py'],
[
sys.executable, "-m", "unittest", "discover",