Commit 648bc0c9 authored by Alexander A. Maly's avatar Alexander A. Maly

Fixed branch name recognition

Hash length set to 12 instead of 40
parent 4be4dd70
Pipeline #632 passed with stages
in 4 minutes and 16 seconds
......@@ -17,6 +17,7 @@ else:
def get_version_information(top_level_dir):
assert isinstance(top_level_dir, str) or isinstance(top_level_dir, unicode)
if os.path.exists(top_level_dir + os.path.sep + ".git"):
version_info = ""
try:
version_info = to_str(subprocess.check_output(
"git describe --abbrev=0 --tags --exact-match",
......@@ -24,18 +25,44 @@ def get_version_information(top_level_dir):
stderr=subprocess.PIPE
)).strip()
except subprocess.CalledProcessError:
version_info = to_str(subprocess.check_output(
pass
if version_info:
return version_info
branch_name = ""
try:
branch_name = to_str(subprocess.check_output(
"git rev-parse --abbrev-ref HEAD",
shell=True
)).strip()
version_info += "-" + to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%H",
except subprocess.CalledProcessError:
pass
if branch_name == "HEAD": # detached HEAD?
branch_name = os.environ.get("CI_COMMIT_REF_NAME", "").strip()
if not branch_name:
branch_name = "NONE"
hash_tag = ""
try:
hash_tag = to_str(subprocess.check_output(
"git rev-parse --short=12 --verify HEAD",
shell=True
)).strip()
except subprocess.CalledProcessError:
pass
if not hash_tag:
hash_tag = os.environ.get("CI_COMMIT_SHA", "").strip()
if not hash_tag:
hash_tag = "0000000000000000000000000000000000000000"
return branch_name + "-" + hash_tag
else:
dir_name = os.path.basename(top_level_dir)
match = re.match(r"kumir2-(.+)", dir_name)
version_info = match.group(1)
return version_info
......
......@@ -58,12 +58,13 @@ for path_variant in GIT_PATH_SEARCH:
def get_version_information(top_level_dir):
assert isinstance(top_level_dir, str)
result = {
"taggedRelease": True,
"taggedRelease": False,
"version": None,
"hash": None,
"branch": None,
"date": None
"date": get_date(top_level_dir)
}
if os.path.exists(top_level_dir + os.path.sep + ".git"):
try:
version_info = subprocess.check_output(
......@@ -71,31 +72,52 @@ def get_version_information(top_level_dir):
shell=True,
stderr=subprocess.PIPE
).strip()
result["taggedRelease"] = True
result["version"] = to_str(version_info)
except subprocess.CalledProcessError:
result["taggedRelease"] = False
pass
if result["version"]:
return result
branch_name = ""
try:
branch_name = to_str(subprocess.check_output(
"git rev-parse --abbrev-ref HEAD",
shell=True
).strip())
result["branch"] = branch_name
git_hash = to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%H",
)).strip()
except subprocess.CalledProcessError:
pass
if branch_name == "HEAD": # detached HEAD?
branch_name = os.environ.get("CI_COMMIT_REF_NAME", "").strip()
if not branch_name:
branch_name = "NONE"
hash_tag = ""
try:
hash_tag = to_str(subprocess.check_output(
"git rev-parse --short=12 --verify HEAD",
shell=True
).strip())
result["hash"] = git_hash
result["date"] = get_date(top_level_dir)
)).strip()
except subprocess.CalledProcessError:
pass
if not hash_tag:
hash_tag = os.environ.get("CI_COMMIT_SHA", "").strip()
if not hash_tag:
hash_tag = "0000000000000000000000000000000000000000"
result["taggedRelease"] = False
result["branch"] = branch_name
result["hash"] = hash_tag
else:
dir_name = os.path.basename(top_level_dir)
match = re.match(r"kumir2-(.+)", dir_name)
version_info = match.group(1)
if version_info.startswith("2"):
result["version"] = version_info
else:
result["taggedRelease"] = False
result["date"] = get_date(top_level_dir)
if not result["taggedRelease"] and result["branch"]=="HEAD":
result["branch"] = "master" # fix GitLab naming bug
result["taggedRelease"] = True
return result
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment