Skip to content

Commit

Permalink
Add publish and bump helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Nov 4, 2019
1 parent ec67bf4 commit 099bf68
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/bump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
import argparse
import io
import os
import re
import sys

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
PACKAGES = ('v8-android', 'v8-android-nointl')


class PackageConfigPatcher:
def __init__(self, root, version):
self._config_path = os.path.join(root, 'package.json')
self._version = version

@classmethod
def _replace_file_content(cls,
file_path,
old_pattern,
new_pattern,
re_flags=0):
with io.open(file_path, 'r', encoding='utf8') as f:
content = str(f.read())
new_content = re.sub(old_pattern,
new_pattern,
content,
flags=re_flags)
with io.open(file_path, 'w', encoding='utf8') as f:
f.write(new_content)

def patch(self):
self._replace_file_content(self._config_path, r'("version": )("[^"]+")(,)', '\\1"' + self._version + '"\\3')

def parse_args():
arg_parser = argparse.ArgumentParser()

arg_parser.add_argument('--version', '-V', type=str, required=True, help='Bump packages version')

args = arg_parser.parse_args()
return args


def main():
args = parse_args()
version = args.version

PackageConfigPatcher(ROOT_DIR, version).patch()

for package in PACKAGES:
print('\nBump {} package to version {}'.format(package, version))
package_root = os.path.join(ROOT_DIR, 'packages', package)
PackageConfigPatcher(package_root, version).patch()

if __name__ == '__main__':
main()
60 changes: 60 additions & 0 deletions scripts/publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
import argparse
import os
import shutil
import subprocess
import sys

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
PACKAGES = ('v8-android', 'v8-android-nointl')


def parse_args():
arg_parser = argparse.ArgumentParser()

arg_parser.add_argument('--dry-run',
action='store_true',
help='Dry run mode for npm publish')
arg_parser.add_argument('--tag',
'-T',
type=str,
required=True,
help='NPM published tag')
arg_parser.add_argument('dist_tar_file',
action='store',
help='dist.tgz created from CI')

args = arg_parser.parse_args()
if not args.dist_tar_file:
arg_parser.print_help()
sys.exit(1)
return args


def main():
args = parse_args()

workdir = os.path.join(ROOT_DIR, 'build', 'publish')
if not os.path.exists(workdir):
os.makedirs(workdir)
subprocess.run(
['tar', '-xf', args.dist_tar_file, '-C', workdir])

for package in PACKAGES:
print('\n\n========== Publish {} package =========='.format(package))
cwd = os.path.join(ROOT_DIR, 'packages', package)
source_dir_in_tar_file = os.path.join(workdir, 'dist', 'packages', package)
distdir = os.path.join(cwd, 'dist')
if os.path.exists(distdir):
shutil.rmtree(distdir)
shutil.move(source_dir_in_tar_file, distdir)
cmds = ['npm', 'publish', '--tag', args.tag]
if args.dry_run:
cmds.append('--dry-run')
subprocess.run(cmds, cwd=cwd)

shutil.rmtree(workdir)


if __name__ == '__main__':
main()

0 comments on commit 099bf68

Please sign in to comment.