From 36eaf3039a5d96d4f8ebb644b1ab3b0ad4136cd0 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 29 Nov 2021 22:30:02 +0530 Subject: [PATCH] [build] Save Git HEAD at release alongside version info --- .github/workflows/build.yml | 2 -- devscripts/update-version.py | 39 ++++++++++++++++++++---------------- yt_dlp/YoutubeDL.py | 34 ++++++++++++++++++------------- yt_dlp/version.py | 4 +++- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f75b11700..3d3df9426 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,6 @@ jobs: run: | python devscripts/update-version.py make issuetemplates - - name: Print version - run: echo "${{ steps.bump_version.outputs.ytdlp_version }}" - name: Update master id: push_update run: | diff --git a/devscripts/update-version.py b/devscripts/update-version.py index 2d1673d0e..770926f0c 100644 --- a/devscripts/update-version.py +++ b/devscripts/update-version.py @@ -1,16 +1,13 @@ #!/usr/bin/env python3 -from __future__ import unicode_literals - from datetime import datetime -# import urllib.request +import subprocess -# response = urllib.request.urlopen('https://blackjack4494.github.io/youtube-dlc/update/LATEST_VERSION') -# old_version = response.read().decode('utf-8') -exec(compile(open('yt_dlp/version.py').read(), 'yt_dlp/version.py', 'exec')) +with open('yt_dlp/version.py', 'rt') as f: + exec(compile(f.read(), 'yt_dlp/version.py', 'exec')) old_version = locals()['__version__'] -old_version_list = old_version.split(".", 4) +old_version_list = old_version.split('.') old_ver = '.'.join(old_version_list[:3]) old_rev = old_version_list[3] if len(old_version_list) > 3 else '' @@ -19,15 +16,23 @@ rev = str(int(old_rev or 0) + 1) if old_ver == ver else '' VERSION = '.'.join((ver, rev)) if rev else ver -# VERSION_LIST = [(int(v) for v in ver.split(".") + [rev or 0])] + +try: + sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE) + GIT_HEAD = sp.communicate()[0].decode().strip() or None +except Exception: + GIT_HEAD = None + +VERSION_FILE = f''' +# Autogenerated by devscripts/update-version.py + +__version__ = {VERSION!r} + +RELEASE_GIT_HEAD = {GIT_HEAD!r} +'''.lstrip() + +with open('yt_dlp/version.py', 'wt') as f: + f.write(VERSION_FILE) print('::set-output name=ytdlp_version::' + VERSION) - -file_version_py = open('yt_dlp/version.py', 'rt') -data = file_version_py.read() -data = data.replace(old_version, VERSION) -file_version_py.close() - -file_version_py = open('yt_dlp/version.py', 'wt') -file_version_py.write(data) -file_version_py.close() +print(f'\nVersion = {VERSION}, Git HEAD = {GIT_HEAD}') diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 5e2b633b7..8a3accf53 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -153,7 +153,7 @@ _PLUGIN_CLASSES as plugin_postprocessors ) from .update import detect_variant -from .version import __version__ +from .version import __version__, RELEASE_GIT_HEAD if compat_os_name == 'nt': import ctypes @@ -3401,7 +3401,11 @@ def get_encoding(stream): write_debug = lambda msg: self._write_string(f'[debug] {msg}\n') source = detect_variant() - write_debug('yt-dlp version %s%s' % (__version__, '' if source == 'unknown' else f' ({source})')) + write_debug(join_nonempty( + 'yt-dlp version', __version__, + f'[{RELEASE_GIT_HEAD}]' if RELEASE_GIT_HEAD else '', + '' if source == 'unknown' else f'({source})', + delim=' ')) if not _LAZY_LOADER: if os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'): write_debug('Lazy loading extractors is forcibly disabled') @@ -3413,20 +3417,22 @@ def get_encoding(stream): for name, klass in itertools.chain(plugin_extractors.items(), plugin_postprocessors.items())]) if self.params.get('compat_opts'): write_debug('Compatibility options: %s' % ', '.join(self.params.get('compat_opts'))) - try: - sp = Popen( - ['git', 'rev-parse', '--short', 'HEAD'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=os.path.dirname(os.path.abspath(__file__))) - out, err = sp.communicate_or_kill() - out = out.decode().strip() - if re.match('[0-9a-f]+', out): - write_debug('Git HEAD: %s' % out) - except Exception: + + if source == 'source': try: - sys.exc_clear() + sp = Popen( + ['git', 'rev-parse', '--short', 'HEAD'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cwd=os.path.dirname(os.path.abspath(__file__))) + out, err = sp.communicate_or_kill() + out = out.decode().strip() + if re.match('[0-9a-f]+', out): + write_debug('Git HEAD: %s' % out) except Exception: - pass + try: + sys.exc_clear() + except Exception: + pass def python_implementation(): impl_name = platform.python_implementation() diff --git a/yt_dlp/version.py b/yt_dlp/version.py index 5290afa2d..aa8fd80a3 100644 --- a/yt_dlp/version.py +++ b/yt_dlp/version.py @@ -1,3 +1,5 @@ -from __future__ import unicode_literals +# Autogenerated by devscripts/update-version.py __version__ = '2021.11.10.1' + +RELEASE_GIT_HEAD = '7144b697f'