Skip to content

Commit e63c48d

Browse files
committed
Print count of ignored stale builders
1 parent 48dcbc2 commit e63c48d

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

buildbotapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ async def all_builders(self, branch: str | None = None) -> dict[int, Builder]:
6262
}
6363
return all_builders
6464

65-
async def is_builder_failing_currently(self, builder: Builder) -> bool:
65+
async def is_builder_failing_currently(self, builder: Builder) -> bool | None:
66+
"""Return whether the most recent build failed, or None if the
67+
builder is stale (ignored because its most recent build is older
68+
than STALE_BUILDER_DAYS)."""
6669
builds_: dict[str, Any] = await self._fetch_json(
6770
f"https://buildbot.python.org/all/api/v2/builds?complete__eq=true"
6871
f"&&builderid__eq={builder.builderid}&&order=-complete_at"
@@ -75,7 +78,7 @@ async def is_builder_failing_currently(self, builder: Builder) -> bool:
7578

7679
age_days = (time.time() - build["complete_at"]) / SECONDS_PER_DAY
7780
if age_days > STALE_BUILDER_DAYS:
78-
return False
81+
return None
7982
if build["results"] == 2:
8083
return True
8184
return False

run_release.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import release as release_mod
3636
import sbom
3737
import update_version_next
38-
from buildbotapi import BuildBotAPI, Builder
38+
from buildbotapi import STALE_BUILDER_DAYS, BuildBotAPI, Builder
3939
from release import ReleaseShelf, Tag, Task, ask_question
4040

4141
API_KEY_REGEXP = re.compile(r"(?P<user>\w+):(?P<key>\w+)")
@@ -352,10 +352,10 @@ def check_sigstore_version(version: str) -> None:
352352

353353

354354
def check_buildbots(db: ReleaseShelf) -> None:
355-
async def _check() -> set[Builder]:
355+
async def _check() -> tuple[set[Builder], int]:
356356
async def _get_builder_status(
357357
buildbot_api: BuildBotAPI, the_builder: Builder
358-
) -> tuple[Builder, bool]:
358+
) -> tuple[Builder, bool | None]:
359359
return the_builder, await buildbot_api.is_builder_failing_currently(
360360
the_builder
361361
)
@@ -378,11 +378,21 @@ async def _get_builder_status(
378378
for the_builder in stable_builders.values()
379379
]
380380
)
381-
return {the_builder for (the_builder, is_failing) in builders if is_failing}
381+
stale_count = sum(is_failing is None for _, is_failing in builders)
382+
return {
383+
the_builder for (the_builder, is_failing) in builders if is_failing
384+
}, stale_count
385+
386+
failing_builders, stale_count = asyncio.run(_check())
387+
if stale_count:
388+
print(
389+
f"Ignoring {stale_count} stale builder{'' if stale_count == 1 else 's'}"
390+
f" (no builds in the last {STALE_BUILDER_DAYS} days)"
391+
)
382392

383-
failing_builders = asyncio.run(_check())
384393
if not failing_builders:
385394
return
395+
386396
print()
387397
print("The following buildbots are failing:")
388398
for builder in failing_builders:

tests/test_buildbotapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,14 @@ async def test_buildbotapi_stable_builders() -> None:
127127
# At the staleness cutoff: failure still counts
128128
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + 14 * DAY, True),
129129
# Stale build (last run > 14 days ago): builder ignored
130-
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + 15 * DAY, False),
130+
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + 15 * DAY, None),
131131
],
132132
)
133133
async def test_buildbotapi_is_builder_failing_currently(
134-
monkeypatch: pytest.MonkeyPatch, json_data: str, now: int, expected: bool
134+
monkeypatch: pytest.MonkeyPatch,
135+
json_data: str,
136+
now: int,
137+
expected: bool | None,
135138
) -> None:
136139
# Arrange
137140
mock_session = AsyncMock(aiohttp.ClientSession)

0 commit comments

Comments
 (0)