Skip to content

Commit

Permalink
Fix misc/sign_windows_release.py artificat query when newer build h…
Browse files Browse the repository at this point in the history
…ave shadowned the one we want
  • Loading branch information
touilleMan committed Feb 28, 2025
1 parent 7e019bb commit 0ec10d4
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions misc/sign_windows_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,23 @@ class Artifact:
version: str


@dataclass(frozen=True, slots=True)
class Artifacts:
name: str
items: tuple[Artifact]
# Number of artifacts matching the `name`, but which have been omitted
# when querying Github API given they are too old.
omitted: int


@lru_cache
def get_artifacts(base_url: str, token: str, version: None | str = None) -> tuple[Artifact]:
url = f"{base_url}/actions/artifacts?per_page=100"
def get_artifacts(base_url: str, token: str, name: str) -> Artifacts:
per_page = 100 # Max allowed by Github API
url = f"{base_url}/actions/artifacts?name={name}&per_page={per_page}"
response = get(url, token)
artifacts = []
for raw in json.loads(response.read())["artifacts"]:
body = json.loads(response.read())
for raw in body["artifacts"]:
head = raw["workflow_run"]["head_branch"]
if not head.startswith("v"):
continue
Expand All @@ -96,20 +107,30 @@ def get_artifacts(base_url: str, token: str, version: None | str = None) -> tupl
version=head,
)
)
return tuple(artifacts)
return Artifacts(
name=name,
items=tuple(artifacts),
omitted=body["total_count"] - per_page,
)


@lru_cache
def get_artifact(
artifact_name: str, base_url: str, token: str, version: None | str = None
) -> Artifact:
for artifact in get_artifacts(base_url, token, version):
if artifact.name != artifact_name:
continue
artifacts = get_artifacts(base_url, token, artifact_name)
for artifact in artifacts.items:
if version is not None and artifact.version != version:
continue
return artifact

# Since we filter the artifact by name and are only interested into signing recent
# releases, it is unlikely that what we are looking for is among the omitted items
# (more likely we are looking for something that doesn't exist).
if artifacts.omitted:
print(
f"WARNING: {artifacts.omitted} older items correspond to `{artifact_name}` artificat have been omitted"

Check warning on line 131 in misc/sign_windows_release.py

View workflow job for this annotation

GitHub Actions / spelling / cspell

Unknown word (artificat)
)

if version is None:
raise RuntimeError(f"Artifact {artifact_name} not found")
else:
Expand Down

0 comments on commit 0ec10d4

Please sign in to comment.