1919import yaml
2020
2121from .bucket import Bucket
22+ from ..features import CName
2223
2324
2425class S3Artifacts (object ):
@@ -116,36 +117,20 @@ def upload_from_directory(
116117
117118 artifacts_dir = Path (artifacts_dir )
118119
120+ cname_object = CName (cname )
121+
119122 if not artifacts_dir .is_dir ():
120123 raise RuntimeError (f"Artifacts directory given is invalid: { artifacts_dir } " )
121124
122125 release_file = artifacts_dir .joinpath (f"{ cname } .release" )
123126 release_timestamp = stat (release_file ).st_ctime
124127
125- release_config = ConfigParser (allow_unnamed_section = True )
126- release_config .read (release_file )
127-
128- # Get architecture from the GARDENLINUX_CNAME (second to last element when split by -)
129- release_cname = release_config .get (UNNAMED_SECTION , "GARDENLINUX_CNAME" )
130- cname_parts = release_cname .split ("-" )
131- if len (cname_parts ) < 2 :
132- raise RuntimeError (f"Invalid GARDENLINUX_CNAME format in release file: { release_cname } " )
133- arch = cname_parts [- 2 ] # Second to last element is the architecture
128+ cname_object .load_from_release_file (release_file )
134129
135- commit_id = release_config .get (UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID" )
136- expected_cname = f"{ release_cname } -{ commit_id } "
137-
138- # Verify the provided cname matches the release file
139- if cname != expected_cname :
140- raise RuntimeError (
141- f"Release file cname does not match provided cname: { expected_cname } != { cname } "
142- )
143-
144- commit_hash = release_config .get (UNNAMED_SECTION , "GARDENLINUX_COMMIT_ID_LONG" )
145-
146- feature_set = release_config .get (UNNAMED_SECTION , "GARDENLINUX_FEATURES" )
147- feature_list = feature_set .split ("," )
130+ if cname_object .arch is None :
131+ raise RuntimeError ("Architecture could not be determined from cname" )
148132
133+ feature_list = cname_object .feature_set
149134 requirements_file = artifacts_dir .joinpath (f"{ cname } .requirements" )
150135 require_uefi = None
151136 secureboot = None
@@ -168,33 +153,25 @@ def upload_from_directory(
168153 if secureboot is None :
169154 secureboot = "_trustedboot" in feature_list
170155
171- version = release_config .get (UNNAMED_SECTION , "GARDENLINUX_VERSION" )
172- platform = release_config .get (UNNAMED_SECTION , "GARDENLINUX_PLATFORM" )
173-
174156 metadata = {
175- "platform" : platform ,
176- "architecture" : arch ,
157+ "platform" : cname_object . feature_set_platform ,
158+ "architecture" : cname_object . arch ,
177159 "base_image" : None ,
178- "build_committish" : commit_hash ,
160+ "build_committish" : cname_object . commit_hash ,
179161 "build_timestamp" : datetime .fromtimestamp (release_timestamp ).isoformat (),
180- "gardenlinux_epoch" : int (version .split ("." , 1 )[0 ]),
162+ "gardenlinux_epoch" : int (cname_object . version .split ("." , 1 )[0 ]),
181163 "logs" : None ,
182- "modifiers" : feature_list ,
164+ "modifiers" : cname_object . feature_set ,
183165 "require_uefi" : require_uefi ,
184166 "secureboot" : secureboot ,
185167 "published_image_metadata" : None ,
186168 "s3_bucket" : self ._bucket .name ,
187169 "s3_key" : f"meta/singles/{ cname } " ,
188170 "test_result" : None ,
189- "version" : version ,
171+ "version" : cname_object . version ,
190172 "paths" : [],
191173 }
192174
193- if release_config .has_option (UNNAMED_SECTION , "GARDENLINUX_PLATFORM_VARIANT" ):
194- metadata ["platform_variant" ] = release_config .get (
195- UNNAMED_SECTION , "GARDENLINUX_PLATFORM_VARIANT"
196- )
197-
198175 re_object = re .compile ("[^a-zA-Z0-9\\ s+\\ -=.\\ _:/@]" )
199176
200177 for artifact in artifacts_dir .iterdir ():
@@ -224,16 +201,14 @@ def upload_from_directory(
224201 }
225202
226203 s3_tags = {
227- "architecture" : re_object .sub ("+" , arch ),
228- "platform" : re_object .sub ("+" , platform ),
229- "version" : re_object .sub ("+" , version ),
230- "committish" : commit_hash ,
204+ "architecture" : re_object .sub ("+" , cname_object . arch ),
205+ "platform" : re_object .sub ("+" , cname_object . platform ),
206+ "version" : re_object .sub ("+" , cname_object . version ),
207+ "committish" : cname_object . commit_hash ,
231208 "md5sum" : md5sum ,
232209 "sha256sum" : sha256sum ,
233210 }
234211
235- metadata ["paths" ].append (artifact_metadata )
236-
237212 if not dry_run :
238213 if delete_before_push :
239214 self ._bucket .delete_objects (Delete = {"Objects" : [{"Key" : s3_key }]})
@@ -244,6 +219,8 @@ def upload_from_directory(
244219 ExtraArgs = {"Tagging" : urlencode (s3_tags )},
245220 )
246221
222+ metadata ["paths" ].append (artifact_metadata )
223+
247224 if dry_run :
248225 print (yaml .dump (metadata , sort_keys = False ))
249226 else :
0 commit comments