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