From 0f8d1cbf1b3b6e6e81fe660102b3c151c405f951 Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Tue, 29 Sep 2020 11:20:05 +0800 Subject: [PATCH 1/3] CI: get git describe from annotated tags: we should only parse IDF version from annotated tags --- tools/ci/check_idf_version.sh | 2 +- tools/ci/checkout_project_ref.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci/check_idf_version.sh b/tools/ci/check_idf_version.sh index 9a9ac4eae0..2d66dacda1 100755 --- a/tools/ci/check_idf_version.sh +++ b/tools/ci/check_idf_version.sh @@ -33,7 +33,7 @@ cmake_ver_minor=$(get_ver_from_cmake IDF_VERSION_MINOR) cmake_ver_patch=$(get_ver_from_cmake IDF_VERSION_PATCH) version_from_cmake="${cmake_ver_major}.${cmake_ver_minor}.${cmake_ver_patch}" -git_desc=$(git describe --tags) +git_desc=$(git describe) git_desc_regex="^v([0-9]+)\.([0-9]+)(\.([0-9]+))?.*$" if [[ ! ${git_desc} =~ ${git_desc_regex} ]]; then echo "Could not determine the version from 'git describe' output: ${git_desc}" diff --git a/tools/ci/checkout_project_ref.py b/tools/ci/checkout_project_ref.py index 29f4b59571..fae39ac0de 100755 --- a/tools/ci/checkout_project_ref.py +++ b/tools/ci/checkout_project_ref.py @@ -35,7 +35,7 @@ def target_branch_candidates(proj_name): pass # branch name read from IDF try: - git_describe = subprocess.check_output(["git", "describe", "--tags", "HEAD"]) + git_describe = subprocess.check_output(["git", "describe", "HEAD"]) match = IDF_GIT_DESCRIBE_PATTERN.search(git_describe.decode()) if match: major_revision = match.group(1) From 261363855c61a0845e16c03d114d6ccfa6c94816 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 7 Oct 2020 09:36:40 +1100 Subject: [PATCH 2/3] build system: Also get IDF version from annotated tags only Builds on previous commit. Note: Getting the project version still pases --tags so still works with plain tags, to keep compatibility for existing projects --- docs/idf_extensions/gen_version_specific_includes.py | 2 +- make/project.mk | 2 +- tools/idf_tools.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/idf_extensions/gen_version_specific_includes.py b/docs/idf_extensions/gen_version_specific_includes.py index ba290a01a6..0707d8344e 100755 --- a/docs/idf_extensions/gen_version_specific_includes.py +++ b/docs/idf_extensions/gen_version_specific_includes.py @@ -196,7 +196,7 @@ def get_version(): """ # Use git to look for a tag try: - tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"]).strip().decode('utf-8') + tag = subprocess.check_output(["git", "describe", "--exact-match"]).strip().decode('utf-8') is_stable = re.match(r"v[0-9\.]+$", tag) is not None return (tag, "tag", is_stable) except subprocess.CalledProcessError: diff --git a/make/project.mk b/make/project.mk index bd40e64aa6..19e848e688 100644 --- a/make/project.mk +++ b/make/project.mk @@ -338,7 +338,7 @@ endif # If we have `version.txt` then prefer that for extracting IDF version ifeq ("$(wildcard ${IDF_PATH}/version.txt)","") -IDF_VER_T := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty) +IDF_VER_T := $(shell cd ${IDF_PATH} && git describe --always --dirty) else IDF_VER_T := $(shell cat ${IDF_PATH}/version.txt) endif diff --git a/tools/idf_tools.py b/tools/idf_tools.py index 3525d29be4..e430472b8b 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -857,7 +857,7 @@ def get_python_env_path(): idf_version_str = version_file.read() else: try: - idf_version_str = subprocess.check_output(['git', 'describe', '--tags'], + idf_version_str = subprocess.check_output(['git', 'describe'], cwd=global_idf_path, env=os.environ).decode() except subprocess.CalledProcessError as e: warn('Git describe was unsuccessul: {}'.format(e)) From 1612f84ab3e898274f2b805c374142b5c144e7be Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 7 Oct 2020 09:54:27 +1100 Subject: [PATCH 3/3] ci: Check version tags are always annotated Closes https://github.com/espressif/esp-idf/issues/3114 --- tools/ci/config/pre_check.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/ci/config/pre_check.yml b/tools/ci/config/pre_check.yml index 06b13bf058..17ac8241d1 100644 --- a/tools/ci/config/pre_check.yml +++ b/tools/ci/config/pre_check.yml @@ -215,3 +215,15 @@ check_codeowners: extends: .check_job_template script: - tools/codeowners.py ci-check + +# For release tag pipelines only, make sure the tag was created with 'git tag -a' so it will update +# the version returned by 'git describe' +check_version_tag: + extends: .check_job_template + only: + refs: + - /^v\d+\.\d+(\.\d+)?($|-)/ + variables: + - $BOT_TRIGGER_WITH_LABEL == null + script: + - (git cat-file -t $CI_COMMIT_REF_NAME | grep tag) || echo "ESP-IDF versions must be annotated tags." && exit 1