@@ -148,108 +148,75 @@ def charm():
148
148
directory = pathlib .Path (args .directory )
149
149
150
150
# Upload charm file(s) & store revision
151
- charm_revisions : dict [ craft . Architecture , list [int ]] = {}
151
+ charm_revisions : list [int ] = []
152
152
for charm_file in directory .glob ("*.charm" ):
153
- # Examples of `charm_file.name`:
154
- # - "mysql-router-k8s_ubuntu-22.04-amd64.charm"
155
- # - "mysql-router-k8s_ubuntu-22.04-amd64-arm64.charm"
156
- architectures = (
157
- charm_file .name .split ("_" )[- 1 ].removesuffix (".charm" ).split ("-" )[2 :]
158
- )
159
- assert (
160
- len (architectures ) == 1
161
- ), f"Multiple architectures ({ architectures } ) in one (charmcraft.yaml) base not supported. Use one base per architecture"
162
- architecture = craft .Architecture (architectures [0 ])
163
- logging .info (f"Uploading { charm_file = } { architecture = } " )
153
+ logging .info (f"Uploading { charm_file = } " )
164
154
output = run (["charmcraft" , "upload" , "--format" , "json" , charm_file ])
165
155
revision : int = json .loads (output )["revision" ]
166
156
logging .info (f"Uploaded charm { revision = } " )
167
- charm_revisions .setdefault ( architecture , []). append (revision )
157
+ charm_revisions .append (revision )
168
158
assert len (charm_revisions ) > 0 , "No charm packages found"
169
159
170
160
metadata_file = yaml .safe_load ((directory / "metadata.yaml" ).read_text ())
171
161
charm_name = metadata_file ["name" ]
172
162
173
163
# (Only for Kubernetes charms) upload OCI image(s) & store revision
174
- oci_resources : dict [ craft . Architecture , list [OCIResource ]] = {}
164
+ oci_resources : list [OCIResource ] = []
175
165
resources = metadata_file .get ("resources" , {})
176
166
for resource_name , resource in resources .items ():
177
167
if resource ["type" ] != "oci-image" :
178
168
continue
179
- for architecture in charm_revisions .keys ():
180
- # Format: ST111 - Multi-architecture `upstream-source` in charm OCI resources
181
- # https://docs.google.com/document/d/19pzpza7zj7qswDRSHBlpqdBrA7Ndcnyh6_75cCxMKSo/edit
182
- upstream_source = resource .get ("upstream-source" )
183
- if upstream_source is not None and "upstream-sources" in resource :
184
- raise ValueError (
185
- "`upstream-sources` and `upstream-source` cannot be used simultaneously. Use only `upstream-sources`"
186
- )
187
- elif upstream_source :
188
- # Default to X64
189
- upstream_sources = {craft .Architecture .X64 .value : upstream_source }
190
- else :
191
- upstream_sources = resource ["upstream-sources" ]
192
- image_name = upstream_sources [architecture .value ]
193
- logging .info (f"Downloading OCI image ({ architecture = } ): { image_name } " )
194
- run (["docker" , "pull" , image_name ])
195
- image_id = run (
196
- ["docker" , "image" , "inspect" , image_name , "--format" , "'{{.Id}}'" ]
197
- )
198
- image_id = image_id .rstrip ("\n " ).strip ("'" ).removeprefix ("sha256:" )
199
- assert "\n " not in image_id , f"Multiple local images found for { image_name } "
200
- logging .info (f"Uploading charm resource: { resource_name } " )
201
- output = run (
202
- [
203
- "charmcraft" ,
204
- "upload-resource" ,
205
- "--format" ,
206
- "json" ,
207
- charm_name ,
208
- resource_name ,
209
- "--image" ,
210
- image_id ,
211
- ]
212
- )
213
- revision : int = json .loads (output )["revision" ]
214
- logging .info (f"Uploaded charm resource { revision = } " )
215
- oci_resources .setdefault (architecture , []).append (
216
- OCIResource (resource_name , revision )
217
- )
218
-
219
- # Release charm file(s)
220
- for architecture , revisions in charm_revisions .items ():
221
- for charm_revision in revisions :
222
- logging .info (f"Releasing { charm_revision = } { architecture = } " )
223
- command = [
169
+ image_name = resource ["upstream-source" ]
170
+ logging .info (f"Downloading OCI image: { image_name } " )
171
+ run (["docker" , "pull" , image_name ])
172
+ image_id = run (
173
+ ["docker" , "image" , "inspect" , image_name , "--format" , "'{{.Id}}'" ]
174
+ )
175
+ image_id = image_id .rstrip ("\n " ).strip ("'" ).removeprefix ("sha256:" )
176
+ assert "\n " not in image_id , f"Multiple local images found for { image_name } "
177
+ logging .info (f"Uploading charm resource: { resource_name } " )
178
+ output = run (
179
+ [
224
180
"charmcraft" ,
225
- "release" ,
181
+ "upload-resource" ,
182
+ "--format" ,
183
+ "json" ,
226
184
charm_name ,
227
- "--revision" ,
228
- str (charm_revision ),
229
- "--channel" ,
230
- args .channel ,
185
+ resource_name ,
186
+ "--image" ,
187
+ image_id ,
231
188
]
232
- if oci_resources :
233
- for oci in oci_resources [architecture ]:
234
- command += ["--resource" , f"{ oci .resource_name } :{ oci .revision } " ]
235
- run (command )
189
+ )
190
+ revision : int = json .loads (output )["revision" ]
191
+ logging .info (f"Uploaded charm resource { revision = } " )
192
+ oci_resources .append (OCIResource (resource_name , revision ))
193
+
194
+ # Release charm file(s)
195
+ for charm_revision in charm_revisions :
196
+ logging .info (f"Releasing { charm_revision = } " )
197
+ command = [
198
+ "charmcraft" ,
199
+ "release" ,
200
+ charm_name ,
201
+ "--revision" ,
202
+ str (charm_revision ),
203
+ "--channel" ,
204
+ args .channel ,
205
+ ]
206
+ for oci in oci_resources :
207
+ command += ["--resource" , f"{ oci .resource_name } :{ oci .revision } " ]
208
+ run (command )
236
209
237
210
# Output GitHub release info
238
- revisions = []
239
- for revs in charm_revisions .values ():
240
- revisions .extend (revs )
241
- release_tag = f"rev{ max (revisions )} "
242
- if len (revisions ) == 1 :
211
+ release_tag = f"rev{ max (charm_revisions )} "
212
+ if len (charm_revisions ) == 1 :
243
213
release_title = "Revision "
244
214
else :
245
215
release_title = "Revisions "
246
- release_title += ", " .join (str (revision ) for revision in revisions )
247
- oci_info = "OCI images:"
248
- for architecture , resources in oci_resources .items ():
249
- oci_info += f"\n - { architecture } :"
250
- for oci in resources :
251
- oci_info += f"\n - { dataclasses .asdict (oci )} "
252
- release_notes = f"Released to { args .channel } \n { oci_info } "
216
+ release_title += ", " .join (str (revision ) for revision in charm_revisions )
217
+ release_notes = f"Released to { args .channel } \n OCI images:\n " + "\n " .join (
218
+ f"- { dataclasses .asdict (oci )} " for oci in oci_resources
219
+ )
253
220
with open ("release_notes.txt" , "w" ) as file :
254
221
file .write (release_notes )
255
222
output = f"release_tag={ release_tag } \n release_title={ release_title } "
0 commit comments