forked from jupyter/nbdime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump_version.py
75 lines (59 loc) · 2 KB
/
bump_version.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
71
72
73
74
75
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import argparse
import shlex
import sys
from pathlib import Path
from subprocess import check_output, check_call
try:
from jupyter_releaser import run
except ImportError:
def run(cmd, **kwargs):
check_call(shlex.split(cmd), encoding="utf-8", **kwargs)
LERNA_CMD = "npx lerna version --no-push --no-git-tag-version"
def install_dependencies() -> None:
pkgs = []
try:
import hatch
except ImportError:
pkgs.append("hatch")
if pkgs:
run(f"{sys.executable} -m pip install {' '.join(pkgs)}")
def bump(force: bool, spec: str) -> None:
install_dependencies()
HERE = Path(__file__).parent.parent.resolve()
output = check_output(
shlex.split("git status --porcelain"), cwd=HERE, encoding="utf-8"
)
if len(output) > 0:
print(output)
raise Exception("Must be in a clean git state with no untracked files")
print(f"Executing 'python -m hatch version {spec}'...")
run(
f"{sys.executable} -m hatch version {spec}", cwd=HERE
)
# convert the Python version
lerna_cmd = LERNA_CMD
if spec in ["alpha", "a", "beta", "b", "rc"]:
js_spec = "--force-publish"
spec = "prerelease"
elif spec == "release":
js_spec = "--conventional-commits --no-changelog --conventional-graduate"
spec = ""
else:
js_spec = f"--force-publish"
# bump the JS packages
if force:
# This needs to be the latest option for weird reason
js_spec += " -y"
lerna_cmd += f" {js_spec} {spec}"
print(f"Executing '{lerna_cmd}'...")
run(lerna_cmd, cwd=HERE)
print(f"Changed made:")
run("git diff", cwd=HERE)
if __name__ == "__main__":
parser = argparse.ArgumentParser("bump_version", "Bump package version")
parser.add_argument("--force", action="store_true")
parser.add_argument("spec")
args = parser.parse_args()
bump(args.force, args.spec)