-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgenerate_changelog.py
More file actions
executable file
·149 lines (119 loc) · 4.42 KB
/
generate_changelog.py
File metadata and controls
executable file
·149 lines (119 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
"""Generate changelog for weekly releases."""
import argparse
import re
import subprocess
from datetime import datetime
def get_latest_tag():
"""Get the latest git tag."""
try:
result = subprocess.run(
["git", "describe", "--tags", "--abbrev=0"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except subprocess.CalledProcessError:
return None
def get_commits_since_tag(tag):
"""Get commits since the given tag."""
if tag:
cmd = ["git", "log", f"{tag}..HEAD", "--oneline"]
else:
cmd = ["git", "log", "--oneline"]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
return result.stdout.strip().split("\n") if result.stdout.strip() else []
def categorize_commits(commits):
"""Categorize commits by type."""
categories = {
"features": [],
"fixes": [],
"performance": [],
"docs": [],
"other": [],
}
for commit in commits:
commit = commit.strip()
if not commit:
continue
if re.search(r"\b(feat|feature|add)\b", commit, re.I):
categories["features"].append(commit)
elif re.search(r"\b(fix|bug|patch)\b", commit, re.I):
categories["fixes"].append(commit)
elif re.search(r"\b(perf|performance|speed|optimize)\b", commit, re.I):
categories["performance"].append(commit)
elif re.search(r"\b(doc|docs|readme)\b", commit, re.I):
categories["docs"].append(commit)
else:
categories["other"].append(commit)
return categories
def generate_changelog(beta=False):
"""Generate changelog content."""
latest_tag = get_latest_tag()
commits = get_commits_since_tag(latest_tag)
if not commits:
return "No changes since last release."
categories = categorize_commits(commits)
if beta:
changelog = "# Beta Release Notes\n\n"
changelog += f"*Beta Release: {datetime.now().strftime('%Y-%m-%d')}*\n\n"
changelog += "⚠️ **This is a beta release for testing purposes.**\n\n"
else:
changelog = "# What's New\n\n"
changelog += f"*Released: {datetime.now().strftime('%Y-%m-%d')}*\n\n"
if categories["features"]:
changelog += "## 🚀 New Features\n"
for commit in categories["features"]:
changelog += f"- {commit[8:]}\n" # Remove hash
changelog += "\n"
if categories["performance"]:
changelog += "## ⚡ Performance Improvements\n"
for commit in categories["performance"]:
changelog += f"- {commit[8:]}\n"
changelog += "\n"
if categories["fixes"]:
changelog += "## 🐛 Bug Fixes\n"
for commit in categories["fixes"]:
changelog += f"- {commit[8:]}\n"
changelog += "\n"
if categories["docs"]:
changelog += "## 📚 Documentation\n"
for commit in categories["docs"]:
changelog += f"- {commit[8:]}\n"
changelog += "\n"
if categories["other"]:
changelog += "## 🔧 Other Changes\n"
for commit in categories["other"]:
changelog += f"- {commit[8:]}\n"
changelog += "\n"
changelog += "## 📥 Installation\n\n"
changelog += "```bash\n"
changelog += "# Core package (lightweight)\n"
changelog += "pip install datafog\n\n"
changelog += "# With all features\n"
changelog += "pip install datafog[all]\n"
changelog += "```\n\n"
changelog += "## 📊 Metrics\n\n"
changelog += "- Package size: ~2MB (core)\n"
changelog += "- Install time: ~10 seconds\n"
changelog += "- Tests passing: ✅\n"
changelog += f"- Commits this week: {len(commits)}\n\n"
return changelog
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate changelog for releases")
parser.add_argument(
"--beta", action="store_true", help="Generate beta release changelog"
)
parser.add_argument(
"--output", help="Output file name", default="CHANGELOG_LATEST.md"
)
args = parser.parse_args()
changelog_content = generate_changelog(beta=args.beta)
# Write to file for GitHub release
with open(args.output, "w") as f:
f.write(changelog_content)
print(f"✅ Changelog generated: {args.output}")
print("\nPreview:")
print("=" * 50)
print(changelog_content)