Update version_branch.yml
This commit is contained in:
90
.github/workflows/version_branch.yml
vendored
90
.github/workflows/version_branch.yml
vendored
@@ -116,62 +116,60 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
new_version = os.environ.get('NEW_VERSION', '').strip() or '00.00.00'
|
new_version = os.environ.get('NEW_VERSION', '').strip() or '00.00.00'
|
||||||
|
|
||||||
p = Path('CHANGELOG.md')
|
p = Path('CHANGELOG.md')
|
||||||
text = p.read_text(encoding='utf-8', errors='replace').splitlines(True)
|
text = p.read_text(encoding='utf-8', errors='replace').splitlines(True)
|
||||||
|
|
||||||
todo_re = re.compile(r'^##\s*\[?TODO\]?\s*$', re.IGNORECASE)
|
todo_re = re.compile(r'^##\\s*\\[?TODO\\]?\\s*$', re.IGNORECASE)
|
||||||
h2_re = re.compile(r'^##\s+')
|
h2_re = re.compile(r'^##\\s+')
|
||||||
bullet_re = re.compile(r'^\s*[-*+]\s+')
|
bullet_re = re.compile(r'^\\s*[-*+]\\s+')
|
||||||
blank_re = re.compile(r'^\s*$')
|
blank_re = re.compile(r'^\\s*$')
|
||||||
|
|
||||||
idx = None
|
idx = None
|
||||||
for i, line in enumerate(text):
|
for i, line in enumerate(text):
|
||||||
if todo_re.match(line.rstrip('\n').rstrip('\r')):
|
if todo_re.match(line.rstrip('\\n').rstrip('\\r')):
|
||||||
idx = i
|
idx = i
|
||||||
break
|
break
|
||||||
|
|
||||||
if idx is None:
|
if idx is None:
|
||||||
print('[INFO] No TODO section found. No action taken.')
|
print('[INFO] No TODO section found. No action taken.')
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
j = idx + 1
|
j = idx + 1
|
||||||
saw_bullet = False
|
saw_bullet = False
|
||||||
while j < len(text):
|
while j < len(text):
|
||||||
line = text[j].rstrip('\n').rstrip('\r')
|
line = text[j].rstrip('\\n').rstrip('\\r')
|
||||||
if bullet_re.match(line):
|
if bullet_re.match(line):
|
||||||
saw_bullet = True
|
saw_bullet = True
|
||||||
j += 1
|
j += 1
|
||||||
continue
|
continue
|
||||||
if blank_re.match(line):
|
if blank_re.match(line):
|
||||||
j += 1
|
j += 1
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
|
|
||||||
if not saw_bullet:
|
if not saw_bullet:
|
||||||
print('[INFO] TODO section missing bullet list, inserting placeholder bullet')
|
print('[INFO] TODO section missing bullet list, inserting placeholder bullet')
|
||||||
text.insert(idx + 1, '- Placeholder TODO item\n')
|
text.insert(idx + 1, '- Placeholder TODO item\\n')
|
||||||
j = idx + 2
|
j = idx + 2
|
||||||
|
|
||||||
if j < len(text) and h2_re.match(text[j]):
|
if j < len(text) and h2_re.match(text[j]):
|
||||||
print('[INFO] TODO block already followed by an H2. No action taken.')
|
print('[INFO] TODO block already followed by an H2. No action taken.')
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
stamp = datetime.now(timezone.utc).strftime('%Y-%m-%d')
|
stamp = datetime.now(timezone.utc).strftime('%Y-%m-%d')
|
||||||
insert = "
|
insert = "\\n## [{}] {}\\n".format(new_version, stamp)
|
||||||
## [{}] {}
|
print('[INFO] Inserting initial H2 after TODO block')
|
||||||
".format(new_version, stamp)
|
|
||||||
print('[INFO] Inserting initial H2 after TODO block')
|
|
||||||
|
|
||||||
text.insert(j, insert)
|
text.insert(j, insert)
|
||||||
p.write_text(''.join(text), encoding='utf-8')
|
p.write_text(''.join(text), encoding='utf-8')
|
||||||
PY
|
PY
|
||||||
|
|
||||||
- name: Preflight discovery (src and docs only)
|
- name: Preflight discovery (src and docs only)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
Reference in New Issue
Block a user