-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
release.py
executable file
·153 lines (113 loc) · 4.69 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
description = """if run with no args, this script will:
1. determine the true project version from jupyterlab_hdf/_version.py
2. "version"
- force the version in package.json to agree
3. "tag"
- create a git version tag
- push said tag upstream
4. "pypi"
- build/bundle the labextension together with the python package
- do the pypi release
5. "npmjs"
- build the labextension
- do the npmjs release
"""
import argparse as argpar
import json
import subprocess
from packaging.version import parse
from setupbase import get_version
VERSION_FILE_PY = "jupyterlab_hdf/_version.py"
def assertEqualVersion():
serverVersion = parse(serverExtensionVersion())
frontendVersion = parse(labExtensionVersion())
error_msg = "Frontend ({}) and server ({}) version do not match".format(frontendVersion, serverVersion)
assert serverVersion == frontendVersion, error_msg
def prepLabextensionBundle():
subprocess.run(["jlpm", "install"], check=True)
subprocess.run(["jlpm", "clean:slate"], check=True)
def tag(version, dry_run=False, kind=None):
"""git tagging"""
kw = {"version": version, "kind": kind}
tag = "{kind}_v{version}".format(**kw) if kind else "v{version}".format(**kw)
if dry_run:
print("Would tag: {}".format(tag))
else:
subprocess.run(["git", "tag", "-a", tag], check=True)
subprocess.run(["git", "push", "--tags"], check=True)
def pypi(wheel=True, dry_run=False):
"""release on pypi"""
if wheel:
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "setuptools", "wheel"], check=True)
# build the source (sdist) and binary wheel (bdist_wheel) releases
subprocess.run(["python", "setup.py", "sdist", "bdist_wheel"], check=True)
else:
# build just the source release
subprocess.run(["python", "setup.py", "sdist"], check=True)
if dry_run:
# check the dist
subprocess.run(["twine", "check", "dist/*"], check=True)
else:
# release to the production pypi server
subprocess.run(["twine", "upload", "dist/*"], check=True)
def npmjs(dry_run=False):
"""release on npmjs"""
if dry_run:
# dry run build and release
subprocess.run(["npm", "publish", "--access", "public", "--dry-run"], check=True)
else:
# build and release
subprocess.run(["npm", "publish", "--access", "public"], check=True)
def labExtensionVersion(dry_run=False, version=None):
if version:
if "rc" in version:
version, rc = version.split("rc")
version = version + "-rc.{}".format(rc)
force_ver_cmd = ["npm", "--no-git-tag-version", "version", version, "--force", "--allow-same-version"]
force_ver_info = " ".join(force_ver_cmd)
if dry_run:
print("Would force npm version with: {}".format(force_ver_info))
else:
# force the labextension version to match the supplied version
print("> {}".format(force_ver_info))
subprocess.run(force_ver_cmd, check=True)
else:
# get single source of truth from the Typescript labextension
with open("package.json") as f:
info = json.load(f)
version = info["version"]
return version
def serverExtensionVersion():
# get single source of truth from the Python serverextension
return get_version(VERSION_FILE_PY)
def doRelease(actions, dry_run=False):
# treat the serverextension version as the "real" single source of truth
version = serverExtensionVersion()
if "version" in actions:
# force the labextension version to agree with the serverextension version
labExtensionVersion(dry_run=dry_run, version=version)
if "tag" in actions:
# tag with version and push the tag
tag(dry_run=dry_run, version=version)
if "pypi" in actions or "npmjs" in actions:
# prep the build area for the labextension bundle
prepLabextensionBundle()
if "pypi" in actions:
# release to pypi
pypi(dry_run=dry_run)
if "npmjs" in actions:
# release to npmjs
npmjs(dry_run=dry_run)
def main():
parser = argpar.ArgumentParser(description=description)
parser.add_argument("--dry-run", action="store_true", help="Performs a dry run of all release actions")
parser.add_argument(
"--actions", nargs="*", choices={"version", "tag", "pypi", "npmjs"}, default={"version", "tag", "pypi", "npmjs"}, help="optionally select a subset of the release actions to perform"
)
parsed = vars(parser.parse_args())
actions = parsed["actions"]
dry_run = parsed["dry_run"]
doRelease(actions, dry_run=dry_run)
if __name__ == "__main__":
main()