]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | # Allow direct execution | |
4 | import os | |
5 | import sys | |
6 | ||
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
9 | ||
10 | import contextlib | |
11 | import subprocess | |
12 | import sys | |
13 | from datetime import datetime | |
14 | ||
15 | from devscripts.utils import read_version, write_file | |
16 | ||
17 | ||
18 | def get_new_version(revision): | |
19 | version = datetime.utcnow().strftime('%Y.%m.%d') | |
20 | ||
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) | |
27 | ||
28 | return f'{version}.{revision}' if revision else version | |
29 | ||
30 | ||
31 | def 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 | ||
37 | VERSION = get_new_version((sys.argv + [''])[1]) | |
38 | GIT_HEAD = get_git_head() | |
39 | ||
40 | VERSION_FILE = f'''\ | |
41 | # Autogenerated by devscripts/update-version.py | |
42 | ||
43 | __version__ = {VERSION!r} | |
44 | ||
45 | RELEASE_GIT_HEAD = {GIT_HEAD!r} | |
46 | ||
47 | VARIANT = None | |
48 | ||
49 | UPDATE_HINT = None | |
50 | ''' | |
51 | ||
52 | write_file('yt_dlp/version.py', VERSION_FILE) | |
53 | print(f'::set-output name=ytdlp_version::{VERSION}') | |
54 | print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}') |