-
Notifications
You must be signed in to change notification settings - Fork 5
/
release.py
70 lines (55 loc) · 1.61 KB
/
release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import shlex
import subprocess
import click
@click.command(
help="""A little release script.
Cut a release and publish it.
"""
)
@click.option(
"--bump",
type=str,
required=True,
help="""
The version label for bumping.\n
Use either "major", "minor", "patch" or the version number.\n
Will be passed to `poetry version {bump}`.""",
)
def start(bump: str):
"""
Run the whole shebang.
:param bump: The version bump identifier (major, minor, patch) or the version number.
:return:
"""
# Bump version.
run(f"poetry version {bump}")
# Get new version.
version = run("poetry version --short").strip()
# Commit version in "pyproject.toml".
run(f'git commit pyproject.toml CHANGES.rst -m "Bump version to {version}"')
# Tag repository.
run(f"git tag {version}")
# Push repository.
run("git push")
run("git push --tags")
# Build wheels and publish to PyPI.
run("poetry build")
run("poetry publish")
def run(cmd, **kwargs) -> str:
"""
Wrapper around ``subprocess.check_output()`` for conveniently running commands.
:param cmd: The command.
:param kwargs: **kwargs will get passed through to ``subprocess.Popen()``.
:return: The content on stdout.
"""
cmd = shlex.split(cmd)
try:
stdout = subprocess.check_output(cmd, **kwargs)
except subprocess.CalledProcessError as ex:
print(ex.stdout.decode("utf-8"))
if ex.stderr:
print(ex.stderr.decode("utf-8"))
raise
outcome = stdout.decode("utf-8")
print(outcome)
return outcome