Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/scripts/parse_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Parse CHANGELOG.md and extract the latest version and release notes."""

import json
import re
import sys


def parse_changelog(filepath="CHANGELOG.md"):
"""Extract the latest version and its content from CHANGELOG.md."""
with open(filepath) as f:
content = f.read()

# Match version headers like ## [0.3.1] - 2026-02-10
version_pattern = r"^## \[([^\]]+)\] - (\d{4}-\d{2}-\d{2})"
matches = list(re.finditer(version_pattern, content, re.MULTILINE))

if not matches:
print("Error: No version found in CHANGELOG.md", file=sys.stderr)
sys.exit(1)

# Get the first (latest) version
first_match = matches[0]
version = first_match.group(1)
date = first_match.group(2)

# Extract content between first and second version headers
start_pos = first_match.end()
if len(matches) > 1:
end_pos = matches[1].start()
body = content[start_pos:end_pos].strip()
else:
# If only one version, get everything after it until the end or separator
remaining = content[start_pos:]
separator_match = re.search(r"^---$", remaining, re.MULTILINE)
if separator_match:
body = remaining[: separator_match.start()].strip()
else:
body = remaining.strip()

return {"version": version, "tag": f"v{version}", "date": date, "body": body}


if __name__ == "__main__":
result = parse_changelog()
print(json.dumps(result))
73 changes: 8 additions & 65 deletions .github/workflows/auto-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
branches:
- main
paths:
- 'CHANGELOG.md'
# paths:
# - 'CHANGELOG.md'

jobs:
create-release:
Expand All @@ -22,66 +22,10 @@ jobs:
- name: Parse Changelog
id: changelog
run: |
# Extract the latest version and its content from CHANGELOG.md
python3 << 'EOF'
import re
import sys

with open('CHANGELOG.md', 'r') as f:
content = f.read()

# Match version headers like ## [0.3.1] - 2026-02-10
version_pattern = r'^## \[([^\]]+)\] - (\d{4}-\d{2}-\d{2})'
matches = list(re.finditer(version_pattern, content, re.MULTILINE))

if not matches:
print("No version found in CHANGELOG.md", file=sys.stderr)
sys.exit(1)

# Get the first (latest) version
first_match = matches[0]
version = first_match.group(1)
date = first_match.group(2)

# Extract content between first and second version headers
start_pos = first_match.end()
if len(matches) > 1:
end_pos = matches[1].start()
body = content[start_pos:end_pos].strip()
else:
# If only one version, get everything after it until the end or separator
remaining = content[start_pos:]
separator_match = re.search(r'^---$', remaining, re.MULTILINE)
if separator_match:
body = remaining[:separator_match.start()].strip()
else:
body = remaining.strip()

# Clean up the body - remove leading/trailing whitespace
body = body.strip()

# Write outputs
with open('version.txt', 'w') as f:
f.write(version)
with open('body.txt', 'w') as f:
f.write(body)

print(f"Version: {version}")
print(f"Date: {date}")
print(f"Body length: {len(body)} characters")
EOF

# Set outputs
VERSION=$(cat version.txt)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT

# For multiline output, use delimiter
{
echo 'body<<EOF_CHANGELOG'
cat body.txt
echo EOF_CHANGELOG
} >> $GITHUB_OUTPUT
RESULT=$(python3 .github/scripts/parse_changelog.py)
echo "version=$(echo "$RESULT" | jq -r '.version')" >> $GITHUB_OUTPUT
echo "tag=$(echo "$RESULT" | jq -r '.tag')" >> $GITHUB_OUTPUT
echo "body=$(echo "$RESULT" | jq -r '.body')" >> $GITHUB_OUTPUT

- name: Check if release exists
id: check_release
Expand All @@ -90,7 +34,6 @@ jobs:
run: |
TAG="${{ steps.changelog.outputs.tag }}"

# Check if release exists
if gh release view "$TAG" &>/dev/null; then
echo "Release $TAG already exists"
echo "exists=true" >> $GITHUB_OUTPUT
Expand All @@ -106,11 +49,11 @@ jobs:
run: |
TAG="${{ steps.changelog.outputs.tag }}"
VERSION="${{ steps.changelog.outputs.version }}"
BODY="${{ steps.changelog.outputs.body }}"

# Create release with changelog body
gh release create "$TAG" \
--title "Release $VERSION" \
--notes "${{ steps.changelog.outputs.body }}" \
--notes "$BODY" \
--verify-tag

- name: Skip Release
Expand Down