diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2023-03-03 22:33:12 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-03-03 22:54:23 +0530 |
commit | 29cb20bd563c02671b31dd840139e93dd37150a1 (patch) | |
tree | c9198d47a705bdbd19d948919327b808bc11a4fe /devscripts/update-version.py | |
parent | d400e261cf029a3f20d364113b14de973be75404 (diff) | |
download | hypervideo-pre-29cb20bd563c02671b31dd840139e93dd37150a1.tar.lz hypervideo-pre-29cb20bd563c02671b31dd840139e93dd37150a1.tar.xz hypervideo-pre-29cb20bd563c02671b31dd840139e93dd37150a1.zip |
[build] Automated builds and nightly releases (#6220)
Closes #1839
Authored by: Grub4K, bashonly
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
Diffstat (limited to 'devscripts/update-version.py')
-rw-r--r-- | devscripts/update-version.py | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/devscripts/update-version.py b/devscripts/update-version.py index 9cf8b42e6..00c2d54cf 100644 --- a/devscripts/update-version.py +++ b/devscripts/update-version.py @@ -7,6 +7,7 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import argparse import contextlib import subprocess import sys @@ -15,8 +16,9 @@ from datetime import datetime from devscripts.utils import read_version, write_file -def get_new_version(revision): - version = datetime.utcnow().strftime('%Y.%m.%d') +def get_new_version(version, revision): + if not version: + version = datetime.utcnow().strftime('%Y.%m.%d') if revision: assert revision.isdigit(), 'Revision must be a number' @@ -30,27 +32,41 @@ def get_new_version(revision): def get_git_head(): with contextlib.suppress(Exception): - sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE) - return sp.communicate()[0].decode().strip() or None + return subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip() or None -VERSION = get_new_version((sys.argv + [''])[1]) -GIT_HEAD = get_git_head() - -VERSION_FILE = f'''\ +VERSION_TEMPLATE = '''\ # Autogenerated by devscripts/update-version.py -__version__ = {VERSION!r} +__version__ = {version!r} -RELEASE_GIT_HEAD = {GIT_HEAD!r} +RELEASE_GIT_HEAD = {git_head!r} VARIANT = None UPDATE_HINT = None + +CHANNEL = "{channel!r}" ''' -write_file('yt_dlp/version.py', VERSION_FILE) -github_output = os.getenv('GITHUB_OUTPUT') -if github_output: - write_file(github_output, f'ytdlp_version={VERSION}\n', 'a') -print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}') +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Update the version.py file') + parser.add_argument( + '-c', '--channel', choices=['stable', 'nightly'], default='stable', + help='Select update channel (default: %(default)s)') + parser.add_argument( + '-o', '--output', default='yt_dlp/version.py', + help='The output file to write to (default: %(default)s)') + parser.add_argument( + 'version', nargs='?', default=None, + help='A version or revision to use instead of generating one') + args = parser.parse_args() + + git_head = get_git_head() + version = ( + args.version if args.version and '.' in args.version + else get_new_version(None, args.version)) + write_file(args.output, VERSION_TEMPLATE.format( + version=version, git_head=git_head, channel=args.channel)) + + print(f'version={version} ({args.channel}), head={git_head}') |