Skip to content
Myr

👷 Add CI to create draft release after merging a `release` PR (#1807)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent 2f54c22 · Browse files · 4 files+234 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+234 added−1 removed

  • tests:+124 added−0 removed
  • other:+110 added−1 removed

4 files+234 added−1 removed

added:.github/workflows/create-draft-release.yml+56 added
modified:.github/workflows/publish.yml+1 added-1 removed
modified:scripts/prepare_release.py+53 added
6 unmodified lines
78import typer910VERSION_PATTERN = re.compile(r'(?m)^__version__ = "(\d+\.\d+\.\d+)"$')11VERSION_HEADING_PATTERN = re.compile(r"(?m)^## (\d+\.\d+\.\d+)(?: \([^)]+\))?$")12RELEASE_NOTES_HEADER = "# Release Notes\n\n"13LATEST_CHANGES_HEADER = "## Latest Changes"14BumpType = Literal["major", "minor", "patch"]15
57 unmodified lines
73 1,74 )757677def get_release_notes_body(content: str, version: str, release_notes_file: Path) -> str:78 version_heading = re.compile(rf"(?m)^## {re.escape(version)}(?: \([^)]+\))?$")79 match = version_heading.search(content)80 if not match:81 raise RuntimeError(82 f"Could not find release notes section for {version} in {release_notes_file}"83 )8485 next_match = VERSION_HEADING_PATTERN.search(content, match.end())86 end = next_match.start() if next_match else len(content)87 body = content[match.end() : end].strip()88 if not body:89 raise RuntimeError(90 f"Release notes section for {version} in {release_notes_file} is empty"91 )92 return f"{body}\n"939495@app.command()96def prepare(97 bump: Annotated[98 BumpType,
71 unmodified lines
170) -> None:171 typer.echo(get_current_version(version_file.read_text(), version_file))172173174@app.command()175def release_notes(176 version_file: Annotated[177 Path,178 typer.Option(179 envvar="PREPARE_RELEASE_VERSION_FILE",180 exists=True,181 file_okay=True,182 dir_okay=False,183 readable=True,184 help="Path to the Python file containing the __version__ assignment.",185 ),186 ],187 release_notes_file: Annotated[188 Path,189 typer.Option(190 envvar="PREPARE_RELEASE_RELEASE_NOTES_FILE",191 exists=True,192 file_okay=True,193 dir_okay=False,194 readable=True,195 help="Path to the release notes Markdown file.",196 ),197 ],198) -> None:199 version = get_current_version(version_file.read_text(), version_file)200 typer.echo(201 get_release_notes_body(202 release_notes_file.read_text(), version, release_notes_file203 ),204 nl=False,205 )206207208if __name__ == "__main__":209 app()
modified:tests/test_prepare_release.py+124 added
6 unmodified lines
7from scripts.prepare_release import (8 BumpType,9 app,10 bump_version,11 get_release_notes_body,12 update_release_notes,13 update_version_file,14)15
81 unmodified lines
97 content, "0.26.3", date(2026, 5, 28), Path("docs/release-notes.md")98 )99100101def test_get_release_notes_body_with_dated_heading() -> None:102 content = """# Release Notes103104## Latest Changes105106## 0.26.3 (2026-05-28)107108### Fixes109110* Fix something.111112## 0.26.2 (2026-05-27)113114### Fixes115116* Previous fix.117"""118119 body = get_release_notes_body(content, "0.26.3", Path("docs/release-notes.md"))120121 assert (122 body123 == """### Fixes124125* Fix something.126"""127 )128129130def test_get_release_notes_body_with_plain_heading() -> None:131 content = """# Release Notes132133## Latest Changes134135## 0.26.3136137### Fixes138139* Fix something.140"""141142 body = get_release_notes_body(content, "0.26.3", Path("docs/release-notes.md"))143144 assert body == "### Fixes\n\n* Fix something.\n"145146147def test_get_release_notes_body_allows_non_version_h2_content() -> None:148 content = """# Release Notes149150## Latest Changes151152## 0.26.3153154## Highlights155156* Fix something.157158## 0.26.2159160* Previous fix.161"""162163 body = get_release_notes_body(content, "0.26.3", Path("docs/release-notes.md"))164165 assert body == "## Highlights\n\n* Fix something.\n"166167168def test_get_release_notes_body_requires_version_section() -> None:169 content = "# Release Notes\n\n## Latest Changes\n"170171 with pytest.raises(RuntimeError, match="Could not find"):172 get_release_notes_body(content, "0.26.3", Path("docs/release-notes.md"))173174175def test_get_release_notes_body_requires_non_empty_section() -> None:176 content = """# Release Notes177178## Latest Changes179180## 0.26.3181182## 0.26.2183184* Previous fix.185"""186187 with pytest.raises(RuntimeError, match="is empty"):188 get_release_notes_body(content, "0.26.3", Path("docs/release-notes.md"))189190191def test_cli_updates_configured_files(tmp_path: Path) -> None:192 version_file = tmp_path / "package" / "__init__.py"193 version_file.parent.mkdir()194 version_file.write_text('__version__ = "0.26.2"\n')
64 unmodified lines
259 )260261 assert result.exit_code == 0, result.output262 assert result.output == "0.26.2\n"263264265def test_cli_prints_release_notes(tmp_path: Path) -> None:266 version_file = tmp_path / "package" / "__init__.py"267 version_file.parent.mkdir()268 version_file.write_text('__version__ = "0.26.3"\n')269 release_notes_file = tmp_path / "release-notes.md"270 release_notes_file.write_text(271 """# Release Notes272273## Latest Changes274275## 0.26.3 (2026-05-28)276277### Fixes278279* Fix something.280"""281 )282283 result = runner.invoke(284 app,285 [286 "release-notes",287 "--version-file",288 str(version_file),289 "--release-notes-file",290 str(release_notes_file),291 ],292 )293294 assert result.exit_code == 0, result.output295 assert result.output == "### Fixes\n\n* Fix something.\n"