-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |