Update version_branch.yml

This commit is contained in:
2025-12-23 16:36:37 -06:00
parent 787482ebdd
commit 3178db4625

View File

@@ -320,127 +320,120 @@ jobs:
exit 2 exit 2
fi fi
- name: Bump versions and update manifest dates (targeted, excluding .github) $1 import json
run: | import os
source "$CI_HELPERS" import re
moko_init "Version bump" from pathlib import Path
from collections import defaultdict
from datetime import datetime, timezone
python3 - <<'PY' new_version = (os.environ.get("NEW_VERSION") or "").strip()
import json version_text = (os.environ.get("VERSION_TEXT") or "").strip()
import os report_only = (os.environ.get("REPORT_ONLY") or "").strip().lower() == "true"
import re report_path = (os.environ.get("REPORT_PATH") or "").strip()
from pathlib import Path
from collections import defaultdict
from datetime import datetime, timezone
new_version = (os.environ.get("NEW_VERSION") or "").strip() stamp = datetime.now(timezone.utc).strftime("%Y-%m-%d")
version_text = (os.environ.get("VERSION_TEXT") or "").strip() root = Path(".").resolve()
report_only = (os.environ.get("REPORT_ONLY") or "").strip().lower() == "true"
report_path = (os.environ.get("REPORT_PATH") or "").strip()
stamp = datetime.now(timezone.utc).strftime("%Y-%m-%d") header_re = re.compile(r"(?im)(VERSION[ \t]*:[ \t]*)([0-9]{2}[.][0-9]{2}[.][0-9]{2})")
root = Path(".").resolve() manifest_marker_re = re.compile(r"(?is)<extension\b")
xml_version_re = re.compile(r"(?is)(<version[ \t]*>)([^<]*?)(</version[ \t]*>)")
xml_date_res = [
re.compile(r"(?is)(<creationDate[ \t]*>)([^<]*?)(</creationDate[ \t]*>)"),
re.compile(r"(?is)(<date[ \t]*>)([^<]*?)(</date[ \t]*>)"),
re.compile(r"(?is)(<releaseDate[ \t]*>)([^<]*?)(</releaseDate[ \t]*>)"),
]
header_re = re.compile(r"(?im)(VERSION[ \t]*:[ \t]*)([0-9]{2}[.][0-9]{2}[.][0-9]{2})") skip_ext = {
manifest_marker_re = re.compile(r"(?is)<extension\b") ".json", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".pdf",
xml_version_re = re.compile(r"(?is)(<version[ \t]*>)([^<]*?)(</version[ \t]*>)") ".zip", ".7z", ".tar", ".gz", ".woff", ".woff2", ".ttf", ".otf",
xml_date_res = [ ".mp3", ".mp4",
re.compile(r"(?is)(<creationDate[ \t]*>)([^<]*?)(</creationDate[ \t]*>)"), }
re.compile(r"(?is)(<date[ \t]*>)([^<]*?)(</date[ \t]*>)"), skip_dirs = {".git", ".github", "node_modules", "vendor", ".venv", "dist", "build"}
re.compile(r"(?is)(<releaseDate[ \t]*>)([^<]*?)(</releaseDate[ \t]*>)"),
]
skip_ext = { counters = defaultdict(int)
".json", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".pdf", updated_files = []
".zip", ".7z", ".tar", ".gz", ".woff", ".woff2", ".ttf", ".otf", updated_manifests = []
".mp3", ".mp4", would_update_files = []
} would_update_manifests = []
skip_dirs = {".git", ".github", "node_modules", "vendor", ".venv", "dist", "build"}
counters = defaultdict(int) exclude_root = {"update.xml", "updates.xml"}
updated_files = []
updated_manifests = []
would_update_files = []
would_update_manifests = []
# Exclude root update feeds. They are generated at release time. def should_skip(p: Path) -> bool:
exclude_root = {"update.xml", "updates.xml"} if p.suffix.lower() in skip_ext:
counters["skipped_by_ext"] += 1
return True
parts = {x.lower() for x in p.parts}
if any(d in parts for d in skip_dirs):
counters["skipped_by_dir"] += 1
return True
return False
def should_skip(p: Path) -> bool: for p in root.rglob("*"):
if p.suffix.lower() in skip_ext: if not p.is_file():
counters["skipped_by_ext"] += 1 continue
return True if should_skip(p):
parts = {x.lower() for x in p.parts} continue
if any(d in parts for d in skip_dirs):
counters["skipped_by_dir"] += 1
return True
return False
for p in root.rglob("*"): if p.parent == root and p.name.lower() in exclude_root:
if not p.is_file(): counters["skipped_release_artifacts"] += 1
continue continue
if should_skip(p):
continue
if p.parent == root and p.name.lower() in exclude_root: try:
counters["skipped_release_artifacts"] += 1 original = p.read_text(encoding="utf-8", errors="replace")
continue except Exception:
counters["skipped_read_error"] += 1
continue
try: text = original
original = p.read_text(encoding="utf-8", errors="replace")
except Exception:
counters["skipped_read_error"] += 1
continue
text = original text, n1 = header_re.subn(lambda m: m.group(1) + new_version, text)
if n1:
counters["header_replacements"] += n1
text, n1 = header_re.subn(lambda m: m.group(1) + new_version, text) is_manifest = (p.suffix.lower() == ".xml" and manifest_marker_re.search(original) is not None)
if n1: if is_manifest:
counters["header_replacements"] += n1 text, n2 = xml_version_re.subn(lambda m: m.group(1) + new_version + m.group(3), text)
if n2:
counters["xml_version_replacements"] += n2
is_manifest = (p.suffix.lower() == ".xml" and manifest_marker_re.search(original) is not None) for rx in xml_date_res:
if is_manifest: text, n3 = rx.subn(lambda m: m.group(1) + stamp + m.group(3), text)
text, n2 = xml_version_re.subn(lambda m: m.group(1) + new_version + m.group(3), text) if n3:
if n2: counters["xml_date_replacements"] += n3
counters["xml_version_replacements"] += n2
for rx in xml_date_res: if text != original:
text, n3 = rx.subn(lambda m: m.group(1) + stamp + m.group(3), text) would_update_files.append(str(p))
if n3: if is_manifest:
counters["xml_date_replacements"] += n3 would_update_manifests.append(str(p))
if text != original: if not report_only:
would_update_files.append(str(p)) p.write_text(text, encoding="utf-8")
if is_manifest: updated_files.append(str(p))
would_update_manifests.append(str(p)) if is_manifest:
updated_manifests.append(str(p))
if not report_only: report = {
p.write_text(text, encoding="utf-8") "mode": "report_only" if report_only else "apply",
updated_files.append(str(p)) "new_version": new_version,
if is_manifest: "version_text": version_text,
updated_manifests.append(str(p)) "stamp_utc": stamp,
"counters": dict(counters),
"updated_files": updated_files,
"updated_manifests": updated_manifests,
"would_update_files": would_update_files,
"would_update_manifests": would_update_manifests,
}
report = { Path(report_path).write_text(json.dumps(report, indent=2), encoding="utf-8")
"mode": "report_only" if report_only else "apply",
"new_version": new_version,
"version_text": version_text,
"stamp_utc": stamp,
"counters": dict(counters),
"updated_files": updated_files,
"updated_manifests": updated_manifests,
"would_update_files": would_update_files,
"would_update_manifests": would_update_manifests,
}
Path(report_path).write_text(json.dumps(report, indent=2), encoding="utf-8") print("[INFO] Report written to:", report_path)
print("[INFO] Mode:", report["mode"])
print("[INFO] Report written to:", report_path) print("[INFO] Would update files:", len(would_update_files))
print("[INFO] Mode:", report["mode"]) print("[INFO] Would update manifests:", len(would_update_manifests))
print("[INFO] Would update files:", len(would_update_files)) print("[INFO] Updated files:", len(updated_files))
print("[INFO] Would update manifests:", len(would_update_manifests)) print("[INFO] Updated manifests:", len(updated_manifests))
print("[INFO] Updated files:", len(updated_files)) PY
print("[INFO] Updated manifests:", len(updated_manifests))
PY
- name: Commit changes - name: Commit changes
if: ${{ env.REPORT_ONLY != 'true' }} if: ${{ env.REPORT_ONLY != 'true' }}