]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 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 | ||
115add43 | 10 | import contextlib |
36eaf303 | 11 | import subprocess |
f8271158 | 12 | import sys |
13 | from datetime import datetime | |
915f2a92 | 14 | |
115add43 | 15 | from devscripts.utils import read_version, write_file |
915f2a92 | 16 | |
915f2a92 | 17 | |
115add43 | 18 | def 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 | 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() | |
36eaf303 | 39 | |
b69fd25c | 40 | VERSION_FILE = f'''\ |
36eaf303 | 41 | # Autogenerated by devscripts/update-version.py |
915f2a92 | 42 | |
36eaf303 | 43 | __version__ = {VERSION!r} |
5b328c97 | 44 | |
36eaf303 | 45 | RELEASE_GIT_HEAD = {GIT_HEAD!r} |
70b23409 | 46 | |
47 | VARIANT = None | |
48 | ||
49 | UPDATE_HINT = None | |
b69fd25c | 50 | ''' |
36eaf303 | 51 | |
115add43 | 52 | write_file('yt_dlp/version.py', VERSION_FILE) |
7d61d230 L |
53 | github_output = os.getenv('GITHUB_OUTPUT') |
54 | if github_output: | |
55 | write_file(github_output, f'ytdlp_version={VERSION}\n', 'a') | |
36eaf303 | 56 | print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}') |