Skip to content

Commit 646771a

Browse files
committed
Streamline release process
1 parent 8520e7d commit 646771a

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ Commands defined in `tasks.py`:
2929
invoke test
3030
```
3131
[Git Bash](https://git-scm.com) is recommended for Windows.
32+
33+
## Release
34+
* Run `invoke prerelease`
35+
* Verify the changes and `git add` them
36+
* Run `invoke release`
37+
* Create a release on GitHub for the new tag and attach the artifacts from `dist`

tasks.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
2+
import re
23
import shutil
4+
import sys
5+
import datetime as dt
36
from pathlib import Path
47

58
from invoke import task
@@ -16,7 +19,19 @@ def get_version() -> str:
1619
if line.startswith("version ="):
1720
return line.replace("version = ", "").strip('"')
1821

19-
return "0.0.0"
22+
raise RuntimeError("Could not determine version")
23+
24+
25+
def replace_pattern_in_file(file: Path, old: str, new: str, count: int = 1):
26+
content = file.read_text("utf-8")
27+
updated = re.sub(old, new, content, count=count)
28+
file.write_text(updated, "utf-8")
29+
30+
31+
def confirm(prompt: str):
32+
response = input(f"Confirm by typing '{prompt}': ")
33+
if response.lower() != prompt.lower():
34+
sys.exit(1)
2035

2136

2237
@task
@@ -125,3 +140,37 @@ def docs(ctx):
125140
joined = " ".join(arg if " " not in arg else f'"{arg}"' for arg in args)
126141

127142
ctx.run(joined)
143+
144+
145+
@task
146+
def prerelease(ctx, new_version):
147+
date = dt.datetime.now().strftime("%Y-%m-%d")
148+
149+
replace_pattern_in_file(
150+
ROOT / "pyproject.toml",
151+
'version = ".+"',
152+
f'version = "{new_version}"',
153+
)
154+
155+
replace_pattern_in_file(
156+
ROOT / "CHANGELOG.md",
157+
"## Unreleased",
158+
f"## v{new_version} ({date})",
159+
)
160+
161+
build(ctx, clean=True)
162+
docs(ctx)
163+
164+
165+
@task
166+
def release(ctx):
167+
version = get_version()
168+
169+
confirm(f"release {version}")
170+
171+
ctx.run(f'git commit -m "Release v{version}"')
172+
ctx.run(f'git tag v{version} -m "Release"')
173+
ctx.run("git push")
174+
ctx.run("git push origin tag v{version}")
175+
176+
ctx.run("poetry publish")

0 commit comments

Comments
 (0)