Skip to content

Commit 9acd70e

Browse files
committed
ci: read an unreadable environment recording as not a match
A cache miss, an eviction or a cache-service outage leaves the reference file absent, and the comparison then reported `match=true`: every guarded step ran and the run uploaded a measurement without having identified the machine it was taken on. An absent recording now reports `match=false`, and says so as a `::warning` rather than the `::notice` a mismatch emits, so a job that measures nothing because it has nothing to compare against is distinguishable from one that measures nothing because the machine differs. Assisted-by: Claude
1 parent c2e1b70 commit 9acd70e

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

‎scripts/codspeed-environment.py‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
2424
The rule this enforces: `main` defines the environment. Every run on it records
2525
what it measured on, and a run on any other ref measures only when it matches
26-
that recording. A mismatch is skipped rather than uploaded, because an uploaded
27-
cross-environment run is published as a regression of the branch that happened
28-
to draw the other machine.
26+
that recording. Anything else is skipped rather than uploaded, because an
27+
uploaded cross-environment run is published as a regression of the branch that
28+
happened to draw the other machine. A recording that cannot be read is
29+
"anything else" too: an unknown machine is not a matching one, and reading it as
30+
one would leave the guard open exactly while it has nothing to check against.
2931
3032
codspeed-environment.py --record build/codspeed-environment.json
3133
codspeed-environment.py --record CURRENT --reference REFERENCE --github-output
@@ -220,8 +222,8 @@ def main(argv=None):
220222
parser.add_argument(
221223
"--reference",
222224
metavar="PATH",
223-
help="compare against a previously recorded environment; a missing file"
224-
" is not a mismatch, because there is nothing yet to disagree with",
225+
help="compare against a previously recorded environment; a file that"
226+
" cannot be read leaves the machine unidentified, which is not a match",
225227
)
226228
parser.add_argument(
227229
"--github-output",
@@ -235,18 +237,34 @@ def main(argv=None):
235237
_render(current)
236238

237239
match = True
240+
annotation = ""
238241
if args.reference:
239242
try:
240243
with open(args.reference, encoding="utf-8") as handle:
241244
reference = json.load(handle)
242245
except (OSError, ValueError):
243-
print(
244-
f"\nNo reference environment at {args.reference}; recording this one."
246+
match = False
247+
# A warning rather than a notice: a mismatch is the guard working,
248+
# while an unreadable recording means it has nothing to work from,
249+
# and a job that quietly measures nothing forever looks the same as
250+
# one that measures.
251+
annotation = (
252+
"::warning title=CodSpeed benchmarks skipped::No recording of the"
253+
" machine the comparison base was measured on could be read at"
254+
f" {args.reference}, so a measurement taken here cannot be shown"
255+
" to be comparable with it."
245256
)
257+
print(f"\nNo reference environment at {args.reference}.")
246258
else:
247259
moved = differences(current, reference)
248260
if moved:
249261
match = False
262+
annotation = (
263+
"::notice title=CodSpeed benchmarks skipped::"
264+
f"This runner ({current['cpu_brand']}, {current['digest']}) is"
265+
" not the machine the comparison base was measured on, and an"
266+
" upload from it would be published as a regression."
267+
)
250268
# Digest the reference's own fields rather than reading back the
251269
# digest stored beside them, so a recording written by an older
252270
# field set is named by what it actually holds.
@@ -272,15 +290,10 @@ def main(argv=None):
272290
handle.write("\n")
273291

274292
if args.github_output:
275-
if not match:
276-
# A skipped job is otherwise indistinguishable from one that never
277-
# had benchmarks, and the reason is the one fact a reader needs.
278-
print(
279-
"::notice title=CodSpeed benchmarks skipped::"
280-
f"This runner ({current['cpu_brand']}, {current['digest']}) is not"
281-
" the machine the comparison base was measured on, and an"
282-
" upload from it would be published as a regression."
283-
)
293+
# A skipped job is otherwise indistinguishable from one that never had
294+
# benchmarks, and the reason is the one fact a reader needs.
295+
if annotation:
296+
print(annotation)
284297
output = os.environ.get("GITHUB_OUTPUT")
285298
if output:
286299
with open(output, "a", encoding="utf-8") as handle:

0 commit comments

Comments
 (0)