77from packaging .version import parse , Version
88
99from matrix import CONFIG
10- from util import format_image_name , maybe , smart_script_split , parse_text_bool
10+ from util import format_image_name , maybe , smart_script_split , parse_text_bool , get_branch_tag_suffix
1111
1212# Targets that are handled via docker run + host CCACHE packaging stages.
1313CCACHE_TARGET_MAP = {
@@ -166,18 +166,28 @@ def docker_build(
166166 publish : bool ,
167167 pass_build_args : bool ,
168168 mark_format : Optional [str ],
169+ firmware_url : str ,
170+ firmware_sig_url : str ,
171+ tag_suffix : Optional [str ] = None ,
169172) -> list [str ]:
170173 lines = []
171174
172175 version = dockerify_version (version )
173176 actual_target = CCACHE_TARGET_MAP .get (target , target )
174177
178+ # tag_version is the version string used for OCI tags; version is the
179+ # actual kernel version passed as a build arg and recorded in annotations.
180+ # They differ when building from a non-main branch to avoid tag collisions.
181+ # Tags in the list are already branch-suffixed (applied during matrix generation).
182+ tag_version = "%s-%s" % (version , tag_suffix ) if tag_suffix else version
183+ oci_tags = list (tags )
184+
175185 root = format_image_name (
176186 image_name_format = CONFIG ["imageNameFormat" ],
177187 flavor = flavor ,
178188 version_info = version_info ,
179189 name = name ,
180- tag = version ,
190+ tag = tag_version ,
181191 )
182192
183193 image_build_command = [
@@ -192,7 +202,7 @@ def docker_build(
192202 "--target" ,
193203 quoted (actual_target ),
194204 "--iidfile" ,
195- quoted ("image-id-%s-%s-%s" % (version , flavor , actual_target )),
205+ quoted ("image-id-%s-%s-%s" % (tag_version , flavor , actual_target )),
196206 ]
197207
198208 for build_platform in docker_platforms (architectures ):
@@ -229,8 +239,8 @@ def docker_build(
229239 all_tags = [root ]
230240 additional_tags = []
231241
232- for tag in tags :
233- if tag == version :
242+ for tag in oci_tags :
243+ if tag == tag_version :
234244 continue
235245 additional_tags .append (
236246 format_image_name (
@@ -261,7 +271,7 @@ def docker_build(
261271 "sign" ,
262272 "--yes" ,
263273 quoted (
264- '%s@$(cat "image-id-%s-%s-%s")' % (tag , version , flavor , actual_target )
274+ '%s@$(cat "image-id-%s-%s-%s")' % (tag , tag_version , flavor , actual_target )
265275 ),
266276 ]
267277 lines += ["" ]
@@ -288,6 +298,7 @@ def generate_builds(
288298 kernel_architectures : list [str ],
289299 firmware_url : str ,
290300 firmware_sig_url : str ,
301+ tag_suffix : Optional [str ] = None ,
291302) -> list [str ]:
292303 lines = []
293304 kernel_version_info = parse (kernel_version )
@@ -336,6 +347,9 @@ def generate_builds(
336347 mark_format = image_format ,
337348 flavor = kernel_flavor ,
338349 architectures = kernel_architectures ,
350+ firmware_url = firmware_url ,
351+ firmware_sig_url = firmware_sig_url ,
352+ tag_suffix = tag_suffix ,
339353 )
340354 return lines
341355
@@ -356,11 +370,13 @@ def generate_build_from_env() -> list[str]:
356370 kernel_architectures = root_kernel_architectures ,
357371 firmware_url = root_firmware_url ,
358372 firmware_sig_url = root_firmware_sig_url ,
373+ tag_suffix = get_branch_tag_suffix (),
359374 )
360375
361376
362377def generate_builds_from_matrix (matrix ) -> list [str ]:
363378 lines = []
379+ tag_suffix = get_branch_tag_suffix ()
364380 builds = matrix ["builds" ] # type: list[dict[str, any]]
365381 for build in builds :
366382 build_version = build ["version" ]
@@ -378,6 +394,7 @@ def generate_builds_from_matrix(matrix) -> list[str]:
378394 kernel_architectures = build_architectures ,
379395 firmware_url = firmware_url ,
380396 firmware_sig_url = firmware_sig_url ,
397+ tag_suffix = tag_suffix ,
381398 )
382399 return lines
383400
0 commit comments