summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Lothoré <alexis.lothore@bootlin.com>2023-08-18 16:17:11 +0200
committerSteve Sakoman <steve@sakoman.com>2023-11-12 11:30:08 -1000
commit03ccc1284aee335253607c5d71c6cbf73c28a2cc (patch)
tree1ba7a0bde8e81aad4f8f7bcee8bd12251fac15b8
parentf0265a9051412eaf41290b5d86786c870112e9fc (diff)
downloadpoky-03ccc1284aee335253607c5d71c6cbf73c28a2cc.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: b0d96ea432196800fedb45e6d1da44a3523fad63) 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> (cherry picked from commit 9cbbe9689866158825a7ae774b7965b41ff5c461) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-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 cd60a605d4..2bb1bde774 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