@@ -297,6 +297,49 @@ def add_tag(repo: str, existing_tag: Tag, new_tag: Tag, dry_run: bool):
297297 )
298298
299299
300+ def _log_config (config : "Config" ) -> None :
301+ if config .dry_run :
302+ logging .info ("dry run enabled. build and publish actions will be skipped." )
303+ if config .republish :
304+ logging .info ("republish enabled. images will be republished." )
305+ if config .no_cache :
306+ logging .info ("no cache enabled. images will be built without cache." )
307+ if config .only_postgres_version :
308+ logging .info (f"only postgres { config .only_postgres_version } enabled. other images will be skipped." )
309+ if config .only_spock_version :
310+ logging .info (f"only spock { config .only_spock_version } enabled. other images will be skipped." )
311+ if config .only_arch :
312+ logging .info (f"only arch { config .only_arch } enabled. other images will be skipped." )
313+
314+
315+ def _should_skip_image (image : "PgEdgeImage" , config : "Config" ) -> bool :
316+ if config .only_postgres_version and image .postgres_version != config .only_postgres_version :
317+ return True
318+ if config .only_spock_version and image .spock_version != config .only_spock_version :
319+ return True
320+ return False
321+
322+
323+ def _process_extra_tags (config : "Config" , image : "PgEdgeImage" , published : set ) -> None :
324+ for tag in image .extra_tags :
325+ tag_published = published_digests (config .repo , tag )
326+ if len (tag_published ) == 0 or not tag_published .issubset (published ) or config .republish :
327+ add_tag (repo = config .repo , existing_tag = image .build_tag , new_tag = tag , dry_run = config .dry_run )
328+ else :
329+ logging .info (f"{ tag } is already up-to-date" )
330+
331+
332+ def _process_image (config : "Config" , image : "PgEdgeImage" ) -> None :
333+ published = published_digests (config .repo , image .build_tag )
334+ if len (published ) == 0 or config .republish :
335+ build (repo = config .repo , image = image , dry_run = config .dry_run , no_cache = config .no_cache , only_arch = config .only_arch )
336+ digest = index_digest (config .repo , image .build_tag )
337+ sign (repo = config .repo , digest = digest , dry_run = config .dry_run )
338+ else :
339+ logging .info (f"{ image .build_tag } is already published" )
340+ _process_extra_tags (config , image , published )
341+
342+
300343def main ():
301344 logging .basicConfig (
302345 level = logging .INFO ,
@@ -305,84 +348,18 @@ def main():
305348
306349 config = Config .from_env ()
307350
308- # If list_latest_tags is enabled, output tags and exit
309351 if config .list_latest_tags :
310- tags = get_latest_tags ()
311- # Output as comma-separated list
312- print ("," .join (tags ))
352+ print ("," .join (get_latest_tags ()))
313353 return
314354
315- if config .dry_run :
316- logging .info ("dry run enabled. build and publish actions will be skipped." )
317-
318- if config .republish :
319- logging .info ("republish enabled. images will be republished." )
320-
321- if config .no_cache :
322- logging .info ("no cache enabled. images will be built without cache." )
323-
324- if config .only_postgres_version :
325- logging .info (
326- f"only postgres { config .only_postgres_version } enabled. other images will be skipped."
327- )
328-
329- if config .only_spock_version :
330- logging .info (
331- f"only spock { config .only_spock_version } enabled. other images will be skipped."
332- )
333-
334- if config .only_arch :
335- logging .info (
336- f"only arch { config .only_arch } enabled. other images will be skipped."
337- )
338-
355+ _log_config (config )
339356 validate_images (all_images )
340357
341358 for image in all_images :
342- if (
343- config .only_postgres_version
344- and image .postgres_version != config .only_postgres_version
345- ) or (
346- config .only_spock_version
347- and image .spock_version != config .only_spock_version
348- ):
359+ if _should_skip_image (image , config ):
349360 logging .info (f"skipping image { image .build_tag } " )
350361 continue
351-
352- published = published_digests (config .repo , image .build_tag )
353- if len (published ) == 0 or config .republish :
354- build (
355- repo = config .repo ,
356- image = image ,
357- dry_run = config .dry_run ,
358- no_cache = config .no_cache ,
359- only_arch = config .only_arch ,
360- )
361-
362- id = index_digest (config .repo , image .build_tag )
363- sign (
364- repo = config .repo ,
365- digest = id ,
366- dry_run = config .dry_run ,
367- )
368- else :
369- logging .info (f"{ image .build_tag } is already published" )
370-
371- for tag in image .extra_tags :
372- tag_published = published_digests (config .repo , tag )
373- if (
374- len (tag_published ) == 0
375- or not tag_published .issubset (published )
376- or config .republish
377- ):
378- add_tag (
379- repo = config .repo ,
380- existing_tag = image .build_tag ,
381- new_tag = tag ,
382- dry_run = config .dry_run ,
383- )
384- else :
385- logging .info (f"{ tag } is already up-to-date" )
362+ _process_image (config , image )
386363
387364
388365def get_latest_tags () -> list [str ]:
0 commit comments