Skip to content

Commit 13130e9

Browse files
committed
Automate generating GitHub releases
1 parent 518b5b6 commit 13130e9

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ jobs:
5353
- name: Install wheel
5454
run: |
5555
python -m pip install --upgrade pip
56-
pip install wheel
56+
pip install build
5757
- name: Build package
5858
run: |
59-
python setup.py sdist bdist_wheel
59+
python -m build
6060
- name: Publish package to PyPI
6161
uses: pypa/gh-action-pypi-publish@master
6262
with:
6363
user: __token__
6464
password: ${{ secrets.pypi_token }}
65+
- name: Generate release notes
66+
run: |
67+
pip install pypandoc
68+
python scripts/gen-release-notes.py
69+
- name: GitHub Release
70+
uses: softprops/action-gh-release@v1
71+
with:
72+
body_path: scripts/latest-release-notes.md

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ docs/_build/
6060
.idea
6161
.vscode
6262
/src/pytest_mock/_version.py
63+
scripts/latest-release-notes.md

scripts/gen-release-notes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Generates the release notes for the latest release, in Markdown.
3+
4+
Convert CHANGELOG.rst to Markdown, and extracts just the latest release.
5+
6+
Writes to ``scripts/latest-release-notes.md``, which can be
7+
used with https://github.com/softprops/action-gh-release.
8+
"""
9+
from pathlib import Path
10+
11+
import pypandoc
12+
13+
this_dir = Path(__file__).parent
14+
rst_text = (this_dir.parent / "CHANGELOG.rst").read_text(encoding="UTF-8")
15+
md_text = pypandoc.convert_text(
16+
rst_text, "md", format="rst", extra_args=["--wrap=preserve"]
17+
)
18+
19+
output_lines = []
20+
first_heading_found = False
21+
for line in md_text.splitlines():
22+
if line.startswith("# "):
23+
if first_heading_found:
24+
break
25+
first_heading_found = True
26+
output_lines.append(line)
27+
28+
output_fn = this_dir / "latest-release-notes.md"
29+
output_fn.write_text("\n".join(output_lines), encoding="UTF-8")
30+
print(output_fn, "generated.")

0 commit comments

Comments
 (0)