mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
dvc: version: detect release
See failed release at [1]. Previously we used to look at TRAVIS_TAG env var, but now we will try to detect release by matching current tag with base version. [1] https://travis-ci.com/iterative/dvc/builds/107365596 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+18
-1
@@ -3,6 +3,9 @@ import os
|
||||
import subprocess
|
||||
|
||||
|
||||
BASE_VERSION = "0.35.0"
|
||||
|
||||
|
||||
def generate_version(base_version):
|
||||
"""Generate a version with information about the git repository"""
|
||||
pkg_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
@@ -10,6 +13,9 @@ def generate_version(base_version):
|
||||
if not is_git_repo(pkg_dir) or not have_git():
|
||||
return base_version
|
||||
|
||||
if is_release(pkg_dir, base_version):
|
||||
return base_version
|
||||
|
||||
return "{base_version}+{short_sha}{dirty}".format(
|
||||
base_version=base_version,
|
||||
short_sha=git_revision(pkg_dir).decode("utf-8")[0:6],
|
||||
@@ -33,6 +39,17 @@ def have_git():
|
||||
return False
|
||||
|
||||
|
||||
def is_release(dir_path, base_version):
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
["git", "describe", "--tags", "--exact-match"], cwd=dir_path
|
||||
).decode("utf-8")
|
||||
tag = output.strip()
|
||||
return tag == base_version
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def git_revision(dir_path):
|
||||
"""Get the SHA-1 of the HEAD of a git repository."""
|
||||
return subprocess.check_output(
|
||||
@@ -49,4 +66,4 @@ def is_dirty(dir_path):
|
||||
return True
|
||||
|
||||
|
||||
__version__ = generate_version(base_version="0.35.0")
|
||||
__version__ = generate_version(BASE_VERSION)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import mock
|
||||
import subprocess
|
||||
|
||||
|
||||
import dvc.version
|
||||
from dvc.utils.compat import cast_bytes
|
||||
|
||||
|
||||
def test_is_release():
|
||||
with mock.patch.object(dvc.version.subprocess, "check_output") as m:
|
||||
m.side_effect = subprocess.CalledProcessError(1, "cmd")
|
||||
ret = dvc.version.is_release(None, dvc.version.BASE_VERSION)
|
||||
assert ret is False
|
||||
|
||||
m.side_effect = None
|
||||
m.return_value = cast_bytes(dvc.version.BASE_VERSION)
|
||||
ret = dvc.version.is_release(None, dvc.version.BASE_VERSION)
|
||||
assert ret
|
||||
|
||||
m.return_value = cast_bytes("630d1741c2d5dd89a3176bd15b63121b905d35c9")
|
||||
ret = dvc.version.is_release(None, dvc.version.BASE_VERSION)
|
||||
assert ret is False
|
||||
Reference in New Issue
Block a user