mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
feat(git): add module index updating workflow
This commit is contained in:
38
.github/workflows/update-module-index.yml
vendored
Normal file
38
.github/workflows/update-module-index.yml
vendored
Normal 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
|
||||||
58
scripts/update_module_index.py
Normal file
58
scripts/update_module_index.py
Normal 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()
|
||||||
Reference in New Issue
Block a user