From ed806c668a5f2654f6f2f7dad2e157e400c7f092 Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Sun, 10 May 2026 22:08:47 +0800 Subject: [PATCH] feat(git): add module index updating workflow --- .github/workflows/update-module-index.yml | 38 +++++++++++++++ scripts/update_module_index.py | 58 +++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 .github/workflows/update-module-index.yml create mode 100644 scripts/update_module_index.py diff --git a/.github/workflows/update-module-index.yml b/.github/workflows/update-module-index.yml new file mode 100644 index 00000000..8378898e --- /dev/null +++ b/.github/workflows/update-module-index.yml @@ -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 diff --git a/scripts/update_module_index.py b/scripts/update_module_index.py new file mode 100644 index 00000000..2e08e844 --- /dev/null +++ b/scripts/update_module_index.py @@ -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() \ No newline at end of file