Update version_branch.yml

This commit is contained in:
2025-12-16 17:16:56 -06:00
parent 7ac6a2d70b
commit e7b840550b

View File

@@ -95,6 +95,82 @@ jobs:
git checkout -B "${BRANCH_NAME}" "origin/${BASE_BRANCH}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV"
- name: Ensure CHANGELOG.md has an H2 immediately after TODO block (repo creation)
shell: bash
run: |
set -Eeuo pipefail
trap 'echo "[FATAL] CHANGELOG initialization failed at line $LINENO" >&2; echo "[FATAL] Last command: $BASH_COMMAND" >&2' ERR
if [[ ! -f "CHANGELOG.md" ]]; then
echo "[INFO] CHANGELOG.md missing. Pulling baseline from MokoDefaults/generic-git (main)."
BASE_URL="https://raw.githubusercontent.com/mokoconsulting-tech/MokoDefaults/main/generic-git/CHANGELOG.md"
if ! curl -fsSL "${BASE_URL}" -o CHANGELOG.md; then
echo "[FATAL] Unable to fetch baseline CHANGELOG.md from: ${BASE_URL}" >&2
echo "[FATAL] Validate repository visibility and path: MokoDefaults/main/generic-git/CHANGELOG.md" >&2
exit 2
fi
echo "[INFO] Baseline CHANGELOG.md retrieved"
fi
python3 - <<'PY'
import os
import re
from datetime import datetime, timezone
from pathlib import Path
new_version = os.environ.get('NEW_VERSION', '').strip() or '00.00.00'
p = Path('CHANGELOG.md')
text = p.read_text(encoding='utf-8', errors='replace').splitlines(True)
todo_re = re.compile(r'^##\s*\[?TODO\]?\s*$', re.IGNORECASE)
h2_re = re.compile(r'^##\s+')
bullet_re = re.compile(r'^\s*[-*+]\s+')
blank_re = re.compile(r'^\s*$')
idx = None
for i, line in enumerate(text):
if todo_re.match(line.rstrip('\n').rstrip('\r')):
idx = i
break
if idx is None:
print('[INFO] No TODO section found. No action taken.')
raise SystemExit(0)
j = idx + 1
saw_bullet = False
while j < len(text):
line = text[j].rstrip('\n').rstrip('\r')
if bullet_re.match(line):
saw_bullet = True
j += 1
continue
if blank_re.match(line):
j += 1
continue
break
if not saw_bullet:
print('[INFO] TODO section missing bullet list, inserting placeholder bullet')
text.insert(idx + 1, '- Placeholder TODO item\n')
j = idx + 2
if j < len(text) and h2_re.match(text[j]):
print('[INFO] TODO block already followed by an H2. No action taken.')
raise SystemExit(0)
stamp = datetime.now(timezone.utc).strftime('%Y-%m-%d')
insert = f"\n## [{new_version}] {stamp}\n"
print('[INFO] Inserting initial H2 after TODO block')
text.insert(j, insert)
p.write_text(''.join(text), encoding='utf-8')
PY
- name: Preflight discovery (src and docs only)
shell: bash
run: |