Browse Source

refactor: replace inline Python scripts with dedicated scripts for formatting release notes and updating version mapping

This update simplifies the workflow by utilizing separate Python scripts for generating user-friendly release notes and managing the version mapping for ABP Studio. The previous inline scripts have been removed to enhance maintainability and clarity.
pull/25651/head
selmankoc 4 months ago
parent
commit
04786974a4
  1. 200
      .github/workflows/update-studio-docs.yml

200
.github/workflows/update-studio-docs.yml

@ -242,74 +242,7 @@ jobs:
echo "$AI_RESPONSE" > .tmp/final-notes.txt
else
echo "⚠️ AI unavailable - generating concise user-friendly summaries from raw notes"
python3 <<'PYTHON_EOF'
import os
import re
raw = os.environ.get("RAW_NOTES", "")
lines = raw.splitlines()
output = []
seen = set()
def clean_line(text: str) -> str:
text = text.strip()
if not text:
return ""
# Drop markdown headers/changelog lines.
if re.match(r"^#+\s", text, flags=re.I):
return ""
if re.match(r"^\*\*?\s*full\s+changelog", text, flags=re.I):
return ""
if re.match(r"^full\s+changelog", text, flags=re.I):
return ""
text = re.sub(r"^[\s\-*•]+", "", text)
text = re.sub(r"\s+by\s+@?[a-zA-Z0-9_-]+\s+in\s+https?://\S+", "", text)
text = re.sub(r"\s+by\s+@?[a-zA-Z0-9_-]+\s*$", "", text)
text = re.sub(r"@([a-zA-Z0-9_-]+)", "", text)
text = re.sub(r"\s*\([^)]*#\d+\)\s*$", "", text)
text = re.sub(r"\s+#\d+\s*$", "", text)
text = re.sub(r"\s+", " ", text).strip(" .:-")
if len(text) < 8:
return ""
# Make user-friendly short title + summary when possible.
if ":" in text:
left, right = [p.strip() for p in text.split(":", 1)]
left = left[:40].rstrip(" .")
right_words = right.split()
right = " ".join(right_words[:14]).rstrip(" .")
text = f"{left}: {right}" if right else left
else:
words = text.split()
if len(words) > 16:
text = " ".join(words[:16]).rstrip(" .")
return text
for line in lines:
cleaned = clean_line(line)
if not cleaned:
continue
# Normalize casing and deduplicate.
cleaned = cleaned[0].upper() + cleaned[1:] if cleaned else cleaned
key = cleaned.lower()
if key in seen:
continue
seen.add(key)
output.append(f"* {cleaned}")
if len(output) >= 8:
break
with open('.tmp/final-notes.txt', 'w', encoding='utf-8') as f:
f.write("\n".join(output))
PYTHON_EOF
python3 .github/scripts/format-studio-release-notes.py
fi
# Normalize bullets to "* " even if AI returns "- ".
@ -454,137 +387,8 @@ jobs:
exit 0
fi
# Use Python for smart version range handling
python3 <<'PYTHON_EOF'
import os
import re
from packaging.version import Version, InvalidVersion
studio_ver = os.environ["STUDIO_VERSION"]
abp_ver = os.environ["ABP_VERSION"]
file_path = "docs/en/studio/version-mapping.md"
python3 .github/scripts/update-studio-version-mapping.py
try:
studio = Version(studio_ver)
except InvalidVersion:
print(f"❌ Invalid Studio version: {studio_ver}")
exit(1)
with open(file_path, 'r') as f:
lines = f.readlines()
# Find table start (skip SEO and headers)
table_start = 0
table_end = 0
for i, line in enumerate(lines):
if line.strip().startswith('|') and '**ABP Studio Version**' in line:
table_start = i
elif table_start > 0 and line.strip() and not line.strip().startswith('|'):
table_end = i
break
if table_start == 0:
print("❌ Could not find version mapping table")
exit(1)
# If no end found, table goes to end of file
if table_end == 0:
table_end = len(lines)
# Extract sections
before_table = lines[:table_start] # Everything before table
table_header = lines[table_start:table_start+2] # Header + separator
data_rows = [l for l in lines[table_start+2:table_end] if l.strip().startswith('|')] # Data rows
after_table = lines[table_end:] # Everything after table
new_rows = []
handled = False
def parse_version_range(version_str):
"""Parse '2.1.5 - 2.1.9' or '2.1.5' into (start, end)"""
version_str = version_str.strip()
if '–' in version_str or '-' in version_str:
# Handle both em-dash and hyphen
parts = re.split(r'\s*[–-]\s*', version_str)
if len(parts) == 2:
try:
return Version(parts[0].strip()), Version(parts[1].strip())
except InvalidVersion:
return None, None
try:
v = Version(version_str)
return v, v
except InvalidVersion:
return None, None
def format_row(studio_range, abp_version):
"""Format a table row with proper spacing"""
return f"| {studio_range:<22} | {abp_version:<27} |\n"
# Process existing rows
for row in data_rows:
match = re.match(r'\|\s*(.+?)\s*\|\s*(.+?)\s*\|', row)
if not match:
continue
existing_studio_range = match.group(1).strip()
existing_abp = match.group(2).strip()
# Only consider rows with matching ABP version
if existing_abp != abp_ver:
new_rows.append(row)
continue
start_ver, end_ver = parse_version_range(existing_studio_range)
if start_ver is None or end_ver is None:
new_rows.append(row)
continue
# Check if current studio version is in this range
if start_ver <= studio <= end_ver:
print(f"✅ Studio version {studio_ver} already covered in range {existing_studio_range}")
handled = True
new_rows.append(row)
# Check if we should extend the range
elif end_ver < studio:
# Calculate if studio is the next logical version
# For patch versions: 2.1.9 -> 2.1.10
# For minor versions: 2.1.9 -> 2.2.0
# Simple heuristic: if major.minor match and patch increments, extend range
if (start_ver.major == studio.major and
start_ver.minor == studio.minor and
studio.micro <= end_ver.micro + 5): # Allow small gaps
new_range = f"{start_ver} - {studio}"
new_rows.append(format_row(new_range, abp_ver))
print(f"✅ Extended range: {new_range}")
handled = True
else:
new_rows.append(row)
else:
new_rows.append(row)
# If not handled, add new row at top of data
if not handled:
new_row = format_row(str(studio), abp_ver)
new_rows.insert(0, new_row)
print(f"✅ Added new mapping: {studio_ver} -> {abp_ver}")
# Write updated file - preserve ALL content
with open(file_path, 'w') as f:
f.writelines(before_table) # SEO, title, intro text
f.writelines(table_header) # Table header
f.writelines(new_rows) # Updated data rows
f.writelines(after_table) # Content after table (preview section, etc.)
print("MAPPING_UPDATED=true")
PYTHON_EOF
echo "MAPPING_UPDATED=true" >> $GITHUB_ENV
echo "=== Updated version-mapping.md preview ==="

Loading…
Cancel
Save