summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorAlexis Lothoré <alexis.lothore@bootlin.com>2023-08-18 16:17:11 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-08-21 11:34:12 +0100
commite9cff55e73cce55456997ad277e8742ce9536601 (patch)
treeddb1d02556a11dd661384d8c77251bee78972aa6 /meta
parentf30867795c6eddad62c4a97cc57ca4e766698890 (diff)
downloadpoky-e9cff55e73cce55456997ad277e8742ce9536601.tar.gz
oeqa/utils/gitarchive: fix tag computation when creating archive
Sporadic errors have been observed in autobuilder when trying to store new tests results: error: failed to push some refs to 'push.yoctoproject.org:yocto-testresults' hint: Updates were rejected because the tag already exists in the remote. The new tag name is generated by gitarchive based on known tags from the repository (learnt with git tag). In autobuilder case, this repository is a shallow clone, so git tag only returns most recent tags, which mean we could miss some older tags which exist in remote but not locally. In this case, gitarchive will likely create a tag which already exists in remote, and so will fail to push Fix this tag duplication by using git ls-remote to learn about existing tags instead of git tag. To do so, create a helper ("get_tags") which manages both nominal case (target directory is a git repository with a proper remote) and fallback case (target directory is not from a clone, no remote has been configured) Fixes [YOCTO #15140] (From OE-Core rev: 9cbbe9689866158825a7ae774b7965b41ff5c461) Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/utils/gitarchive.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/meta/lib/oeqa/utils/gitarchive.py b/meta/lib/oeqa/utils/gitarchive.py
index 6e8040eb5c..1a28a09efe 100644
--- a/meta/lib/oeqa/utils/gitarchive.py
+++ b/meta/lib/oeqa/utils/gitarchive.py
@@ -100,9 +100,36 @@ def git_commit_data(repo, data_dir, branch, message, exclude, notes, log):
100 if os.path.exists(tmp_index): 100 if os.path.exists(tmp_index):
101 os.unlink(tmp_index) 101 os.unlink(tmp_index)
102 102
103def get_tags(repo, pattern=None, url=None):
104 """ Fetch remote tags from current repository
105
106 A pattern can be provided to filter returned tags list
107 An URL can be provided if local repository has no valid remote configured
108 """
109
110 base_cmd = ['ls-remote', '--refs', '--tags', '-q']
111 cmd = base_cmd.copy()
112
113 # First try to fetch tags from repository configured remote
114 cmd.append('origin')
115 if pattern:
116 cmd.append(pattern)
117 try:
118 tags_refs = repo.run_cmd(cmd)
119 except GitError as e:
120 # If it fails, retry with repository url if one is provided
121 if not url:
122 raise(e)
123 cmd = base_cmd.copy()
124 cmd.append(url)
125 if pattern:
126 cmd.append(pattern)
127 tags_refs = repo.run_cmd(cmd)
128
129 return ["".join(d.split()[1].split('/', 2)[2:]) for d in tags_refs.splitlines()]
103 130
104def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, 131def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern,
105 keywords): 132 url, keywords):
106 """Generate tag name and message, with support for running id number""" 133 """Generate tag name and message, with support for running id number"""
107 keyws = keywords.copy() 134 keyws = keywords.copy()
108 # Tag number is handled specially: if not defined, we autoincrement it 135 # Tag number is handled specially: if not defined, we autoincrement it
@@ -116,7 +143,7 @@ def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern,
116 tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})') 143 tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})')
117 144
118 keyws['tag_number'] = 0 145 keyws['tag_number'] = 0
119 for existing_tag in repo.run_cmd('tag').splitlines(): 146 for existing_tag in get_tags(repo, url=url):
120 match = re.match(tag_re, existing_tag) 147 match = re.match(tag_re, existing_tag)
121 148
122 if match and int(match.group('tag_number')) >= keyws['tag_number']: 149 if match and int(match.group('tag_number')) >= keyws['tag_number']:
@@ -143,7 +170,8 @@ def gitarchive(data_dir, git_dir, no_create, bare, commit_msg_subject, commit_ms
143 if not no_tag and tagname: 170 if not no_tag and tagname:
144 tag_name, tag_msg = expand_tag_strings(data_repo, tagname, 171 tag_name, tag_msg = expand_tag_strings(data_repo, tagname,
145 tag_msg_subject, 172 tag_msg_subject,
146 tag_msg_body, keywords) 173 tag_msg_body,
174 push, keywords)
147 175
148 # Commit data 176 # Commit data
149 commit = git_commit_data(data_repo, data_dir, branch_name, 177 commit = git_commit_data(data_repo, data_dir, branch_name,
@@ -181,7 +209,7 @@ def get_test_runs(log, repo, tag_name, **kwargs):
181 209
182 # Get a list of all matching tags 210 # Get a list of all matching tags
183 tag_pattern = tag_name.format(**str_fields) 211 tag_pattern = tag_name.format(**str_fields)
184 tags = repo.run_cmd(['tag', '-l', tag_pattern]).splitlines() 212 tags = get_tags(repo, pattern=tag_pattern)
185 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) 213 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern)
186 214
187 # Parse undefined fields from tag names 215 # Parse undefined fields from tag names