-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.py
More file actions
48 lines (40 loc) · 1.55 KB
/
helpers.py
File metadata and controls
48 lines (40 loc) · 1.55 KB
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
import subprocess
def update_changelog_file(
changelog_path: str,
release_notes: str,
log: 'logging.Logger'
):
"""Prepend the given release notes to CHANGELOG.md."""
# TODO: exceptions
try:
with open(changelog_path, 'r') as changelog:
original_contents = changelog.read()
with open(changelog_path, 'w') as changelog:
changelog.write(release_notes + "\n" + original_contents)
except OSError as exc:
log.exception('An unknown error occurred while updating the changelog file.')
raise exc
def run_subprocess(args: list, cwd: str=None):
"""Run the local command described by `args` with some defaults applied."""
return subprocess.run(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, # Combine out/err into stdout; stderr will be None
universal_newlines=True,
check=True,
cwd=cwd,
)
def bump_version(version: str, release_type: str) -> str:
"""Perform a version bump in accordance with semver.org."""
if release_type == 'Hotfix': # Don't bump the version number, just append the suffix
return str(version) + '-Hotfix'
else:
MAJOR = 0
MINOR = 1
PATCH = 2
# TODO: exceptions
release_type = vars()[release_type.upper()]
version_array = [int(x) for x in version.split('.', 2)]
version_array[release_type] += 1
version_array[release_type+1:] = [0] * (PATCH - release_type)
return '.'.join(str(version) for version in version_array)