]> jfr.im git - yt-dlp.git/blame - devscripts/update-version.py
[devscripts] Create `utils` and refactor
[yt-dlp.git] / devscripts / update-version.py
CommitLineData
cc52de43 1#!/usr/bin/env python3
54007a45 2
3# Allow direct execution
4import os
5import sys
6
7sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9
115add43 10import contextlib
36eaf303 11import subprocess
f8271158 12import sys
13from datetime import datetime
915f2a92 14
115add43 15from devscripts.utils import read_version, write_file
915f2a92 16
915f2a92 17
115add43 18def get_new_version(revision):
19 version = datetime.utcnow().strftime('%Y.%m.%d')
915f2a92 20
115add43 21 if revision:
22 assert revision.isdigit(), 'Revision must be a number'
23 else:
24 old_version = read_version().split('.')
25 if version.split('.') == old_version[:3]:
26 revision = str(int((old_version + [0])[3]) + 1)
75b725a7 27
115add43 28 return f'{version}.{revision}' if revision else version
915f2a92 29
915f2a92 30
115add43 31def get_git_head():
32 with contextlib.suppress(Exception):
33 sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE)
34 return sp.communicate()[0].decode().strip() or None
35
36
37VERSION = get_new_version((sys.argv + [''])[1])
38GIT_HEAD = get_git_head()
36eaf303 39
b69fd25c 40VERSION_FILE = f'''\
36eaf303 41# Autogenerated by devscripts/update-version.py
915f2a92 42
36eaf303 43__version__ = {VERSION!r}
5b328c97 44
36eaf303 45RELEASE_GIT_HEAD = {GIT_HEAD!r}
b69fd25c 46'''
36eaf303 47
115add43 48write_file('yt_dlp/version.py', VERSION_FILE)
49print(f'::set-output name=ytdlp_version::{VERSION}')
36eaf303 50print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}')