Skip to content

Commit 3e24bac

Browse files
authored
Merge pull request #6 from captcha-solver-api/ci/changelog-generation
ci: generate changelog on release
2 parents f903942 + ed94220 commit 3e24bac

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Generate a Keep a Changelog section from Conventional Commit subjects."""
2+
3+
import argparse
4+
import datetime as dt
5+
import re
6+
import subprocess
7+
from pathlib import Path
8+
9+
GROUPS = {
10+
"feat": "Added",
11+
"fix": "Fixed",
12+
"perf": "Changed",
13+
"refactor": "Changed",
14+
"docs": "Documentation",
15+
"build": "Maintenance",
16+
"ci": "Maintenance",
17+
"chore": "Maintenance",
18+
"test": "Maintenance",
19+
}
20+
21+
22+
def git(*args: str) -> str:
23+
return subprocess.check_output(["git", *args], text=True, encoding="utf-8").strip()
24+
25+
26+
def main() -> None:
27+
parser = argparse.ArgumentParser()
28+
parser.add_argument("--tag", required=True)
29+
parser.add_argument("--repository", required=True)
30+
args = parser.parse_args()
31+
tags = git("tag", "--sort=-version:refname").splitlines()
32+
previous = next((tag for tag in tags if tag != args.tag), None)
33+
revision = f"{previous}..{args.tag}" if previous else args.tag
34+
subjects = git("log", revision, "--format=%s").splitlines()
35+
grouped: dict[str, list[str]] = {}
36+
for subject in subjects:
37+
match = re.match(r"([a-z]+)(?:\([^)]*\))?(!)?:\s*(.+)", subject)
38+
if not match:
39+
continue
40+
kind, breaking, text = match.groups()
41+
heading = "Breaking changes" if breaking else GROUPS.get(kind)
42+
if heading:
43+
grouped.setdefault(heading, []).append(text)
44+
version = args.tag.removeprefix("v")
45+
date = dt.date.today().isoformat()
46+
order = ["Breaking changes", "Added", "Fixed", "Changed", "Documentation", "Maintenance"]
47+
body = [f"## [{version}] - {date}", ""]
48+
for heading in order:
49+
if heading in grouped:
50+
body.extend([f"### {heading}", "", *[f"- {item}" for item in grouped[heading]], ""])
51+
compare = (
52+
f"https://github.com/{args.repository}/compare/{previous}...{args.tag}"
53+
if previous
54+
else f"https://github.com/{args.repository}/releases/tag/{args.tag}"
55+
)
56+
body.append(f"[Full diff]({compare})")
57+
section = "\n".join(body).rstrip() + "\n"
58+
changelog = Path("CHANGELOG.md")
59+
existing = (
60+
changelog.read_text(encoding="utf-8")
61+
if changelog.exists()
62+
else "# Changelog\n\nAll notable changes are documented here.\n"
63+
)
64+
if f"## [{version}]" not in existing:
65+
marker = "All notable changes are documented here.\n"
66+
existing = existing.replace(marker, marker + "\n" + section + "\n", 1)
67+
changelog.write_text(existing, encoding="utf-8")
68+
Path("release-notes.md").write_text(section, encoding="utf-8")
69+
70+
71+
if __name__ == "__main__":
72+
main()

‎.github/workflows/publish.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,28 @@ jobs:
8686
files: dist/*
8787
# Requires Discussions enabled in the repo with this category present.
8888
discussion_category_name: Announcements
89+
90+
changelog:
91+
needs: publish
92+
if: startsWith(github.ref, 'refs/tags/')
93+
runs-on: ubuntu-latest
94+
permissions:
95+
contents: write
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
ref: main
100+
fetch-depth: 0
101+
- name: Generate changelog
102+
run: python .github/scripts/generate_changelog.py --tag "$GITHUB_REF_NAME" --repository "$GITHUB_REPOSITORY"
103+
- name: Commit changelog
104+
run: |
105+
git config user.name "github-actions[bot]"
106+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
107+
git add CHANGELOG.md
108+
git diff --cached --quiet || git commit -m "docs: update changelog for $GITHUB_REF_NAME"
109+
git push origin main
110+
- name: Use changelog as release notes
111+
run: gh release edit "$GITHUB_REF_NAME" --notes-file release-notes.md
112+
env:
113+
GH_TOKEN: ${{ github.token }}

‎CHANGELOG.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Changelog
2+
3+
All notable changes are documented here.
4+
5+
New sections are generated from Conventional Commits when a version tag is published.
6+
7+
## [1.0.2] - 2026-09-18
8+
9+
### Fixed
10+
11+
- Removed the unsupported Yandex image puzzle mode.
12+
- Kept reCAPTCHA v3 support proxyless-only.
13+
14+
## [1.0.1] - 2026-09-17
15+
16+
### Fixed
17+
18+
- Aligned the polling interval with API recommendations.
19+
20+
## [1.0.0] - 2026-09-17
21+
22+
### Added
23+
24+
- Published the initial Python SDK release.

0 commit comments

Comments
 (0)