44from gardenlinux .features import CName
55from gardenlinux .flavors import Parser as FlavorsParser
66from gardenlinux .s3 import S3Artifacts
7- from gardenlinux .sources .kernel import get_kernel_urls
87from pathlib import Path
98from yaml .loader import SafeLoader
109import argparse
1413import os
1514import re
1615import requests
16+ import shutil
1717import sys
18+ from git import Repo
1819import textwrap
1920import yaml
2021import urllib .request
21- import difflib
22+
23+
24+ from gardenlinux .sources .kernel import get_kernel_urls
2225
2326
2427GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME = os .environ ['GITHUB_RELEASE_BUCKET_NAME' ]
@@ -82,29 +85,29 @@ def _azure_release_note(published_image_metadata):
8285 return output
8386
8487
85- def generate_release_note_image_ids (manifests ):
88+ def generate_release_note_image_ids (metadata_files ):
8689 out = ""
87- for m in manifests :
90+ for m in metadata_files :
8891 out += generate_release_note_image_id_single (m )
8992 return out
9093
9194
92- def generate_release_note_image_id_single (manifest_path ):
95+ def generate_release_note_image_id_single (metadata_file_path ):
9396 """
9497 Outputs a markdown formatted string for github release notes,
9598 containing the image-ids for the respective cloud regions
9699 """
97100 output = ""
98- with open (manifest_path ) as f :
99- manifest_data = yaml .load (f , Loader = SafeLoader )
100- published_image_metadata = manifest_data ['published_image_metadata' ]
101+ with open (metadata_file_path ) as f :
102+ metadata = yaml .load (f , Loader = SafeLoader )
103+ published_image_metadata = metadata ['published_image_metadata' ]
101104
102- # No publishing metadata found in manifest , assume it was not published
105+ # No publishing metadata found in metadata file , assume it was not published
103106 if published_image_metadata is None :
104107 return ""
105108
106- platform_short_name = manifest_data ['platform' ]
107- arch = manifest_data ['architecture' ]
109+ platform_short_name = metadata ['platform' ]
110+ arch = metadata ['architecture' ]
108111 if platform_short_name in cloud_fullname_dict :
109112 platform_long_name = cloud_fullname_dict [platform_short_name ]
110113 output = output + f"### { platform_long_name } ({ arch } )\n "
@@ -126,18 +129,39 @@ def generate_release_note_image_id_single(manifest_path):
126129 return output
127130
128131
129- def download_all_singles (version , commitish ):
130- with open ("./flavors.yaml" , "r" ) as f :
131- flavors_data = f .read ()
132+ def download_metadata_file (s3_artifacts , cname , artifacts_dir ):
133+ """
134+ Download metadata file (s3_metadata.yaml)
135+ """
136+ release_object = list (
137+ s3_artifacts ._bucket .objects .filter (Prefix = f"meta/singles/{ cname } " )
138+ )[0 ]
139+ s3_artifacts ._bucket .download_file (
140+ release_object .key , artifacts_dir .joinpath (f"{ cname } .s3_metadata.yaml" )
141+ )
142+
143+
144+ def download_all_metadata_files (version , commitish ):
145+ repo = Repo ("." )
146+ commit = repo .commit (commitish )
147+ flavors_data = commit .tree ["flavors.yaml" ].data_stream .read ().decode ('utf-8' )
132148 flavors = FlavorsParser (flavors_data ).filter (only_publish = True )
133149
134150 local_dest_path = Path ("s3_downloads" )
135- local_dest_path .mkdir (mode = 0o755 , exist_ok = True )
151+ if local_dest_path .exists ():
152+ shutil .rmtree (local_dest_path )
153+ local_dest_path .mkdir (mode = 0o755 , exist_ok = False )
154+
155+ s3_artifacts = S3Artifacts (GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME )
136156
137157 for flavor in flavors :
138- cname = CName (cname = flavor [1 ], arch = flavor [0 ], version = version , commit_id = commitish )
158+ cname = CName (flavor [1 ], flavor [0 ], "{0}-{1}" . format ( version , commitish ) )
139159 print (f'YTDBG // { flavor = } | { version = } | { commitish = } | { cname .cname = } ' )
140- S3Artifacts (GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME ).download_to_directory (cname .cname , local_dest_path )
160+ try :
161+ download_metadata_file (s3_artifacts , cname .cname , local_dest_path )
162+ except IndexError :
163+ print (f"WARNING: No artifacts found for flavor { cname .cname } , skipping..." )
164+ continue
141165
142166 return [str (artifact ) for artifact in local_dest_path .iterdir ()]
143167
@@ -149,14 +173,14 @@ def get_image_object_url(bucket, object, expiration=0):
149173 return url
150174
151175
152- def generate_image_download_section (manifests , version , commitish ):
176+ def generate_image_download_section (metadata_files , version , commitish ):
153177 output = ""
154- for manifest_path in manifests :
155- with open (manifest_path ) as f :
156- manifest_data = yaml .load (f , Loader = SafeLoader )
157- arch = manifest_data ['architecture' ].upper ()
158- platform = manifest_data ['platform' ]
159- paths = manifest_data ['paths' ]
178+ for metadata_file_path in metadata_files :
179+ with open (metadata_file_path ) as f :
180+ metadata = yaml .load (f , Loader = SafeLoader )
181+ arch = metadata ['architecture' ].upper ()
182+ platform = metadata ['platform' ]
183+ paths = metadata ['paths' ]
160184
161185 for path in paths :
162186 if platform == 'ali' and '.qcow2' == path ['suffix' ]:
@@ -311,16 +335,16 @@ def create_github_release_notes(gardenlinux_version, commitish, dry_run=False):
311335
312336 output += release_notes_compare_package_versions_section (gardenlinux_version , package_list )
313337
314- manifests = download_all_singles (gardenlinux_version , commitish_short )
338+ metadata_files = download_all_metadata_files (gardenlinux_version , commitish_short )
315339
316- output += generate_release_note_image_ids (manifests )
340+ output += generate_release_note_image_ids (metadata_files )
317341
318342 output += "\n "
319343 output += "## Kernel Package direct download links\n "
320344 output += get_kernel_urls (gardenlinux_version )
321345 output += "\n "
322346
323- output += generate_image_download_section (manifests , gardenlinux_version , commitish_short )
347+ output += generate_image_download_section (metadata_files , gardenlinux_version , commitish_short )
324348
325349 output += "\n "
326350 output += "## Kernel Module Build Container (kmodbuild) "
0 commit comments