Skip to content

Commit 0504b6b

Browse files
[skip ci] Fix artifact name parsing in gh-distribute-toolchain
1 parent fa299d2 commit 0504b6b

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

tools/gh-distribute-toolchain

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,6 @@ class SDKArtifactFormat:
167167
raise NotImplementedError()
168168

169169

170-
class SDKArtifactFormatV2(SDKArtifactFormat):
171-
def __init__(self, platform_suffix: str):
172-
self.platform_suffix = platform_suffix
173-
174-
def swift_sdk_artifact_id(self, tag_name: str):
175-
return tag_name.removeprefix("swift-wasm-") + "-wasm"
176-
177-
def swift_sdk_artifact_filename(self, tag_name: str):
178-
return f"{tag_name}-{self.platform_suffix}.artifactbundle"
179-
180-
181170
class SDKArtifactFormatV3(SDKArtifactFormat):
182171
def __init__(self, target_triple: str):
183172
self.target_triple = target_triple
@@ -210,11 +199,15 @@ class Distribution:
210199
for artifact in self.toolchain_artifacts(options):
211200
if not artifact["name"].endswith("-artifactbundle"):
212201
print(f"Skipping {artifact['name']} because it's not an"
213-
" artifactbundle for --only-swift-sdk")
202+
" artifactbundle")
214203
continue
215204

216-
_, scheme, _ = derive_platform_suffix_and_scheme(
217-
artifact["name"], options.scheme)
205+
try:
206+
scheme, _ = derive_platform_suffix_and_scheme(
207+
artifact["name"], options.scheme)
208+
except Exception:
209+
print(f"Skipping {artifact['name']} because it's not a valid artifactbundle for {options.scheme}")
210+
continue
218211

219212
if options.scheme != scheme:
220213
print(f"Skipping {artifact['name']} because it's not scheme {options.scheme}")
@@ -251,7 +244,7 @@ class Distribution:
251244
for artifact, artifact_path in downloaded_paths:
252245
if not artifact["name"].endswith("-artifactbundle"):
253246
continue
254-
platform_suffix, _, target_triple = derive_platform_suffix_and_scheme(
247+
_, target_triple = derive_platform_suffix_and_scheme(
255248
artifact["name"], options.scheme)
256249
bundle_path = await self.unpack_artifactbundle(artifact_path)
257250
dirents = os.listdir(bundle_path)
@@ -278,7 +271,7 @@ class Distribution:
278271

279272
async def package_sdk_work(downloaded):
280273
artifact, artifact_path = downloaded
281-
platform_suffix, scheme, target_triple = derive_platform_suffix_and_scheme(
274+
scheme, target_triple = derive_platform_suffix_and_scheme(
282275
artifact["name"], options.scheme)
283276
artifact_format = SDKArtifactFormatV3(target_triple)
284277
bundle_path = await self.unpack_artifactbundle(artifact_path)
@@ -584,13 +577,13 @@ You can install Swift SDKs for WebAssembly using the following commands:
584577

585578
def derive_platform_suffix_and_scheme(
586579
artifact_name: str, target_scheme: str
587-
) -> Tuple[Optional[str], str, str]:
580+
) -> Optional[Tuple[str, str]]:
588581
"""
589582
Returns platform suffix, scheme, and target triple derived from the
590583
artifact name.
591584
e.g.
592585
"main-wasm32-unknown-wasi-artifactbundle", scheme="main"
593-
-> [None, "main", "wasm32-unknown-wasi"]
586+
-> ["main", "wasm32-unknown-wasi"]
594587
"""
595588

596589
# v3 artifact name: <scheme>-<target-triple>-artifactbundle
@@ -610,7 +603,8 @@ def derive_platform_suffix_and_scheme(
610603
f"Unexpected artifact name {name} with format v3 should"
611604
" end with -artifactbundle")
612605
target_triple = rest[:-len("-artifactbundle")]
613-
return [None, target_scheme, target_triple]
606+
return [target_scheme, target_triple]
607+
raise Exception(f"Unexpected artifact name {name}")
614608

615609

616610
def latest_success_run_id(gh: GitHub, workflow_name: str, branch: str, scheme: str):
@@ -626,11 +620,13 @@ def latest_success_run_id(gh: GitHub, workflow_name: str, branch: str, scheme: s
626620
artifacts = gh.list_artifacts(run["id"])
627621
for artifact in artifacts:
628622
artifact_name = artifact["name"]
629-
if not artifact_name.endswith("-artifactbundle"):
623+
try:
624+
artifact_scheme, _ = derive_platform_suffix_and_scheme(
625+
artifact_name, scheme)
626+
if artifact_scheme == scheme:
627+
return run["id"]
628+
except Exception:
630629
continue
631-
_, artifact_scheme, _ = derive_platform_suffix_and_scheme(artifact_name, scheme)
632-
if artifact_scheme == scheme:
633-
return run["id"]
634630
print(f"Could not find a successful run for {workflow_name} on {branch} branch with scheme {scheme}")
635631
return None
636632

0 commit comments

Comments
 (0)