diff --git a/.github/scripts/parse_changelog.py b/.github/scripts/parse_changelog.py new file mode 100644 index 0000000..c26f0b6 --- /dev/null +++ b/.github/scripts/parse_changelog.py @@ -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)) diff --git a/.github/workflows/auto-release.yaml b/.github/workflows/auto-release.yaml index 29a9774..5ba58f6 100644 --- a/.github/workflows/auto-release.yaml +++ b/.github/workflows/auto-release.yaml @@ -4,8 +4,8 @@ on: push: branches: - main - paths: - - 'CHANGELOG.md' + # paths: + # - 'CHANGELOG.md' jobs: create-release: @@ -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<> $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 @@ -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 @@ -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