Files
tekton/tools/generate_version_json.py
T

129 lines
4.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
generate_version_json.py
Auto-generates version.json by:
1. Reading the current version from project.godot
2. Auto-bumping the PATCH number
3. Reading player-friendly entries from CHANGELOG_DRAFT.md
4. Injecting them into version.json with a date stamp
5. Clearing the [NEXT] section in CHANGELOG_DRAFT.md
Run: python3 tools/generate_version_json.py
"""
import json
import re
import os
from datetime import date
PROJECT_GODOT = "project.godot"
CHANGELOG_DRAFT = "CHANGELOG_DRAFT.md"
VERSION_JSON = "assets/data/version.json"
MANIFEST_URL = "https://raw.githubusercontent.com/adtpdn/tekton-updates/main/latest/patch.pck"
# ─── 1. Read current version from project.godot ──────────────────────────────
version_str = "2.1.5"
with open(PROJECT_GODOT, "r") as f:
for line in f:
m = re.search(r'config/version="([^"]+)"', line)
if m:
version_str = m.group(1)
break
# ─── 2. Auto-bump patch number ───────────────────────────────────────────────
parts = version_str.split(".")
parts[-1] = str(int(parts[-1]) + 1)
new_version = ".".join(parts)
print(f"Version: {version_str}{new_version}")
# ─── 3. Read CHANGELOG_DRAFT.md ──────────────────────────────────────────────
changelog_lines = []
in_next = False
remaining_lines = []
with open(CHANGELOG_DRAFT, "r", encoding="utf-8") as f:
raw = f.readlines()
for line in raw:
if line.strip() == "## [NEXT]":
in_next = True
continue
if in_next:
# Stop at next ## heading
if line.startswith("## ") and "[NEXT]" not in line:
in_next = False
remaining_lines.append(line)
elif line.strip():
# Strip leading "- " and emoji bullet
clean = line.strip().lstrip("- ").strip()
changelog_lines.append(clean)
else:
remaining_lines.append(line)
if not changelog_lines:
print(" No [NEXT] entries found in CHANGELOG_DRAFT.md — skipping version bump and release generation.")
exit(0)
print(f"Changelog entries: {len(changelog_lines)}")
# ─── 4. Load existing version.json ───────────────────────────────────────────
existing = {"releases": []}
if os.path.exists(VERSION_JSON):
with open(VERSION_JSON, "r") as f:
existing = json.load(f)
# ─── 5. Prepend new release ───────────────────────────────────────────────────
today = date.today().isoformat()
new_release = {
"version": new_version,
"date": today,
"pck_url": MANIFEST_URL,
"pck_size": 0,
"changelog": changelog_lines
}
# Remove any existing entry with the same version
existing["releases"] = [r for r in existing["releases"] if r.get("version") != new_version]
existing["releases"].insert(0, new_release)
manifest = {
"latest_version": new_version,
"minimum_app_version": existing.get("minimum_app_version", "2.1.0"),
"releases": existing["releases"]
}
with open(VERSION_JSON, "w") as f:
json.dump(manifest, f, indent="\t")
f.write("\n")
print(f"✅ Written: {VERSION_JSON} (latest={new_version})")
# ─── 6. Bump version in project.godot ────────────────────────────────────────
with open(PROJECT_GODOT, "r") as f:
godot_content = f.read()
godot_content = re.sub(
r'(config/version=")[^"]+(")',
rf'\g<1>{new_version}\g<2>',
godot_content
)
with open(PROJECT_GODOT, "w") as f:
f.write(godot_content)
print(f"✅ Bumped project.godot → {new_version}")
# ─── 7. Clear [NEXT] in CHANGELOG_DRAFT.md ───────────────────────────────────
archived_header = f"## [{new_version}] — {today}\n"
archived_entries = "".join(f"- {line}\n" for line in changelog_lines)
new_draft = "## [NEXT]\n\n" + archived_header + archived_entries
if remaining_lines:
new_draft += "\n" + "".join(remaining_lines)
with open(CHANGELOG_DRAFT, "w", encoding="utf-8") as f:
f.write(new_draft)
print(f"✅ Cleared [NEXT] in {CHANGELOG_DRAFT}, archived as [{new_version}]")
print(f"\nDone! Push to patch-release to deploy v{new_version}.")