Skip to content

Commit

Permalink
Fixed branch name recognition
Browse files Browse the repository at this point in the history
Hash length set to 12 instead of 40
  • Loading branch information
a-a-maly committed Dec 3, 2018
1 parent 4be4dd7 commit 648bc0c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
33 changes: 30 additions & 3 deletions scripts/get_bundle_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,52 @@ def to_str(x):
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",
shell=True,
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


Expand Down
52 changes: 37 additions & 15 deletions scripts/query_version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,66 @@ def _add_path_env(value):
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(
"git describe --abbrev=0 --tags --exact-match",
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


Expand Down

0 comments on commit 648bc0c

Please sign in to comment.