|
|
@@ -10,10 +10,25 @@ import json
|
|
|
import os
|
|
|
import re
|
|
|
import subprocess
|
|
|
-from typing import List
|
|
|
+from typing import List, Tuple
|
|
|
|
|
|
IDF_GIT_DESCRIBE_PATTERN = re.compile(r'^v(\d)\.(\d)')
|
|
|
-RETRY_COUNT = 3
|
|
|
+
|
|
|
+
|
|
|
+def _idf_version_from_cmake() -> Tuple[int, int]:
|
|
|
+ version_path = os.path.join(os.environ['IDF_PATH'], 'tools/cmake/version.cmake')
|
|
|
+ regex = re.compile(r'^\s*set\s*\(\s*IDF_VERSION_([A-Z]{5})\s+(\d+)')
|
|
|
+ try:
|
|
|
+ ver = {}
|
|
|
+ with open(version_path) as f:
|
|
|
+ for line in f:
|
|
|
+ m = regex.match(line)
|
|
|
+ if m:
|
|
|
+ ver[m.group(1)] = m.group(2)
|
|
|
+ return (int(ver['MAJOR']), int(ver['MINOR']))
|
|
|
+ except (KeyError, OSError):
|
|
|
+ print('WARNING: Cannot find ESP-IDF version in version.cmake')
|
|
|
+ return (0, 0)
|
|
|
|
|
|
|
|
|
def get_customized_project_revision(proj_name: str) -> str:
|
|
|
@@ -47,20 +62,12 @@ def target_branch_candidates(proj_name: str) -> List:
|
|
|
candidates.insert(0, customized_candidate)
|
|
|
|
|
|
# branch name read from IDF
|
|
|
- try:
|
|
|
- git_describe = subprocess.check_output(['git', 'describe', 'HEAD'])
|
|
|
- match = IDF_GIT_DESCRIBE_PATTERN.search(git_describe.decode())
|
|
|
- if match:
|
|
|
- major_revision = match.group(1)
|
|
|
- minor_revision = match.group(2)
|
|
|
- # release branch
|
|
|
- candidates.append('release/v{}.{}'.format(major_revision, minor_revision))
|
|
|
- # branch to match all major branches, like v3.x or v3
|
|
|
- candidates.append('release/v{}.x'.format(major_revision))
|
|
|
- candidates.append('release/v{}'.format(major_revision))
|
|
|
- except subprocess.CalledProcessError:
|
|
|
- # this should not happen as IDF should have describe message
|
|
|
- pass
|
|
|
+ major_revision, minor_revision = _idf_version_from_cmake()
|
|
|
+ # release branch
|
|
|
+ candidates.append('release/v{}.{}'.format(major_revision, minor_revision))
|
|
|
+ # branch to match all major branches, like v3.x or v3
|
|
|
+ candidates.append('release/v{}.x'.format(major_revision))
|
|
|
+ candidates.append('release/v{}'.format(major_revision))
|
|
|
|
|
|
return [c for c in candidates if c] # filter out null value
|
|
|
|
|
|
@@ -103,16 +110,10 @@ if __name__ == '__main__':
|
|
|
continue
|
|
|
|
|
|
if ref_to_use:
|
|
|
- for _ in range(RETRY_COUNT):
|
|
|
- # Add retry for projects with git-lfs
|
|
|
- try:
|
|
|
- subprocess.check_call(['git', 'checkout', '-f', ref_to_use], stdout=subprocess.PIPE) # not print the stdout
|
|
|
- print('CI using ref {} for project {}'.format(ref_to_use, args.project))
|
|
|
- break
|
|
|
- except subprocess.CalledProcessError:
|
|
|
- pass
|
|
|
- else:
|
|
|
- print('Failed to use ref {} for project {}'.format(ref_to_use, args.project))
|
|
|
- exit(1)
|
|
|
+ try:
|
|
|
+ subprocess.check_call(['git', 'checkout', '-f', ref_to_use], stdout=subprocess.PIPE) # not print the stdout
|
|
|
+ print('CI using ref {} for project {}'.format(ref_to_use, args.project))
|
|
|
+ except subprocess.CalledProcessError:
|
|
|
+ pass
|
|
|
else:
|
|
|
print('using default branch')
|