]> jfr.im git - yt-dlp.git/blame - devscripts/update-version.py
[cleanup] Minor fixes (See desc)
[yt-dlp.git] / devscripts / update-version.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
36eaf303 2import subprocess
f8271158 3import sys
4from datetime import datetime
915f2a92 5
86e5f3ed 6with open('yt_dlp/version.py') as f:
36eaf303 7 exec(compile(f.read(), 'yt_dlp/version.py', 'exec'))
e38df8f9 8old_version = locals()['__version__']
915f2a92 9
36eaf303 10old_version_list = old_version.split('.')
915f2a92 11
e38df8f9 12old_ver = '.'.join(old_version_list[:3])
13old_rev = old_version_list[3] if len(old_version_list) > 3 else ''
915f2a92 14
f3b7c693 15ver = datetime.utcnow().strftime("%Y.%m.%d")
75b725a7 16
17rev = (sys.argv[1:] or [''])[0] # Use first argument, if present as revision number
18if not rev:
19 rev = str(int(old_rev or 0) + 1) if old_ver == ver else ''
915f2a92 20
e38df8f9 21VERSION = '.'.join((ver, rev)) if rev else ver
915f2a92 22
36eaf303 23try:
24 sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE)
25 GIT_HEAD = sp.communicate()[0].decode().strip() or None
26except Exception:
27 GIT_HEAD = None
28
b69fd25c 29VERSION_FILE = f'''\
36eaf303 30# Autogenerated by devscripts/update-version.py
915f2a92 31
36eaf303 32__version__ = {VERSION!r}
5b328c97 33
36eaf303 34RELEASE_GIT_HEAD = {GIT_HEAD!r}
b69fd25c 35'''
36eaf303 36
37with open('yt_dlp/version.py', 'wt') as f:
38 f.write(VERSION_FILE)
39
40print('::set-output name=ytdlp_version::' + VERSION)
41print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}')