diff --git a/scripts/get_bundle_name.py b/scripts/get_bundle_name.py index 38bc784f1..e77eebf42 100644 --- a/scripts/get_bundle_name.py +++ b/scripts/get_bundle_name.py @@ -17,6 +17,7 @@ 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", @@ -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 diff --git a/scripts/query_version_info.py b/scripts/query_version_info.py index 76ca862ef..1296e2b8e 100644 --- a/scripts/query_version_info.py +++ b/scripts/query_version_info.py @@ -58,12 +58,13 @@ 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( @@ -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