feat(git): add module index updating workflow

This commit is contained in:
2026-05-10 22:08:47 +08:00
parent da381c3adf
commit ed806c668a
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
name: update-module-index.yml
on:
push:
branches:
- master
paths:
- "registry/modules/*.json"
- "registry/index.json"
- "scripts/update_module_index.py"
- "update-module-index.yml"
permissions:
contents: write
jobs:
update-registry-index:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update module index
run: python3 scripts/update_module_index.py
- name: Commit updated index
run: |
if git diff --quiet registry/index.json; then
echo "No module index changes"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add repository/index.json
git commit -m "chore: update registry index"
git push

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env python3
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
INDEX_PATH = ROOT / "registry" / "index.json"
MODULES_DIR = ROOT / "registry" / "modules"
def load_json(path: Path) -> dict:
with path.open("r", encoding="utf-8") as f:
return json.load(f)
def write_json(path: Path, data: dict) -> None:
path.write_text(
json.dumps(data, ensure_ascii=False, indent=2) + "\n",
encoding="utf-8",
)
def build_external_modules() -> list[dict]:
entries = []
if not MODULES_DIR.exists():
return entries
for manifest_path in sorted(MODULES_DIR.glob("*.json")):
manifest = load_json(manifest_path)
# 这里按你当前 ModuleManifest 的完整文件结构取字段。
# version 如果 manifest 里暂时没有,可以先默认取 "0.5.0" 或直接要求 manifest 必须有。
name = manifest["name"]
version = manifest["version"]
with_gateway = manifest.get("withGateway", False)
rel_path = manifest_path.relative_to(ROOT / "repository").as_posix()
entries.append(
{
"name": name,
"version": version,
"withGateway": with_gateway,
"registryRef": rel_path,
}
)
return entries
def main() -> None:
index = load_json(INDEX_PATH)
index["externalModules"] = build_external_modules()
write_json(INDEX_PATH, index)
if __name__ == "__main__":
main()