Skip to content

Commit 099bf68

Browse files
committed
Add publish and bump helper scripts
1 parent ec67bf4 commit 099bf68

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

scripts/bump.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import io
4+
import os
5+
import re
6+
import sys
7+
8+
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
9+
PACKAGES = ('v8-android', 'v8-android-nointl')
10+
11+
12+
class PackageConfigPatcher:
13+
def __init__(self, root, version):
14+
self._config_path = os.path.join(root, 'package.json')
15+
self._version = version
16+
17+
@classmethod
18+
def _replace_file_content(cls,
19+
file_path,
20+
old_pattern,
21+
new_pattern,
22+
re_flags=0):
23+
with io.open(file_path, 'r', encoding='utf8') as f:
24+
content = str(f.read())
25+
new_content = re.sub(old_pattern,
26+
new_pattern,
27+
content,
28+
flags=re_flags)
29+
with io.open(file_path, 'w', encoding='utf8') as f:
30+
f.write(new_content)
31+
32+
def patch(self):
33+
self._replace_file_content(self._config_path, r'("version": )("[^"]+")(,)', '\\1"' + self._version + '"\\3')
34+
35+
def parse_args():
36+
arg_parser = argparse.ArgumentParser()
37+
38+
arg_parser.add_argument('--version', '-V', type=str, required=True, help='Bump packages version')
39+
40+
args = arg_parser.parse_args()
41+
return args
42+
43+
44+
def main():
45+
args = parse_args()
46+
version = args.version
47+
48+
PackageConfigPatcher(ROOT_DIR, version).patch()
49+
50+
for package in PACKAGES:
51+
print('\nBump {} package to version {}'.format(package, version))
52+
package_root = os.path.join(ROOT_DIR, 'packages', package)
53+
PackageConfigPatcher(package_root, version).patch()
54+
55+
if __name__ == '__main__':
56+
main()

scripts/publish.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import os
4+
import shutil
5+
import subprocess
6+
import sys
7+
8+
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
9+
PACKAGES = ('v8-android', 'v8-android-nointl')
10+
11+
12+
def parse_args():
13+
arg_parser = argparse.ArgumentParser()
14+
15+
arg_parser.add_argument('--dry-run',
16+
action='store_true',
17+
help='Dry run mode for npm publish')
18+
arg_parser.add_argument('--tag',
19+
'-T',
20+
type=str,
21+
required=True,
22+
help='NPM published tag')
23+
arg_parser.add_argument('dist_tar_file',
24+
action='store',
25+
help='dist.tgz created from CI')
26+
27+
args = arg_parser.parse_args()
28+
if not args.dist_tar_file:
29+
arg_parser.print_help()
30+
sys.exit(1)
31+
return args
32+
33+
34+
def main():
35+
args = parse_args()
36+
37+
workdir = os.path.join(ROOT_DIR, 'build', 'publish')
38+
if not os.path.exists(workdir):
39+
os.makedirs(workdir)
40+
subprocess.run(
41+
['tar', '-xf', args.dist_tar_file, '-C', workdir])
42+
43+
for package in PACKAGES:
44+
print('\n\n========== Publish {} package =========='.format(package))
45+
cwd = os.path.join(ROOT_DIR, 'packages', package)
46+
source_dir_in_tar_file = os.path.join(workdir, 'dist', 'packages', package)
47+
distdir = os.path.join(cwd, 'dist')
48+
if os.path.exists(distdir):
49+
shutil.rmtree(distdir)
50+
shutil.move(source_dir_in_tar_file, distdir)
51+
cmds = ['npm', 'publish', '--tag', args.tag]
52+
if args.dry_run:
53+
cmds.append('--dry-run')
54+
subprocess.run(cmds, cwd=cwd)
55+
56+
shutil.rmtree(workdir)
57+
58+
59+
if __name__ == '__main__':
60+
main()

0 commit comments

Comments
 (0)