Update version_branch.yml

This commit is contained in:
2025-12-23 14:01:57 -06:00
parent 48cfb23081
commit 7ca0d030c2

View File

@@ -373,162 +373,9 @@ jobs:
stamp = datetime.now(timezone.utc).strftime('%Y-%m-%d')
root = Path('.').resolve()
header_re = re.compile(r'(?im)(VERSION[ ]*:[ ]*)([0-9]{2}[.][0-9]{2}[.][0-9]{2})')
header_re = re.compile(r'(?im)(VERSION[ \t]*:[ \t]*)([0-9]{2}[.][0-9]{2}[.][0-9]{2})')
manifest_marker_re = re.compile(r'(?is)<extension')
xml_version_re = re.compile(r'(?is)(<version[ ]*>)([^<]*?)(</version[ ]*>)')
xml_date_res = [
re.compile(r'(?is)(<creationDate[ ]*>)([^<]*?)(</creationDate[ ]*>)'),
re.compile(r'(?is)(<date[ ]*>)([^<]*?)(</date[ ]*>)'),
re.compile(r'(?is)(<releaseDate[ ]*>)([^<]*?)(</releaseDate[ ]*>)'),
]
skip_ext = {
'.json', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.pdf',
'.zip', '.7z', '.tar', '.gz', '.woff', '.woff2', '.ttf', '.otf',
'.mp3', '.mp4'
}
skip_dirs = {'.git', '.github', 'node_modules', 'vendor', '.venv', 'dist', 'build'}
counters = defaultdict(int)
updated = []
updated_manifests = []
def should_skip(p: Path) -> bool:
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
for p in root.rglob('*'):
if not p.is_file():
continue
if should_skip(p):
continue
# Release only artifacts: never version bumped on version branch creation
if p.parent == root and p.name.lower() in {'update.xml', 'updates.xml'}:
counters['skipped_release_artifacts'] += 1
continue
try:
text = p.read_text(encoding='utf-8', errors='replace')
except Exception:
counters['skipped_read_error'] += 1
continue
original = text
text, n1 = header_re.subn(lambda m: m.group(1) + new_version, text)
if n1:
counters['header_replacements'] += n1
if p.suffix.lower() == '.xml' and manifest_marker_re.search(text):
text2, n2 = xml_version_re.subn(lambda m: m.group(1) + new_version + m.group(3), text)
text = text2
if n2:
counters['xml_version_replacements'] += n2
for rx in xml_date_res:
text3, n3 = rx.subn(lambda m: m.group(1) + stamp + m.group(3), text)
text = text3
if n3:
counters['xml_date_replacements'] += n3
if text != original:
updated_manifests.append(str(p))
if text != original:
p.write_text(text, encoding='utf-8')
updated.append(str(p))
report = {
'new_version': new_version,
'stamp_utc': stamp,
'counters': dict(counters),
'updated_files': updated,
'updated_manifests': updated_manifests,
}
Path('.github').mkdir(parents=True, exist_ok=True)
Path('.github/version-bump-report.json').write_text(json.dumps(report, indent=2), encoding='utf-8')
print('[INFO] Scan summary')
for k in sorted(counters.keys()):
print(' ' + k + ': ' + str(counters[k]))
print('[INFO] Updated files: ' + str(len(updated)))
print('[INFO] Updated manifests: ' + str(len(updated_manifests)))
if not updated:
print('[INFO] No eligible files updated. Skipping version bump without failure.')
raise SystemExit(0)
PY
- name: Enforce update.xml is release generated only
run: |
source "$CI_HELPERS"
moko_init "Enforce update.xml is release generated only"
if [[ -f "update.xml" ]]; then
echo "[INFO] update.xml present at repo root. Clearing contents because it is release generated only."
: > "update.xml"
echo "[INFO] update.xml contents cleared"
else
echo "[INFO] update.xml not present. No action taken."
fi
- name: Post bump audit (updates.xml date only)
run: |
source "$CI_HELPERS"
moko_init "Post bump audit (updates.xml date only)"
python3 - <<'PY'
import json
import re
from pathlib import Path
report_path = Path('.github/version-bump-report.json')
if not report_path.exists():
print('[INFO] No bump report found. Skipping updates.xml audit.')
raise SystemExit(0)
report = json.loads(report_path.read_text(encoding='utf-8', errors='replace'))
stamp = (report.get('stamp_utc') or '').strip()
if not stamp:
print('[INFO] No stamp_utc in bump report. Skipping updates.xml audit.')
raise SystemExit(0)
p = Path('updates.xml')
if not p.exists():
print('[INFO] updates.xml not present. Skipping updates.xml date audit.')
raise SystemExit(0)
text = p.read_text(encoding='utf-8', errors='replace')
tags = ['creationDate', 'date', 'releaseDate']
mismatches = []
for t in tags:
rx = re.compile(r'(?is)<' + re.escape(t) + r'\s*>([^<]*?)</' + re.escape(t) + r'\s*>')
m = rx.search(text)
if not m:
continue
current = (m.group(1) or '').strip()
if current != stamp:
mismatches.append('<' + t + '> ' + current + ' != ' + stamp)
if mismatches:
print('[ERROR] updates.xml date audit failed. Mismatches found:')
for x in mismatches:
print(' ' + x)
raise SystemExit(2)
print('[INFO] updates.xml date audit passed')
manifest_marker_re = re.compile(r'(?is)<extension\b')
PY
- name: Change scope guard (block .github edits)