From d8ce41a2128d290e7720faa4df7f41480bdc8971 Mon Sep 17 00:00:00 2001 From: "Azalea (on HyDEV-Daisy)" Date: Tue, 6 Sep 2022 12:05:53 -0400 Subject: [PATCH] [U] Deploy tool: Automatically create release and deploy --- tools/deploy-release.py | 55 +++++++++++++++++++++++++++++++++++++++++ tools/deploy.md | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) mode change 100644 => 100755 tools/deploy-release.py diff --git a/tools/deploy-release.py b/tools/deploy-release.py old mode 100644 new mode 100755 index 552b1eec..d30fb734 --- a/tools/deploy-release.py +++ b/tools/deploy-release.py @@ -37,6 +37,7 @@ def edit_versions(version: str): :param version: Version to release """ # 1. package.json + print('Editing package.json...') path = Path('package.json') content = json.loads(path.read_text()) cur = pv.parse(content['version']) @@ -45,11 +46,13 @@ def edit_versions(version: str): path.write_text(json.dumps(content, ensure_ascii=False, indent=2)) # 2. hyfetch/constants.py + print('Editing hyfetch/constants.py...') path = Path('hyfetch/constants.py') content = [f"VERSION = '{version}'" if l.startswith('VERSION = ') else l for l in path.read_text().split('\n')] path.write_text('\n'.join(content)) # 3. README.md + print('Editing README.md...') path = Path('README.md') content = path.read_text() changelog_i = content.index('') @@ -59,6 +62,7 @@ def edit_versions(version: str): path.write_text(content) # 4. neofetch script + print('Editing neofetch...') path = Path('neofetch') lines = path.read_text().split('\n') version_i = next(i for i, l in enumerate(lines) if l.startswith('version=')) @@ -74,6 +78,7 @@ def finalize_neofetch(): Finalize current version """ # 1. Update distro list + print('Updating distro list in neofetch...') path = Path('neofetch') content = path.read_text() content = re.compile(r'(?<=# Flag: --ascii_distro\n#\n).*?(?=ascii_distro=)', re.DOTALL)\ @@ -83,11 +88,58 @@ def finalize_neofetch(): path.write_text(content) # 2. Regenerate man page + print('Regenerating neofetch man page...') Path('neofetch.1').write_text(subprocess.check_output(['help2man', './neofetch']).decode()) # 3. Reformat readme links + print('Reformatting readme links...') reformat_readme() + +def post_check(): + """ + Check after changes are made + """ + subprocess.check_call(shlex.split('shellcheck neofetch')) + + +def create_release(v: str): + """ + Create release commit and tag + """ + print('Committing changes...') + + # 1. Add files + subprocess.check_call(['git', 'add', 'hyfetch/constants.py', 'neofetch', 'neofetch.1', 'package.json', 'README.md']) + + # 2. Commit + subprocess.check_call(['git', 'commit', '-m', f'[U] Release {v}']) + + # 3. Create tag + subprocess.check_call(['git', 'tag', v]) + + i = input('Please check the commit is correct. Press y to continue or any other key to cancel.') + assert i == 'y' + + # 4. Push + print('Pushing commits...') + subprocess.check_call(['git', 'push']) + + +def deploy(): + """ + Deploy release to pip and npm + """ + print('Deploying to pypi...') + subprocess.check_call(['bash', './deploy.sh']) + print('Done!') + + print('Deploying to npm...') + otp = input('Please provide 2FA OTP for NPM: ') + subprocess.check_call(['npm', 'publish', '--otp', otp]) + print('Done!') + + if __name__ == '__main__': parser = argparse.ArgumentParser(description='HyFetch Release Utility') parser.add_argument('version', help='Version to release') @@ -97,4 +149,7 @@ if __name__ == '__main__': pre_check() edit_versions(args.version) finalize_neofetch() + post_check() + create_release(args.version) + deploy() diff --git a/tools/deploy.md b/tools/deploy.md index 33d54240..605b3cdc 100644 --- a/tools/deploy.md +++ b/tools/deploy.md @@ -7,5 +7,5 @@ * [x] Regenerate man page (`help2man ./neofetch > neofetch.1`) * [ ] Create an RC release and deploy to pypi, try installing and testing on many distros. * [ ] Change back to stable release, create tag, create GitHub release -* [ ] Formally deploy to pypi and npm (`tools/deploy.sh`, `npm publish`) +* [x] Formally deploy to pypi and npm (`tools/deploy.sh`, `npm publish`) * [ ] Update ArchLinux AUR and NixOS packaging