mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 13:00:39 +00:00
feat: refactor kv sync logic to use regex for R2 block replacement
This commit is contained in:
@@ -40,23 +40,28 @@ jobs:
|
|||||||
git checkout -B kv origin/main
|
git checkout -B kv origin/main
|
||||||
|
|
||||||
python - <<'PY'
|
python - <<'PY'
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
path = Path("wrangler.toml")
|
path = Path("wrangler.toml")
|
||||||
text = path.read_text(encoding="utf-8")
|
text = path.read_text(encoding="utf-8")
|
||||||
old = """[[r2_buckets]]
|
|
||||||
binding = "ATTACHMENTS"
|
|
||||||
bucket_name = "nodewarden-attachments"
|
|
||||||
"""
|
|
||||||
new = """[[kv_namespaces]]
|
|
||||||
binding = "ATTACHMENTS_KV"
|
|
||||||
id = "REPLACE_WITH_KV_NAMESPACE_ID"
|
|
||||||
"""
|
|
||||||
|
|
||||||
if old not in text:
|
pattern = (
|
||||||
|
r"\[\[r2_buckets\]\]\s*"
|
||||||
|
r'binding\s*=\s*"ATTACHMENTS"\s*'
|
||||||
|
r'bucket_name\s*=\s*"nodewarden-attachments"\s*'
|
||||||
|
)
|
||||||
|
replacement = (
|
||||||
|
'[[kv_namespaces]]\n'
|
||||||
|
'binding = "ATTACHMENTS_KV"\n'
|
||||||
|
'id = "REPLACE_WITH_KV_NAMESPACE_ID"\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
new_text, count = re.subn(pattern, replacement, text, count=1)
|
||||||
|
if count == 0:
|
||||||
raise SystemExit("Expected R2 block not found in wrangler.toml")
|
raise SystemExit("Expected R2 block not found in wrangler.toml")
|
||||||
|
|
||||||
path.write_text(text.replace(old, new, 1), encoding="utf-8")
|
path.write_text(new_text, encoding="utf-8")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
git add wrangler.toml
|
git add wrangler.toml
|
||||||
|
|||||||
Reference in New Issue
Block a user