2022-09-06 09:24:16 -06:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shlex
|
|
|
|
import stat
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-12-10 18:54:20 -07:00
|
|
|
from packaging import version as pv
|
2022-09-06 09:24:16 -06:00
|
|
|
|
2022-12-19 09:06:47 -07:00
|
|
|
from tools.list_distros import generate_help, export_distros
|
2022-09-06 09:24:16 -06:00
|
|
|
from tools.reformat_readme import reformat_readme
|
|
|
|
|
2022-11-15 21:37:09 -07:00
|
|
|
NEOFETCH_NEW_VERSION = ""
|
|
|
|
|
|
|
|
|
2022-09-06 09:24:16 -06:00
|
|
|
def pre_check():
|
|
|
|
"""
|
|
|
|
Check source code status before releasing.
|
|
|
|
"""
|
|
|
|
assert os.path.isfile('./neofetch'), './neofetch doesn\'t exist, you are running this script in the wrong directory'
|
|
|
|
assert os.stat('./neofetch').st_mode & stat.S_IEXEC, 'neofetch is not executable'
|
|
|
|
assert os.path.islink('./hyfetch/scripts/neowofetch'), 'neowofetch is not a symbolic link'
|
|
|
|
# subprocess.check_call(shlex.split('git diff-index --quiet HEAD --')) # 'Please commit all changes before release'
|
|
|
|
|
|
|
|
subprocess.check_call(shlex.split('shellcheck neofetch'))
|
|
|
|
|
|
|
|
|
|
|
|
def edit_versions(version: str):
|
|
|
|
"""
|
|
|
|
Edit version numbers in hyfetch/constants.py, package.json, and README.md
|
|
|
|
|
|
|
|
Also edits version number of neofetch, but the neofetch version number is separate.
|
|
|
|
|
|
|
|
:param version: Version to release
|
|
|
|
"""
|
|
|
|
# 1. package.json
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Editing package.json...')
|
2022-09-06 09:24:16 -06:00
|
|
|
path = Path('package.json')
|
|
|
|
content = json.loads(path.read_text())
|
|
|
|
cur = pv.parse(content['version'])
|
|
|
|
assert cur < pv.parse(version), 'Version did not increase'
|
|
|
|
content['version'] = version
|
|
|
|
path.write_text(json.dumps(content, ensure_ascii=False, indent=2))
|
|
|
|
|
|
|
|
# 2. hyfetch/constants.py
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Editing hyfetch/constants.py...')
|
2022-09-06 09:24:16 -06:00
|
|
|
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
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Editing README.md...')
|
2022-09-06 09:24:16 -06:00
|
|
|
path = Path('README.md')
|
|
|
|
content = path.read_text()
|
2023-01-14 20:03:56 -07:00
|
|
|
changelog_token = '<!-- CHANGELOG STARTS HERE --->'
|
|
|
|
changelog_i = content.index(changelog_token) + len(changelog_token)
|
|
|
|
content = content[:changelog_i] + f'\n\n### {version}' + content[changelog_i:]
|
2022-09-06 09:24:16 -06:00
|
|
|
path.write_text(content)
|
|
|
|
|
|
|
|
# 4. neofetch script
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Editing neofetch...')
|
2022-09-06 09:24:16 -06:00
|
|
|
path = Path('neofetch')
|
|
|
|
lines = path.read_text().split('\n')
|
|
|
|
version_i = next(i for i, l in enumerate(lines) if l.startswith('version='))
|
|
|
|
nf = pv.parse(lines[version_i].replace('version=', ''))
|
|
|
|
new = pv.parse(version)
|
|
|
|
nf = f'{nf.major + new.major - cur.major}.{nf.minor + new.minor - cur.minor}.{nf.micro + new.micro - cur.micro}'
|
|
|
|
lines[version_i] = f"version={nf}"
|
|
|
|
path.write_text('\n'.join(lines))
|
|
|
|
|
2022-11-15 21:37:09 -07:00
|
|
|
global NEOFETCH_NEW_VERSION
|
|
|
|
NEOFETCH_NEW_VERSION = nf
|
|
|
|
|
2022-09-06 09:24:16 -06:00
|
|
|
|
2022-09-06 09:30:51 -06:00
|
|
|
def finalize_neofetch():
|
|
|
|
"""
|
|
|
|
Finalize current version
|
|
|
|
"""
|
|
|
|
# 1. Update distro list
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Updating distro list in neofetch...')
|
2022-09-06 09:30:51 -06:00
|
|
|
path = Path('neofetch')
|
|
|
|
content = path.read_text()
|
|
|
|
content = re.compile(r'(?<=# Flag: --ascii_distro\n#\n).*?(?=ascii_distro=)', re.DOTALL)\
|
|
|
|
.sub(generate_help(100, '# ') + '\n', content)
|
|
|
|
content = re.compile(r"""(?<=Which Distro's ascii art to print\n\n).*?{distro}_small to use them\.""", re.DOTALL)\
|
|
|
|
.sub(generate_help(100, ' ' * 32), content)
|
|
|
|
path.write_text(content)
|
|
|
|
|
|
|
|
# 2. Regenerate man page
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Regenerating neofetch man page...')
|
2022-09-06 09:30:51 -06:00
|
|
|
Path('neofetch.1').write_text(subprocess.check_output(['help2man', './neofetch']).decode())
|
|
|
|
|
|
|
|
# 3. Reformat readme links
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Reformatting readme links...')
|
2022-09-06 09:30:51 -06:00
|
|
|
reformat_readme()
|
|
|
|
|
2022-09-06 10:05:53 -06:00
|
|
|
|
|
|
|
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
|
2022-12-19 09:09:29 -07:00
|
|
|
subprocess.check_call(['git', 'add', 'hyfetch/constants.py', 'neofetch', 'neofetch.1', 'package.json', 'README.md',
|
|
|
|
'hyfetch/distros/*'])
|
2022-09-06 10:05:53 -06:00
|
|
|
|
|
|
|
# 2. Commit
|
|
|
|
subprocess.check_call(['git', 'commit', '-m', f'[U] Release {v}'])
|
|
|
|
|
|
|
|
# 3. Create tag
|
|
|
|
subprocess.check_call(['git', 'tag', v])
|
2022-11-15 21:37:09 -07:00
|
|
|
subprocess.check_call(['git', 'tag', f'neofetch-{NEOFETCH_NEW_VERSION}'])
|
2022-09-06 10:05:53 -06:00
|
|
|
|
|
|
|
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'])
|
2022-09-06 10:20:37 -06:00
|
|
|
subprocess.check_call(['git', 'push', 'origin', v])
|
2022-12-19 09:17:22 -07:00
|
|
|
subprocess.check_call(['git', 'push', 'origin', f'neofetch-{NEOFETCH_NEW_VERSION}'])
|
2022-09-06 10:05:53 -06:00
|
|
|
|
|
|
|
|
|
|
|
def deploy():
|
|
|
|
"""
|
|
|
|
Deploy release to pip and npm
|
|
|
|
"""
|
|
|
|
print('Deploying to pypi...')
|
2022-09-06 10:18:58 -06:00
|
|
|
subprocess.check_call(['bash', 'tools/deploy.sh'])
|
2022-09-06 10:05:53 -06:00
|
|
|
print('Done!')
|
|
|
|
|
|
|
|
print('Deploying to npm...')
|
|
|
|
otp = input('Please provide 2FA OTP for NPM: ')
|
|
|
|
subprocess.check_call(['npm', 'publish', '--otp', otp])
|
|
|
|
print('Done!')
|
|
|
|
|
|
|
|
|
2022-09-06 09:24:16 -06:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='HyFetch Release Utility')
|
|
|
|
parser.add_argument('version', help='Version to release')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
pre_check()
|
2022-12-19 09:06:47 -07:00
|
|
|
export_distros()
|
2022-09-06 09:24:16 -06:00
|
|
|
edit_versions(args.version)
|
2022-09-06 09:30:51 -06:00
|
|
|
finalize_neofetch()
|
2022-09-06 10:05:53 -06:00
|
|
|
post_check()
|
|
|
|
create_release(args.version)
|
|
|
|
deploy()
|
2022-09-06 09:24:16 -06:00
|
|
|
|