]> jfr.im git - yt-dlp.git/blame - devscripts/update-version.py
[devscripts] Script to generate changelog (#6220)
[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}
70b23409 46
47VARIANT = None
48
49UPDATE_HINT = None
b69fd25c 50'''
36eaf303 51
115add43 52write_file('yt_dlp/version.py', VERSION_FILE)
7d61d230
L
53github_output = os.getenv('GITHUB_OUTPUT')
54if github_output:
55 write_file(github_output, f'ytdlp_version={VERSION}\n', 'a')
36eaf303 56print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}')