diffcone 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diffcone-0.2.0 → diffcone-0.3.0}/PKG-INFO +1 -1
- {diffcone-0.2.0 → diffcone-0.3.0}/pyproject.toml +1 -1
- {diffcone-0.2.0 → diffcone-0.3.0}/pyproject.toml.orig +1 -1
- diffcone-0.3.0/src/diffcone/ci_report.py +382 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/cli.py +35 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/collect.py +5 -2
- {diffcone-0.2.0 → diffcone-0.3.0}/LICENSE +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/README.md +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/__init__.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/cache.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/check.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/classify.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/cython.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/declarations.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/discovery/__init__.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/discovery/asv_static.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/discovery/common.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/discovery/pytest_static.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/evidence.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/evidence_plan.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/execution.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/__init__.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/core.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/definitions.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/dynamics.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/facts.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/literals.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/references.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/resolver.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/scopes.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/state.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/symbols.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/indexer/syntax.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/manifest.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/model.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/planner.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/report.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/selection.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/snapshot.py +0 -0
- {diffcone-0.2.0 → diffcone-0.3.0}/src/diffcone/testing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffcone
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Static-first, function-level change-impact engine for Python: which tests and benchmarks a change can affect, and why
|
|
5
5
|
Keywords: test selection,test impact analysis,change impact,pytest,asv,ci
|
|
6
6
|
Author: Bearing Research
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"""A report over the diffcone steps of many CI runs (roadmap item 11).
|
|
2
|
+
|
|
3
|
+
``diffcone report --dir DIR`` reads what the ``run`` and ``record`` actions
|
|
4
|
+
uploaded, downloaded into one directory per workflow run::
|
|
5
|
+
|
|
6
|
+
DIR/<run id>/run.json the run: id, url, event, created_at,
|
|
7
|
+
head_sha, pull_requests
|
|
8
|
+
DIR/<run id>/<artifact>/context.json what the action did
|
|
9
|
+
DIR/<run id>/<artifact>/ran.json the plan that ran (run)
|
|
10
|
+
DIR/<run id>/<artifact>/plan.json the plan (run before ran.json; record)
|
|
11
|
+
DIR/<run id>/<artifact>/verdict.json the check (record with check)
|
|
12
|
+
DIR/<run id>/<artifact>/rerun-verdict.json the check of the re-run misses
|
|
13
|
+
|
|
14
|
+
and reports, per artifact name (one job, or one cell of a job's matrix):
|
|
15
|
+
pull-request runs (selected share, plans made from the code instead of a
|
|
16
|
+
recording and why, refusals) and checked pushes (checked or not and why,
|
|
17
|
+
new failures, flaky re-runs, confirmed misses), then each confirmed miss.
|
|
18
|
+
It reads files only and runs nothing, like ``check``.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
import statistics
|
|
25
|
+
from collections import Counter
|
|
26
|
+
from dataclasses import dataclass, field
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
ARTIFACT_FILES = frozenset(
|
|
31
|
+
{"context.json", "plan.json", "ran.json", "verdict.json", "rerun-verdict.json"}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ReportError(Exception):
|
|
36
|
+
"""The directory is not a report input."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class Artifact:
|
|
41
|
+
"""One uploaded artifact of one workflow run: one job or matrix cell."""
|
|
42
|
+
|
|
43
|
+
name: str
|
|
44
|
+
run: dict[str, Any]
|
|
45
|
+
context: dict[str, Any] | None
|
|
46
|
+
plan: dict[str, Any] | None
|
|
47
|
+
verdict: dict[str, Any] | None
|
|
48
|
+
rerun: dict[str, Any] | None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass
|
|
52
|
+
class Miss:
|
|
53
|
+
cell: str
|
|
54
|
+
commit: str
|
|
55
|
+
run_url: str
|
|
56
|
+
test: str
|
|
57
|
+
kind: str
|
|
58
|
+
reason: str | None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class CellReport:
|
|
63
|
+
name: str
|
|
64
|
+
pull_requests: int = 0
|
|
65
|
+
selected_shares: list[float] = field(default_factory=list)
|
|
66
|
+
from_code: Counter[str] = field(default_factory=Counter)
|
|
67
|
+
refused: int = 0
|
|
68
|
+
plan_failed: int = 0
|
|
69
|
+
pushes: int = 0
|
|
70
|
+
checked: int = 0
|
|
71
|
+
not_checked: Counter[str] = field(default_factory=Counter)
|
|
72
|
+
new_failures: int = 0
|
|
73
|
+
flaky: int = 0
|
|
74
|
+
misses: int = 0
|
|
75
|
+
check_errors: int = 0
|
|
76
|
+
without_context: int = 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass
|
|
80
|
+
class Report:
|
|
81
|
+
runs: int
|
|
82
|
+
pull_request_runs: int
|
|
83
|
+
push_runs: int
|
|
84
|
+
first: str | None
|
|
85
|
+
last: str | None
|
|
86
|
+
cells: list[CellReport]
|
|
87
|
+
misses: list[Miss]
|
|
88
|
+
earlier_misses: int = 0
|
|
89
|
+
unlisted_misses: int = 0
|
|
90
|
+
check_errors: int = 0
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def ok(self) -> bool:
|
|
94
|
+
"""No confirmed miss and no check that failed to reach a verdict."""
|
|
95
|
+
return not (self.misses or self.earlier_misses or self.unlisted_misses or self.check_errors)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _read(path: Path) -> dict[str, Any] | None:
|
|
99
|
+
try:
|
|
100
|
+
data = json.loads(path.read_text("utf-8"))
|
|
101
|
+
except (OSError, ValueError):
|
|
102
|
+
return None
|
|
103
|
+
return data if isinstance(data, dict) else None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def load(directory: str | Path) -> list[Artifact]:
|
|
107
|
+
root = Path(directory)
|
|
108
|
+
if not root.is_dir():
|
|
109
|
+
raise ReportError(f"{root} is not a directory")
|
|
110
|
+
artifacts: list[Artifact] = []
|
|
111
|
+
for run_dir in sorted(p for p in root.iterdir() if p.is_dir()):
|
|
112
|
+
run = _read(run_dir / "run.json") or {"id": run_dir.name}
|
|
113
|
+
loose = sorted(
|
|
114
|
+
p.name for p in run_dir.iterdir() if p.is_file() and p.name in ARTIFACT_FILES
|
|
115
|
+
)
|
|
116
|
+
if loose:
|
|
117
|
+
raise ReportError(
|
|
118
|
+
f"{run_dir} holds an artifact's files ({', '.join(loose)}) instead of one "
|
|
119
|
+
"directory per artifact; download with --pattern (gh run download RUN "
|
|
120
|
+
"--pattern 'diffcone-*' --dir DIR/RUN) so each artifact has its own"
|
|
121
|
+
)
|
|
122
|
+
for art in sorted(p for p in run_dir.iterdir() if p.is_dir()):
|
|
123
|
+
artifacts.append(
|
|
124
|
+
Artifact(
|
|
125
|
+
name=art.name,
|
|
126
|
+
run=run,
|
|
127
|
+
context=_read(art / "context.json"),
|
|
128
|
+
plan=_read(art / "ran.json") or _read(art / "plan.json"),
|
|
129
|
+
verdict=_read(art / "verdict.json"),
|
|
130
|
+
rerun=_read(art / "rerun-verdict.json"),
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
return artifacts
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _confirmed(art: Artifact) -> list[tuple[str, str]]:
|
|
137
|
+
"""The misses a push's check confirmed, as (test, kind), counted as the
|
|
138
|
+
record action counts them: what is not a test stands (nothing to
|
|
139
|
+
re-run); tests stand when there is no re-run verdict (the re-run ran
|
|
140
|
+
nothing), and otherwise the re-run's own misses are the confirmed ones."""
|
|
141
|
+
if art.verdict is None:
|
|
142
|
+
return []
|
|
143
|
+
kinds = {f["test"]: f.get("kind", "unknown") for f in art.verdict.get("failures", [])}
|
|
144
|
+
standing = [(test, kinds.get(test, "unknown")) for test in art.verdict.get("misses", [])]
|
|
145
|
+
if art.rerun is None:
|
|
146
|
+
return standing
|
|
147
|
+
again = {f["test"]: f.get("kind", "unknown") for f in art.rerun.get("failures", [])}
|
|
148
|
+
return [(t, k) for t, k in standing if k != "test"] + [
|
|
149
|
+
(test, again.get(test, kinds.get(test, "unknown"))) for test in art.rerun.get("misses", [])
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _unselected_reason(plan: dict[str, Any] | None, test: str) -> str | None:
|
|
154
|
+
for target in (plan or {}).get("unselected_targets", []):
|
|
155
|
+
if target.get("runner_id") == test:
|
|
156
|
+
return target.get("reason")
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def build(artifacts: list[Artifact]) -> Report:
|
|
161
|
+
cells: dict[str, CellReport] = {}
|
|
162
|
+
runs: dict[str, dict[str, Any]] = {}
|
|
163
|
+
misses: list[Miss] = []
|
|
164
|
+
earlier = unlisted = check_errors = 0
|
|
165
|
+
for art in artifacts:
|
|
166
|
+
runs[str(art.run.get("id"))] = art.run
|
|
167
|
+
cell = cells.setdefault(art.name, CellReport(art.name))
|
|
168
|
+
context = art.context
|
|
169
|
+
if context is None:
|
|
170
|
+
cell.without_context += 1
|
|
171
|
+
continue
|
|
172
|
+
# Downloaded without run.json (by hand): the action's context knows.
|
|
173
|
+
art.run.setdefault("event", context.get("event"))
|
|
174
|
+
if context.get("action") == "run":
|
|
175
|
+
cell.pull_requests += 1
|
|
176
|
+
counts = ((art.plan or {}).get("analysis") or {}).get("counts") or {}
|
|
177
|
+
if counts.get("targets"):
|
|
178
|
+
cell.selected_shares.append(counts.get("selected", 0) / counts["targets"])
|
|
179
|
+
evidence = ((art.plan or {}).get("analysis") or {}).get("evidence")
|
|
180
|
+
if art.plan is not None and not evidence:
|
|
181
|
+
note = context.get("recording_note") or (
|
|
182
|
+
"the environment differed from the recording's"
|
|
183
|
+
if context.get("recording")
|
|
184
|
+
else "no recording"
|
|
185
|
+
)
|
|
186
|
+
cell.from_code[note] += 1
|
|
187
|
+
plan_exit = context.get("plan_exit")
|
|
188
|
+
if plan_exit not in (0, 1, 3):
|
|
189
|
+
cell.plan_failed += 1
|
|
190
|
+
elif (
|
|
191
|
+
plan_exit == 3
|
|
192
|
+
and not context.get("allow_incomplete_discovery")
|
|
193
|
+
and context.get("run_exit") == 3
|
|
194
|
+
):
|
|
195
|
+
cell.refused += 1
|
|
196
|
+
elif context.get("action") == "record":
|
|
197
|
+
cell.pushes += 1
|
|
198
|
+
if context.get("checked"):
|
|
199
|
+
cell.checked += 1
|
|
200
|
+
else:
|
|
201
|
+
cell.not_checked[context.get("check_note") or "not checked"] += 1
|
|
202
|
+
if art.verdict is not None:
|
|
203
|
+
cell.new_failures += sum(
|
|
204
|
+
1 for f in art.verdict.get("failures", []) if not f.get("already_failing")
|
|
205
|
+
)
|
|
206
|
+
cell.flaky += int(context.get("flaky") or 0)
|
|
207
|
+
count = int(context.get("misses") or 0)
|
|
208
|
+
if context.get("check_error"):
|
|
209
|
+
cell.check_errors += 1
|
|
210
|
+
check_errors += 1
|
|
211
|
+
continue
|
|
212
|
+
cell.misses += count
|
|
213
|
+
if context.get("sticky"):
|
|
214
|
+
# A verdict kept from an earlier run of the commit: a count,
|
|
215
|
+
# its details are in that run.
|
|
216
|
+
earlier += count
|
|
217
|
+
continue
|
|
218
|
+
confirmed = _confirmed(art)
|
|
219
|
+
for test, kind in confirmed:
|
|
220
|
+
misses.append(
|
|
221
|
+
Miss(
|
|
222
|
+
cell=art.name,
|
|
223
|
+
commit=str(context.get("commit") or art.run.get("head_sha") or ""),
|
|
224
|
+
run_url=str(art.run.get("url") or ""),
|
|
225
|
+
test=test,
|
|
226
|
+
kind=kind,
|
|
227
|
+
reason=_unselected_reason(art.plan, test),
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
# The job counted more than its verdicts name (a verdict file
|
|
231
|
+
# missing from the artifact): still misses.
|
|
232
|
+
unlisted += max(0, count - len(confirmed))
|
|
233
|
+
created = sorted(str(r["created_at"]) for r in runs.values() if r.get("created_at"))
|
|
234
|
+
events = Counter(r.get("event") for r in runs.values())
|
|
235
|
+
return Report(
|
|
236
|
+
runs=len(runs),
|
|
237
|
+
pull_request_runs=events.get("pull_request", 0) + events.get("pull_request_target", 0),
|
|
238
|
+
push_runs=events.get("push", 0),
|
|
239
|
+
first=created[0] if created else None,
|
|
240
|
+
last=created[-1] if created else None,
|
|
241
|
+
cells=sorted(cells.values(), key=lambda c: c.name),
|
|
242
|
+
misses=misses,
|
|
243
|
+
earlier_misses=earlier,
|
|
244
|
+
unlisted_misses=unlisted,
|
|
245
|
+
check_errors=check_errors,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def to_dict(report: Report) -> dict[str, Any]:
|
|
250
|
+
return {
|
|
251
|
+
"ok": report.ok,
|
|
252
|
+
"window": {"first": report.first, "last": report.last},
|
|
253
|
+
"runs": {
|
|
254
|
+
"total": report.runs,
|
|
255
|
+
"pull_request": report.pull_request_runs,
|
|
256
|
+
"push": report.push_runs,
|
|
257
|
+
},
|
|
258
|
+
"cells": [
|
|
259
|
+
{
|
|
260
|
+
"name": c.name,
|
|
261
|
+
"pull_requests": {
|
|
262
|
+
"runs": c.pull_requests,
|
|
263
|
+
"selected_median": statistics.median(c.selected_shares)
|
|
264
|
+
if c.selected_shares
|
|
265
|
+
else None,
|
|
266
|
+
"selected_max": max(c.selected_shares) if c.selected_shares else None,
|
|
267
|
+
"planned_from_code": dict(c.from_code),
|
|
268
|
+
"refused": c.refused,
|
|
269
|
+
"plan_failed": c.plan_failed,
|
|
270
|
+
},
|
|
271
|
+
"pushes": {
|
|
272
|
+
"runs": c.pushes,
|
|
273
|
+
"checked": c.checked,
|
|
274
|
+
"not_checked": dict(c.not_checked),
|
|
275
|
+
"new_failures": c.new_failures,
|
|
276
|
+
"flaky": c.flaky,
|
|
277
|
+
"misses": c.misses,
|
|
278
|
+
"check_errors": c.check_errors,
|
|
279
|
+
},
|
|
280
|
+
"without_context": c.without_context,
|
|
281
|
+
}
|
|
282
|
+
for c in report.cells
|
|
283
|
+
],
|
|
284
|
+
"misses": [
|
|
285
|
+
{
|
|
286
|
+
"cell": m.cell,
|
|
287
|
+
"commit": m.commit,
|
|
288
|
+
"run": m.run_url,
|
|
289
|
+
"test": m.test,
|
|
290
|
+
"kind": m.kind,
|
|
291
|
+
"plan_reason": m.reason,
|
|
292
|
+
}
|
|
293
|
+
for m in report.misses
|
|
294
|
+
],
|
|
295
|
+
"earlier_misses": report.earlier_misses,
|
|
296
|
+
"unlisted_misses": report.unlisted_misses,
|
|
297
|
+
"check_errors": report.check_errors,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _share(value: float | None) -> str:
|
|
302
|
+
return "-" if value is None else f"{100 * value:.1f} %"
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def to_markdown(report: Report) -> str:
|
|
306
|
+
lines = [
|
|
307
|
+
f"### diffcone report: {'no miss' if report.ok else 'MISSES'}",
|
|
308
|
+
"",
|
|
309
|
+
f"{report.runs} workflow run(s) ({report.pull_request_runs} pull request, "
|
|
310
|
+
f"{report.push_runs} push)"
|
|
311
|
+
+ (f", {report.first} to {report.last}" if report.first else "")
|
|
312
|
+
+ ".",
|
|
313
|
+
"",
|
|
314
|
+
]
|
|
315
|
+
if report.misses or report.earlier_misses or report.unlisted_misses:
|
|
316
|
+
lines += [
|
|
317
|
+
"**Misses**: tests that failed on a push, were not selected by the plan "
|
|
318
|
+
"of its change, and failed again when re-run (or could not be re-run).",
|
|
319
|
+
"",
|
|
320
|
+
]
|
|
321
|
+
for m in report.misses:
|
|
322
|
+
where = f"[{m.commit[:12]}]({m.run_url})" if m.run_url else m.commit[:12]
|
|
323
|
+
reason = f"; the plan: {m.reason}" if m.reason else ""
|
|
324
|
+
lines.append(f"- `{m.test}` ({m.kind}) in {m.cell} at {where}{reason}")
|
|
325
|
+
if report.earlier_misses:
|
|
326
|
+
lines.append(
|
|
327
|
+
f"- {report.earlier_misses} kept from an earlier run of the same commit "
|
|
328
|
+
"(see that run's job summary)"
|
|
329
|
+
)
|
|
330
|
+
if report.unlisted_misses:
|
|
331
|
+
lines.append(
|
|
332
|
+
f"- {report.unlisted_misses} counted by a job whose uploaded verdicts do not "
|
|
333
|
+
"name them (see the jobs' summaries)"
|
|
334
|
+
)
|
|
335
|
+
lines.append("")
|
|
336
|
+
if report.check_errors:
|
|
337
|
+
lines += [
|
|
338
|
+
f"**{report.check_errors} check(s) failed** to reach a verdict; see the jobs' logs.",
|
|
339
|
+
"",
|
|
340
|
+
]
|
|
341
|
+
prs = [c for c in report.cells if c.pull_requests]
|
|
342
|
+
if prs:
|
|
343
|
+
lines += [
|
|
344
|
+
"**Pull requests**",
|
|
345
|
+
"",
|
|
346
|
+
"| job | runs | selected (median) | selected (max) | planned from the code "
|
|
347
|
+
"| refused | plan failed |",
|
|
348
|
+
"|---|---|---|---|---|---|---|",
|
|
349
|
+
]
|
|
350
|
+
for c in prs:
|
|
351
|
+
median = statistics.median(c.selected_shares) if c.selected_shares else None
|
|
352
|
+
peak = max(c.selected_shares) if c.selected_shares else None
|
|
353
|
+
from_code = ", ".join(f"{n} ({why})" for why, n in c.from_code.most_common()) or "0"
|
|
354
|
+
lines.append(
|
|
355
|
+
f"| {c.name} | {c.pull_requests} | {_share(median)} | {_share(peak)} | "
|
|
356
|
+
f"{from_code} | {c.refused} | {c.plan_failed} |"
|
|
357
|
+
)
|
|
358
|
+
lines.append("")
|
|
359
|
+
pushes = [c for c in report.cells if c.pushes]
|
|
360
|
+
if pushes:
|
|
361
|
+
lines += [
|
|
362
|
+
"**Pushes to the default branch**",
|
|
363
|
+
"",
|
|
364
|
+
"| job | pushes | checked | not checked | new failures | flaky | misses "
|
|
365
|
+
"| check errors |",
|
|
366
|
+
"|---|---|---|---|---|---|---|---|",
|
|
367
|
+
]
|
|
368
|
+
for c in pushes:
|
|
369
|
+
not_checked = ", ".join(f"{n} ({why})" for why, n in c.not_checked.most_common()) or "0"
|
|
370
|
+
lines.append(
|
|
371
|
+
f"| {c.name} | {c.pushes} | {c.checked} | {not_checked} | {c.new_failures} | "
|
|
372
|
+
f"{c.flaky} | {c.misses} | {c.check_errors} |"
|
|
373
|
+
)
|
|
374
|
+
lines.append("")
|
|
375
|
+
blind = [c for c in report.cells if c.without_context]
|
|
376
|
+
if blind:
|
|
377
|
+
lines.append(
|
|
378
|
+
"Artifacts without the context the actions write (made by an older version?): "
|
|
379
|
+
+ ", ".join(f"{c.name} ({c.without_context})" for c in blind)
|
|
380
|
+
)
|
|
381
|
+
lines.append("")
|
|
382
|
+
return "\n".join(lines)
|
|
@@ -22,6 +22,8 @@ the runner's exit code (0 when nothing was selected or with --dry-run; pytest's
|
|
|
22
22
|
0 when every outcome change was selected, 1 when some were missed, 2 on
|
|
23
23
|
errors. ``check`` exits 0 when every new failure of the full run was
|
|
24
24
|
selected, 1 when the plan missed one, 2 when an input cannot be read.
|
|
25
|
+
``report`` exits 0 when the CI runs it reads have no miss and no failed check,
|
|
26
|
+
1 otherwise, 2 when the directory cannot be read.
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
from __future__ import annotations
|
|
@@ -36,6 +38,7 @@ import traceback
|
|
|
36
38
|
from pathlib import Path
|
|
37
39
|
|
|
38
40
|
from diffcone import check as checking
|
|
41
|
+
from diffcone import ci_report
|
|
39
42
|
from diffcone.cache import IndexCache, default_cache_dir
|
|
40
43
|
from diffcone.discovery import RUNNERS, DiscoveryOptions, discover
|
|
41
44
|
from diffcone.evidence import (
|
|
@@ -377,6 +380,22 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
377
380
|
k.add_argument("--format", choices=("text", "markdown", "json"), default="text")
|
|
378
381
|
k.add_argument("--output", "-o", help="write the result to this file instead of stdout")
|
|
379
382
|
|
|
383
|
+
rp = sub.add_parser(
|
|
384
|
+
"report",
|
|
385
|
+
help="report on many CI runs of the diffcone actions: selection, checks, misses",
|
|
386
|
+
description=(
|
|
387
|
+
"Read the results the run and record actions uploaded, downloaded into one "
|
|
388
|
+
"directory per workflow run (DIR/<run id>/run.json and DIR/<run id>/<artifact>/), "
|
|
389
|
+
"and report per job: the share pull requests selected and why some were planned "
|
|
390
|
+
"from the code, and for pushes whether each was checked, its new failures, flaky "
|
|
391
|
+
"re-runs and confirmed misses. The report action downloads the directory. Runs "
|
|
392
|
+
"nothing."
|
|
393
|
+
),
|
|
394
|
+
)
|
|
395
|
+
rp.add_argument("--dir", required=True, help="the directory of downloaded runs")
|
|
396
|
+
rp.add_argument("--format", choices=("markdown", "json"), default="markdown")
|
|
397
|
+
rp.add_argument("--output", "-o", help="write the report to this file instead of stdout")
|
|
398
|
+
|
|
380
399
|
pr = sub.add_parser(
|
|
381
400
|
"prune",
|
|
382
401
|
help="shrink the cache to what planning at given commits reads",
|
|
@@ -545,6 +564,20 @@ def _collect(args: argparse.Namespace) -> int:
|
|
|
545
564
|
return 0
|
|
546
565
|
|
|
547
566
|
|
|
567
|
+
def _report(args: argparse.Namespace) -> int:
|
|
568
|
+
try:
|
|
569
|
+
report = ci_report.build(ci_report.load(args.dir))
|
|
570
|
+
except ci_report.ReportError as exc:
|
|
571
|
+
print(f"diffcone: error: {exc}", file=sys.stderr)
|
|
572
|
+
return 2
|
|
573
|
+
if args.format == "json":
|
|
574
|
+
text = json.dumps(ci_report.to_dict(report), indent=2) + "\n"
|
|
575
|
+
else:
|
|
576
|
+
text = ci_report.to_markdown(report)
|
|
577
|
+
code = _write(text, args.output)
|
|
578
|
+
return code if code else (0 if report.ok else 1)
|
|
579
|
+
|
|
580
|
+
|
|
548
581
|
def _run_exit_code(returncode: int, missing: bool) -> int:
|
|
549
582
|
"""``run``'s exit code from the runner's. Selected targets that did not run
|
|
550
583
|
make it 3 (the run may have skipped tests) unless the runner failed on its
|
|
@@ -595,6 +628,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
595
628
|
return _collect(args)
|
|
596
629
|
if args.command == "check":
|
|
597
630
|
return _check(args)
|
|
631
|
+
if args.command == "report":
|
|
632
|
+
return _report(args)
|
|
598
633
|
if args.command == "prune":
|
|
599
634
|
return _prune(args)
|
|
600
635
|
options = DiscoveryOptions(
|
|
@@ -602,12 +602,15 @@ def _inert_probe(event: str, args: tuple) -> bool:
|
|
|
602
602
|
return False
|
|
603
603
|
program = argv[0]
|
|
604
604
|
name = os.path.basename(program)
|
|
605
|
+
# ``shutil.which("uv")`` is ``...\\uv.EXE`` on Windows.
|
|
606
|
+
tool_name = name.lower().removesuffix(".exe")
|
|
605
607
|
try:
|
|
606
608
|
runs = os.path.basename(os.fsdecode(executable)) if executable is not None else name
|
|
607
609
|
except TypeError:
|
|
608
610
|
return False
|
|
609
|
-
if runs ==
|
|
610
|
-
|
|
611
|
+
if runs.lower().removesuffix(".exe") == tool_name and any(
|
|
612
|
+
tool_name == tool and tuple(argv[1 : 1 + len(start)]) == start
|
|
613
|
+
for tool, start in _INERT_QUERIES
|
|
611
614
|
):
|
|
612
615
|
return True
|
|
613
616
|
if not (_INTERPRETER.fullmatch(name) or program == sys.executable):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|