quality-graph-github 0.1.9__py3-none-any.whl → 0.2.0__py3-none-any.whl
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.
- qg_github/artifacts.py +40 -9
- qg_github/commands.py +4 -5
- qg_github/compiler.py +137 -19
- qg_github/dashboard.py +10 -3
- qg_github/declarations.py +141 -0
- qg_github/github.py +1 -1
- qg_github/publication.py +124 -32
- qg_github/reporting.py +10 -1
- qg_github/runtime.py +5 -4
- {quality_graph_github-0.1.9.dist-info → quality_graph_github-0.2.0.dist-info}/METADATA +2 -2
- quality_graph_github-0.2.0.dist-info/RECORD +23 -0
- quality_graph_github-0.1.9.dist-info/RECORD +0 -22
- {quality_graph_github-0.1.9.dist-info → quality_graph_github-0.2.0.dist-info}/WHEEL +0 -0
- {quality_graph_github-0.1.9.dist-info → quality_graph_github-0.2.0.dist-info}/entry_points.txt +0 -0
qg_github/artifacts.py
CHANGED
|
@@ -12,7 +12,7 @@ from pathlib import PurePosixPath
|
|
|
12
12
|
from typing import TYPE_CHECKING
|
|
13
13
|
|
|
14
14
|
from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
|
|
15
|
-
from quality_graph_core.result import JsonValue, Result
|
|
15
|
+
from quality_graph_core.result import JsonValue, Provenance, Result, ResultStatus
|
|
16
16
|
|
|
17
17
|
if TYPE_CHECKING:
|
|
18
18
|
from collections.abc import Iterable, Mapping
|
|
@@ -30,18 +30,25 @@ class ArtifactError(ValueError):
|
|
|
30
30
|
"""Represent an invalid or incompatible result artifact."""
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
class DeclarationMismatchError(ArtifactError):
|
|
34
|
+
"""Identify a different declaration after workflow identity has been verified."""
|
|
35
|
+
|
|
36
|
+
|
|
33
37
|
@dataclass(frozen=True)
|
|
34
38
|
class ArtifactExpectation:
|
|
35
39
|
"""Describe trusted workflow provenance required from every result."""
|
|
36
40
|
|
|
37
41
|
repository: str
|
|
38
|
-
pull_request: int
|
|
42
|
+
pull_request: int | None
|
|
39
43
|
head_sha: str
|
|
40
44
|
workflow_run_id: int
|
|
41
45
|
graph_digest: str
|
|
42
46
|
node_ids: frozenset[str]
|
|
43
47
|
flow_id: str | None = None
|
|
44
48
|
operation_ids: Mapping[str, str] = field(default_factory=dict)
|
|
49
|
+
run_attempt: int = 1
|
|
50
|
+
node_attempts: Mapping[str, int] = field(default_factory=dict)
|
|
51
|
+
node_conclusions: Mapping[str, str] = field(default_factory=dict)
|
|
45
52
|
|
|
46
53
|
|
|
47
54
|
@dataclass(frozen=True)
|
|
@@ -59,19 +66,34 @@ def download_results(
|
|
|
59
66
|
port: GitHubPort,
|
|
60
67
|
expectation: ArtifactExpectation,
|
|
61
68
|
) -> dict[str, Result]:
|
|
62
|
-
"""Download
|
|
63
|
-
selected: dict[str,
|
|
69
|
+
"""Download results bound to the expected execution of each node."""
|
|
70
|
+
selected: dict[str, Result] = {}
|
|
71
|
+
seen: dict[tuple[str, int], Result] = {}
|
|
64
72
|
for descriptor in _artifact_descriptors(port, expectation.workflow_run_id):
|
|
65
73
|
if descriptor.node_id not in expectation.node_ids:
|
|
66
74
|
message = f"artifact targets unknown graph node: {descriptor.node_id}"
|
|
75
|
+
raise DeclarationMismatchError(message)
|
|
76
|
+
if descriptor.attempt > expectation.run_attempt:
|
|
77
|
+
message = "result artifact attempt exceeds the latest workflow attempt"
|
|
67
78
|
raise ArtifactError(message)
|
|
68
79
|
archive = port.download(f"/actions/artifacts/{descriptor.id}/zip")
|
|
69
80
|
result = _result_from_archive(archive, descriptor)
|
|
70
81
|
_validate_result(result, descriptor, expectation)
|
|
71
|
-
|
|
72
|
-
if
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
key = (descriptor.node_id, descriptor.attempt)
|
|
83
|
+
if key in seen and seen[key] != result:
|
|
84
|
+
message = f"conflicting result artifacts for node {key[0]} attempt {key[1]}"
|
|
85
|
+
raise ArtifactError(message)
|
|
86
|
+
seen[key] = result
|
|
87
|
+
expected_attempt = expectation.node_attempts.get(
|
|
88
|
+
descriptor.node_id, expectation.run_attempt
|
|
89
|
+
)
|
|
90
|
+
if descriptor.attempt == expected_attempt:
|
|
91
|
+
conclusion = expectation.node_conclusions.get(descriptor.node_id)
|
|
92
|
+
if result.status is ResultStatus.PASSED and conclusion not in {None, "success"}:
|
|
93
|
+
message = f"passed result contradicts workflow job state: {descriptor.node_id}"
|
|
94
|
+
raise ArtifactError(message)
|
|
95
|
+
selected[descriptor.node_id] = result
|
|
96
|
+
return selected
|
|
75
97
|
|
|
76
98
|
|
|
77
99
|
def _artifact_descriptors(port: GitHubPort, run_id: int) -> tuple[ArtifactDescriptor, ...]:
|
|
@@ -169,6 +191,9 @@ def _validate_result(
|
|
|
169
191
|
expectation: ArtifactExpectation,
|
|
170
192
|
) -> None:
|
|
171
193
|
provenance = result.provenance
|
|
194
|
+
if not isinstance(provenance, Provenance):
|
|
195
|
+
message = "GitHub artifact contains foreign provider provenance"
|
|
196
|
+
raise ArtifactError(message)
|
|
172
197
|
expected = (
|
|
173
198
|
expectation.repository,
|
|
174
199
|
expectation.pull_request,
|
|
@@ -189,7 +214,13 @@ def _validate_result(
|
|
|
189
214
|
provenance.flow_id,
|
|
190
215
|
provenance.operation_id,
|
|
191
216
|
)
|
|
192
|
-
if result.node_id != descriptor.node_id or observed != expected:
|
|
217
|
+
if result.node_id != descriptor.node_id or observed[:5] != expected[:5]:
|
|
218
|
+
message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
|
|
219
|
+
raise ArtifactError(message)
|
|
220
|
+
if provenance.graph_digest != expectation.graph_digest:
|
|
221
|
+
message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
|
|
222
|
+
raise DeclarationMismatchError(message)
|
|
223
|
+
if observed[5:] != expected[5:]:
|
|
193
224
|
message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
|
|
194
225
|
raise ArtifactError(message)
|
|
195
226
|
|
qg_github/commands.py
CHANGED
|
@@ -9,9 +9,10 @@ from dataclasses import dataclass
|
|
|
9
9
|
from enum import StrEnum
|
|
10
10
|
|
|
11
11
|
from qg_github.approvals import ApprovalRecord, append_approval_record
|
|
12
|
-
from qg_github.artifacts import ArtifactExpectation
|
|
12
|
+
from qg_github.artifacts import ArtifactExpectation
|
|
13
13
|
from qg_github.compiler import compile_graph
|
|
14
14
|
from qg_github.controls import control_states, decode_control_marker
|
|
15
|
+
from qg_github.declarations import read_pr_results
|
|
15
16
|
from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
|
|
16
17
|
from qg_github.presentation import pr_presentation_graph
|
|
17
18
|
from quality_graph_core.graph import Graph
|
|
@@ -219,11 +220,9 @@ def _command_context(port: GitHubPort, number: int) -> CommandContext:
|
|
|
219
220
|
frozenset(node.id for node in graph.nodes),
|
|
220
221
|
graph.flow_id,
|
|
221
222
|
{node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
|
|
223
|
+
run_attempt=attempt,
|
|
222
224
|
)
|
|
223
|
-
results =
|
|
224
|
-
if any(result.provenance.run_attempt > attempt for result in results.values()):
|
|
225
|
-
message = "result artifact attempt exceeds the latest workflow attempt"
|
|
226
|
-
raise ValueError(message)
|
|
225
|
+
graph, results = read_pr_results(port, graph, expectation)
|
|
227
226
|
state = effective_graph(graph, results, set())
|
|
228
227
|
return CommandContext(graph, run_id, state.targets)
|
|
229
228
|
|
qg_github/compiler.py
CHANGED
|
@@ -35,8 +35,10 @@ GENERATED_HEADER = f"# {GENERATED_NOTICE}\n---\n"
|
|
|
35
35
|
EXECUTION_WORKFLOW = PurePosixPath(".github/workflows/quality-graph.yml")
|
|
36
36
|
PUSH_WORKFLOW = PurePosixPath(".github/workflows/quality-graph-push.yml")
|
|
37
37
|
PUBLICATION_WORKFLOW = PurePosixPath(".github/workflows/quality-graph-publish.yml")
|
|
38
|
+
RELEASE_WORKFLOW = PurePosixPath(".github/workflows/release.yml")
|
|
38
39
|
GRAPH_MANIFEST = PurePosixPath(".quality-graph/manifest.json")
|
|
39
40
|
DEFAULT_UPLOAD_ARTIFACT_ACTION = "actions/upload-artifact@v7"
|
|
41
|
+
RELEASE_UPLOAD_ARTIFACT_ACTION = "actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"
|
|
40
42
|
ACTION_RE = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)?@[A-Za-z0-9_.:/-]+$")
|
|
41
43
|
RUNTIME_ACTION_RE = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+@[0-9a-f]{40}$")
|
|
42
44
|
PERMISSION_NAMES = {
|
|
@@ -134,13 +136,17 @@ def _validate_execution_contracts(graph: Graph) -> None:
|
|
|
134
136
|
message = "compile the original declaration, not a resolved flow"
|
|
135
137
|
raise ValueError(message)
|
|
136
138
|
for profile in graph.profiles:
|
|
137
|
-
_validate_permissions(profile)
|
|
139
|
+
_validate_permissions(profile, allow_write=bool(graph.flows))
|
|
138
140
|
for step in profile.setup:
|
|
139
141
|
_validate_step(step)
|
|
140
142
|
for node in graph.nodes:
|
|
141
|
-
|
|
143
|
+
_validate_node_contract(node, graph.expanded_profiles()[node.profile], allow_write=False)
|
|
142
144
|
for operation in graph.operations:
|
|
143
|
-
|
|
145
|
+
_validate_node_contract(
|
|
146
|
+
operation.place(FlowNode(operation.id, operation.id), DependencyPolicy.GRAPH),
|
|
147
|
+
graph.expanded_profiles()[operation.profile],
|
|
148
|
+
allow_write=True,
|
|
149
|
+
)
|
|
144
150
|
titles = [node.title for node in graph.nodes]
|
|
145
151
|
if len(set(titles)) != len(titles):
|
|
146
152
|
message = "GitHub dashboard requires unique node titles"
|
|
@@ -176,7 +182,7 @@ def _event_projections(graph: Graph) -> tuple[EventProjection, ...]:
|
|
|
176
182
|
flow.dependencies,
|
|
177
183
|
)
|
|
178
184
|
for flow in graph.flows
|
|
179
|
-
if flow.
|
|
185
|
+
if not flow.is_release
|
|
180
186
|
)
|
|
181
187
|
supported = set(SUPPORTED_EVENTS)
|
|
182
188
|
unknown = set(graph.execution) - supported
|
|
@@ -222,7 +228,7 @@ def project_graph(graph: Graph, event: str) -> Graph:
|
|
|
222
228
|
"""Return one dependency-normalized GitHub event graph."""
|
|
223
229
|
if graph.flows:
|
|
224
230
|
for flow in graph.flows:
|
|
225
|
-
if flow.trigger == event:
|
|
231
|
+
if flow.trigger == event and not flow.is_release:
|
|
226
232
|
return graph.for_flow(flow.id)
|
|
227
233
|
message = f"no flow declares the {event} trigger"
|
|
228
234
|
raise ValueError(message)
|
|
@@ -231,13 +237,27 @@ def project_graph(graph: Graph, event: str) -> Graph:
|
|
|
231
237
|
|
|
232
238
|
def _validate_explicit_flows(graph: Graph) -> None:
|
|
233
239
|
for trigger in SUPPORTED_EVENTS:
|
|
234
|
-
selected = [flow for flow in graph.flows if flow.trigger == trigger]
|
|
240
|
+
selected = [flow for flow in graph.flows if flow.trigger == trigger and not flow.is_release]
|
|
235
241
|
if len(selected) > 1:
|
|
236
242
|
message = f"GitHub supports one {trigger} flow per declaration"
|
|
237
243
|
raise ValueError(message)
|
|
244
|
+
releases = [
|
|
245
|
+
flow for flow in graph.flows if flow.is_release and flow.execution_mode == "github-actions"
|
|
246
|
+
]
|
|
247
|
+
if len(releases) > 1:
|
|
248
|
+
message = "GitHub supports one executable release flow per declaration"
|
|
249
|
+
raise ValueError(message)
|
|
238
250
|
for flow in graph.flows:
|
|
251
|
+
if flow.presentation == "gitlab-mr":
|
|
252
|
+
message = "GitHub cannot use GitLab MR presentation"
|
|
253
|
+
raise ValueError(message)
|
|
239
254
|
for branch in flow.branches:
|
|
240
255
|
_default_branch(branch)
|
|
256
|
+
_validate_release_contract(graph, flow)
|
|
257
|
+
for node in graph.for_flow(flow.id).nodes:
|
|
258
|
+
_validate_node_contract(
|
|
259
|
+
node, graph.expanded_profiles()[node.profile], allow_write=flow.is_release
|
|
260
|
+
)
|
|
241
261
|
if flow.presentation == "github-pr":
|
|
242
262
|
titles = [node.title for node in graph.for_flow(flow.id).nodes]
|
|
243
263
|
if len(set(titles)) != len(titles):
|
|
@@ -245,6 +265,44 @@ def _validate_explicit_flows(graph: Graph) -> None:
|
|
|
245
265
|
raise ValueError(message)
|
|
246
266
|
|
|
247
267
|
|
|
268
|
+
def _validate_node_contract(node: Node, profile: Profile, *, allow_write: bool) -> None:
|
|
269
|
+
effective = (
|
|
270
|
+
replace(profile, permissions=node.permissions) if node.permissions is not None else profile
|
|
271
|
+
)
|
|
272
|
+
_validate_permissions(effective, allow_write=allow_write)
|
|
273
|
+
if node.deployment_environment and not allow_write:
|
|
274
|
+
message = "deployment environments are only allowed in release flows"
|
|
275
|
+
raise ValueError(message)
|
|
276
|
+
for step in node.steps or (node.step,):
|
|
277
|
+
_validate_step(step)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _validate_release_contract(graph: Graph, flow: Flow) -> None:
|
|
281
|
+
for pattern in flow.tags:
|
|
282
|
+
if (
|
|
283
|
+
pattern.startswith("!")
|
|
284
|
+
or "${{" in pattern
|
|
285
|
+
or re.search(r"[\x00-\x20\x7f]", pattern)
|
|
286
|
+
or len(pattern) > MAX_BRANCH_NAME_LENGTH
|
|
287
|
+
):
|
|
288
|
+
message = "release tag patterns must be literal nonnegative filters without whitespace"
|
|
289
|
+
raise ValueError(message)
|
|
290
|
+
if not flow.is_release or flow.execution_mode != "github-actions":
|
|
291
|
+
return
|
|
292
|
+
if any(node.checkpoint for node in flow.nodes):
|
|
293
|
+
message = (
|
|
294
|
+
"executable release checkpoints require a resumable provider; use design-only mode"
|
|
295
|
+
)
|
|
296
|
+
raise ValueError(message)
|
|
297
|
+
profiles = graph.expanded_profiles()
|
|
298
|
+
for node in graph.for_flow(flow.id).nodes:
|
|
299
|
+
profile = profiles[node.profile]
|
|
300
|
+
for step in (*profile.setup, *(node.steps or (node.step,))):
|
|
301
|
+
if step.uses is not None and re.fullmatch(r"[^@]+@[0-9a-f]{40}", step.uses) is None:
|
|
302
|
+
message = "executable release actions must be pinned to a 40-character commit"
|
|
303
|
+
raise ValueError(message)
|
|
304
|
+
|
|
305
|
+
|
|
248
306
|
def _default_branch(value: JsonValue) -> str:
|
|
249
307
|
branch = "main" if value is None else value
|
|
250
308
|
if not isinstance(branch, str) or not 1 <= len(branch) <= MAX_BRANCH_NAME_LENGTH:
|
|
@@ -280,12 +338,12 @@ def _upload_artifact_action(runtime: Mapping[str, JsonValue]) -> str:
|
|
|
280
338
|
return _runtime_action(runtime["upload-artifact-action"], "upload artifact")
|
|
281
339
|
|
|
282
340
|
|
|
283
|
-
def _validate_permissions(profile: Profile) -> None:
|
|
341
|
+
def _validate_permissions(profile: Profile, *, allow_write: bool = False) -> None:
|
|
284
342
|
for permission, access in profile.permissions.items():
|
|
285
343
|
if permission not in PERMISSION_NAMES:
|
|
286
344
|
message = f"unknown GitHub permission: {permission}"
|
|
287
345
|
raise ValueError(message)
|
|
288
|
-
if access not in {"none", "read"}:
|
|
346
|
+
if access not in ({"none", "read", "write"} if allow_write else {"none", "read"}):
|
|
289
347
|
message = f"GitHub execution permission must be none or read: {permission}={access}"
|
|
290
348
|
raise ValueError(message)
|
|
291
349
|
|
|
@@ -366,21 +424,44 @@ def _compile_flows(graph: Graph, configuration: _GitHubConfiguration) -> Generat
|
|
|
366
424
|
manifest.update({"graphDigest": digest, "_generated": GENERATED_NOTICE})
|
|
367
425
|
files: list[GeneratedFile] = []
|
|
368
426
|
for flow in graph.flows:
|
|
369
|
-
if flow.
|
|
427
|
+
if flow.execution_mode == "design-only":
|
|
370
428
|
continue
|
|
371
429
|
projection = EventProjection(flow.trigger, graph.for_flow(flow.id).nodes, flow.dependencies)
|
|
372
|
-
|
|
430
|
+
flow_configuration = configuration
|
|
431
|
+
if (
|
|
432
|
+
flow.is_release
|
|
433
|
+
and configuration.upload_artifact_action == DEFAULT_UPLOAD_ARTIFACT_ACTION
|
|
434
|
+
):
|
|
435
|
+
flow_configuration = replace(
|
|
436
|
+
configuration, upload_artifact_action=RELEASE_UPLOAD_ARTIFACT_ACTION
|
|
437
|
+
)
|
|
438
|
+
workflow = _execution_workflow(graph, projection, flow_configuration, digest, flow=flow)
|
|
373
439
|
if flow.concurrency is not None:
|
|
374
440
|
workflow["concurrency"] = {
|
|
375
441
|
"group": f"quality-graph-{flow.concurrency}",
|
|
376
442
|
"cancel-in-progress": False,
|
|
377
443
|
}
|
|
378
|
-
if flow.
|
|
444
|
+
if flow.is_release:
|
|
445
|
+
workflow["name"] = "Release"
|
|
446
|
+
workflow["on"] = (
|
|
447
|
+
{"push": {"tags": list(flow.tags)}}
|
|
448
|
+
if flow.tags
|
|
449
|
+
else {"workflow_dispatch": {"inputs": dict(flow.inputs)}}
|
|
450
|
+
)
|
|
451
|
+
elif flow.trigger == "push":
|
|
379
452
|
workflow["on"] = {"push": {"branches": list(flow.branches)}}
|
|
380
453
|
else:
|
|
381
454
|
workflow["on"] = {"pull_request": {"branches": [configuration.default_branch]}}
|
|
382
|
-
path =
|
|
383
|
-
|
|
455
|
+
path = (
|
|
456
|
+
RELEASE_WORKFLOW
|
|
457
|
+
if flow.is_release
|
|
458
|
+
else EXECUTION_WORKFLOW
|
|
459
|
+
if flow.trigger == "pull-request"
|
|
460
|
+
else PUSH_WORKFLOW
|
|
461
|
+
)
|
|
462
|
+
files.append(
|
|
463
|
+
GeneratedFile(path, _yaml_file(workflow, width=80 if flow.is_release else 1_000))
|
|
464
|
+
)
|
|
384
465
|
if any(flow.presentation == "github-pr" for flow in graph.flows):
|
|
385
466
|
files.append(
|
|
386
467
|
GeneratedFile(
|
|
@@ -395,18 +476,20 @@ def _compile_flows(graph: Graph, configuration: _GitHubConfiguration) -> Generat
|
|
|
395
476
|
for path in (EXECUTION_WORKFLOW, PUSH_WORKFLOW, PUBLICATION_WORKFLOW)
|
|
396
477
|
if path not in paths
|
|
397
478
|
)
|
|
398
|
-
return GeneratedProject(
|
|
479
|
+
return GeneratedProject(
|
|
480
|
+
digest, tuple(files), retired, () if RELEASE_WORKFLOW in paths else (RELEASE_WORKFLOW,)
|
|
481
|
+
)
|
|
399
482
|
|
|
400
483
|
|
|
401
484
|
def _flow_value(flow: Flow) -> dict[str, JsonValue]:
|
|
402
|
-
|
|
485
|
+
value: dict[str, JsonValue] = {
|
|
403
486
|
"trigger": flow.trigger,
|
|
404
487
|
"branches": list(flow.branches),
|
|
405
488
|
"inputs": dict(flow.inputs),
|
|
406
489
|
"dependencies": flow.dependencies.value,
|
|
407
490
|
"presentation": flow.presentation,
|
|
408
491
|
"concurrency": flow.concurrency,
|
|
409
|
-
"execution":
|
|
492
|
+
"execution": flow.execution_mode,
|
|
410
493
|
"nodes": [
|
|
411
494
|
{
|
|
412
495
|
"id": node.id,
|
|
@@ -417,6 +500,9 @@ def _flow_value(flow: Flow) -> dict[str, JsonValue]:
|
|
|
417
500
|
for node in flow.nodes
|
|
418
501
|
],
|
|
419
502
|
}
|
|
503
|
+
if flow.tags:
|
|
504
|
+
value["tags"] = list(flow.tags)
|
|
505
|
+
return value
|
|
420
506
|
|
|
421
507
|
|
|
422
508
|
def _manifest_value(
|
|
@@ -493,6 +579,13 @@ def _node_value(node: Node, profile: Profile) -> dict[str, JsonValue]:
|
|
|
493
579
|
"env": {**profile.environment, **node.environment},
|
|
494
580
|
}
|
|
495
581
|
_put_optional(value, "timeoutMinutes", node.timeout_minutes or profile.timeout_minutes)
|
|
582
|
+
if node.steps:
|
|
583
|
+
value.pop("step")
|
|
584
|
+
value["steps"] = [_step_value(step) for step in node.steps]
|
|
585
|
+
if node.permissions is not None:
|
|
586
|
+
value["permissions"] = dict(node.permissions)
|
|
587
|
+
if node.deployment_environment:
|
|
588
|
+
value["environment"] = dict(node.deployment_environment)
|
|
496
589
|
if isinstance(node.failing_label, LabelSpec):
|
|
497
590
|
value["failingLabel"] = _label_value(node.failing_label)
|
|
498
591
|
elif node.failing_label is False:
|
|
@@ -521,6 +614,23 @@ def _labels_value(graph: Graph) -> dict[str, JsonValue]:
|
|
|
521
614
|
return value
|
|
522
615
|
|
|
523
616
|
|
|
617
|
+
def pr_contract(graph: Graph) -> dict[str, JsonValue]:
|
|
618
|
+
"""Describe effective PR checks and governance independently of pin revisions."""
|
|
619
|
+
profiles = graph.expanded_profiles()
|
|
620
|
+
configuration = dict(graph.provider.values)
|
|
621
|
+
runtime = cast("dict[str, JsonValue]", configuration.pop("runtime"))
|
|
622
|
+
return {
|
|
623
|
+
"provider": graph.provider.name,
|
|
624
|
+
"configuration": configuration,
|
|
625
|
+
"runtimeRepository": _runtime_action(runtime.get("action"), "runtime").partition("@")[0],
|
|
626
|
+
"uploadArtifactRepository": _upload_artifact_action(runtime).partition("@")[0],
|
|
627
|
+
"nodes": [_node_value(node, profiles[node.profile]) for node in graph.nodes],
|
|
628
|
+
"profiles": {node.profile: _profile_value(profiles[node.profile]) for node in graph.nodes},
|
|
629
|
+
"labels": _labels_value(graph),
|
|
630
|
+
"administration": list(graph.administrator_roles),
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
524
634
|
def _label_value(label: LabelSpec) -> dict[str, JsonValue]:
|
|
525
635
|
return {
|
|
526
636
|
"name": label.name,
|
|
@@ -621,7 +731,7 @@ def _execution_job(
|
|
|
621
731
|
"permissions": dict(profile.permissions),
|
|
622
732
|
"steps": [
|
|
623
733
|
*(_workflow_step(step) for step in profile.setup),
|
|
624
|
-
command,
|
|
734
|
+
*([_workflow_step(step) for step in node.steps] if node.steps else [command]),
|
|
625
735
|
collect,
|
|
626
736
|
upload,
|
|
627
737
|
enforce,
|
|
@@ -629,6 +739,12 @@ def _execution_job(
|
|
|
629
739
|
}
|
|
630
740
|
if node.needs:
|
|
631
741
|
value["needs"] = list(node.needs)
|
|
742
|
+
if node.permissions is not None:
|
|
743
|
+
value["permissions"] = dict(node.permissions)
|
|
744
|
+
if node.deployment_environment:
|
|
745
|
+
value["environment"] = dict(node.deployment_environment)
|
|
746
|
+
if flow is not None and flow.is_release:
|
|
747
|
+
value["if"] = "startsWith(github.ref, 'refs/tags/')"
|
|
632
748
|
environment = _json_string_mapping(profile.environment)
|
|
633
749
|
environment.update(_json_string_mapping(node.environment))
|
|
634
750
|
if flow is not None:
|
|
@@ -664,6 +780,8 @@ def _collection_inputs(node: Node, graph_digest: str, flow: Flow | None) -> dict
|
|
|
664
780
|
"approval-files": str(node.policy.approvals.files).lower(),
|
|
665
781
|
"approval-node": str(node.policy.approvals.node).lower(),
|
|
666
782
|
}
|
|
783
|
+
if node.steps:
|
|
784
|
+
inputs["command-outcome"] = "${{ job.status }}"
|
|
667
785
|
if flow is not None:
|
|
668
786
|
inputs.update(
|
|
669
787
|
{
|
|
@@ -750,13 +868,13 @@ def _publication_workflow(runtime_action: str) -> dict[str, JsonValue]:
|
|
|
750
868
|
}
|
|
751
869
|
|
|
752
870
|
|
|
753
|
-
def _yaml_file(value: Mapping[str, JsonValue]) -> str:
|
|
871
|
+
def _yaml_file(value: Mapping[str, JsonValue], *, width: int = 1_000) -> str:
|
|
754
872
|
body = yaml.dump(
|
|
755
873
|
dict(value),
|
|
756
874
|
Dumper=WorkflowDumper,
|
|
757
875
|
default_flow_style=False,
|
|
758
876
|
sort_keys=False,
|
|
759
|
-
width=
|
|
877
|
+
width=width,
|
|
760
878
|
)
|
|
761
879
|
return GENERATED_HEADER + body
|
|
762
880
|
|
qg_github/dashboard.py
CHANGED
|
@@ -32,6 +32,7 @@ class DashboardRow:
|
|
|
32
32
|
metric: str
|
|
33
33
|
summary_url: str
|
|
34
34
|
logs_url: str
|
|
35
|
+
logs_label: str = "Logs"
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
@dataclass(frozen=True)
|
|
@@ -108,6 +109,8 @@ def final_dashboard(
|
|
|
108
109
|
graph: Graph,
|
|
109
110
|
results: Mapping[str, Result],
|
|
110
111
|
run: DashboardRun,
|
|
112
|
+
*,
|
|
113
|
+
job_urls: Mapping[str, str] | None = None,
|
|
111
114
|
) -> DashboardModel:
|
|
112
115
|
"""Build a final dashboard in declaration order."""
|
|
113
116
|
rows: list[DashboardRow] = []
|
|
@@ -122,7 +125,8 @@ def final_dashboard(
|
|
|
122
125
|
status,
|
|
123
126
|
dashboard_metric(result),
|
|
124
127
|
f"{run.url}#quality-graph-{node.id}",
|
|
125
|
-
run.url,
|
|
128
|
+
(job_urls or {}).get(node.id, run.url),
|
|
129
|
+
"Logs" if node.id in (job_urls or {}) else "Workflow run",
|
|
126
130
|
)
|
|
127
131
|
)
|
|
128
132
|
if result is not None and (result.controls or result.notes):
|
|
@@ -163,6 +167,7 @@ def pending_dashboard(
|
|
|
163
167
|
"—",
|
|
164
168
|
f"{run.url}#quality-graph-{node.id}",
|
|
165
169
|
run.url,
|
|
170
|
+
"Workflow run",
|
|
166
171
|
)
|
|
167
172
|
for node in graph.nodes
|
|
168
173
|
)
|
|
@@ -183,6 +188,7 @@ def live_dashboard(
|
|
|
183
188
|
run: DashboardRun,
|
|
184
189
|
*,
|
|
185
190
|
managed_labels: tuple[str, ...] = (),
|
|
191
|
+
job_urls: Mapping[str, str] | None = None,
|
|
186
192
|
) -> DashboardModel:
|
|
187
193
|
"""Build a live dashboard from authoritative GitHub job statuses."""
|
|
188
194
|
rows = tuple(
|
|
@@ -192,7 +198,8 @@ def live_dashboard(
|
|
|
192
198
|
statuses.get(node.node_id, ResultStatus.WAITING),
|
|
193
199
|
"—",
|
|
194
200
|
f"{run.url}#quality-graph-{node.node_id}",
|
|
195
|
-
run.url,
|
|
201
|
+
(job_urls or {}).get(node.node_id, run.url),
|
|
202
|
+
"Logs" if node.node_id in (job_urls or {}) else "Workflow run",
|
|
196
203
|
)
|
|
197
204
|
for node in nodes
|
|
198
205
|
)
|
|
@@ -252,7 +259,7 @@ def _render(model: DashboardModel) -> str:
|
|
|
252
259
|
]
|
|
253
260
|
lines.extend(
|
|
254
261
|
f"| {_table(row.title)} | {_status_icon(row.status)} {row.status.value} | "
|
|
255
|
-
f"{row.metric} | [Summary]({row.summary_url}) · [
|
|
262
|
+
f"{row.metric} | [Summary]({row.summary_url}) · [{row.logs_label}]({row.logs_url}) |"
|
|
256
263
|
for row in model.rows
|
|
257
264
|
)
|
|
258
265
|
if model.control_groups:
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Accept declaration migrations that preserve every trusted required check."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
from dataclasses import replace
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
from urllib.parse import quote
|
|
9
|
+
|
|
10
|
+
from qg_github.artifacts import ArtifactError, DeclarationMismatchError, download_results
|
|
11
|
+
from qg_github.compiler import compile_graph, pr_contract
|
|
12
|
+
from qg_github.github import GITHUB_PAGE_SIZE, GitHubError
|
|
13
|
+
from qg_github.presentation import pr_presentation_graph
|
|
14
|
+
from quality_graph_core.graph import Graph
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from qg_github.artifacts import ArtifactExpectation
|
|
18
|
+
from qg_github.github import GitHubPort
|
|
19
|
+
from quality_graph_core.result import JsonValue, Result
|
|
20
|
+
|
|
21
|
+
MAX_DECLARATION_BYTES = 1_048_576
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def read_pr_results(
|
|
25
|
+
port: GitHubPort, graph: Graph, expectation: ArtifactExpectation
|
|
26
|
+
) -> tuple[Graph, dict[str, Result]]:
|
|
27
|
+
"""Verify run provenance while preserving the trusted checks and governance."""
|
|
28
|
+
expectation = _execution_expectation(port, graph, expectation)
|
|
29
|
+
try:
|
|
30
|
+
return graph, download_results(port, expectation)
|
|
31
|
+
except DeclarationMismatchError as mismatch:
|
|
32
|
+
try:
|
|
33
|
+
head = _head_declaration(port, expectation.head_sha)
|
|
34
|
+
compiled = compile_graph(head)
|
|
35
|
+
projected = pr_presentation_graph(head)
|
|
36
|
+
except (GitHubError, ValueError, TypeError) as error:
|
|
37
|
+
raise mismatch from error
|
|
38
|
+
if (
|
|
39
|
+
projected is None
|
|
40
|
+
or compiled.graph_digest == expectation.graph_digest
|
|
41
|
+
or not _preserves_required_checks(graph, projected)
|
|
42
|
+
):
|
|
43
|
+
message = (
|
|
44
|
+
"PR declaration changes existing required checks or governance; "
|
|
45
|
+
"the trusted base declaration must be updated before these results can be accepted"
|
|
46
|
+
)
|
|
47
|
+
raise DeclarationMismatchError(message) from mismatch
|
|
48
|
+
current = replace(
|
|
49
|
+
expectation,
|
|
50
|
+
graph_digest=compiled.graph_digest,
|
|
51
|
+
node_ids=frozenset(node.id for node in projected.nodes),
|
|
52
|
+
flow_id=projected.flow_id,
|
|
53
|
+
operation_ids={
|
|
54
|
+
node.id: node.operation_id
|
|
55
|
+
for node in projected.nodes
|
|
56
|
+
if node.operation_id is not None
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
current = _execution_expectation(port, projected, current)
|
|
60
|
+
return projected, download_results(port, current)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _preserves_required_checks(base: Graph, head: Graph) -> bool:
|
|
64
|
+
"""Allow additional nodes only when existing contracts remain identical."""
|
|
65
|
+
required = {node.id for node in base.nodes}
|
|
66
|
+
existing = tuple(node for node in head.nodes if node.id in required)
|
|
67
|
+
return pr_contract(replace(head, nodes=existing)) == pr_contract(base)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _head_declaration(port: GitHubPort, sha: str) -> Graph:
|
|
71
|
+
value = port.request("GET", f"/contents/qg.yaml?ref={quote(sha, safe='')}")
|
|
72
|
+
if not isinstance(value, dict):
|
|
73
|
+
message = "head declaration response must be an object"
|
|
74
|
+
raise TypeError(message)
|
|
75
|
+
content = value.get("content")
|
|
76
|
+
if not isinstance(content, str):
|
|
77
|
+
message = "head declaration must be text"
|
|
78
|
+
raise TypeError(message)
|
|
79
|
+
decoded = base64.b64decode("".join(content.split()), validate=True)
|
|
80
|
+
if len(decoded) > MAX_DECLARATION_BYTES:
|
|
81
|
+
message = "head declaration exceeds the size limit"
|
|
82
|
+
raise ValueError(message)
|
|
83
|
+
return Graph.from_yaml(decoded.decode())
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _execution_expectation(
|
|
87
|
+
port: GitHubPort, graph: Graph, expectation: ArtifactExpectation
|
|
88
|
+
) -> ArtifactExpectation:
|
|
89
|
+
if expectation.run_attempt < 1:
|
|
90
|
+
message = "workflow attempt must be positive"
|
|
91
|
+
raise ArtifactError(message)
|
|
92
|
+
if expectation.run_attempt == 1:
|
|
93
|
+
return expectation
|
|
94
|
+
by_title = {node.title: node.id for node in graph.nodes}
|
|
95
|
+
attempts: dict[str, int] = {}
|
|
96
|
+
conclusions: dict[str, str] = {}
|
|
97
|
+
for attempt in range(expectation.run_attempt, 0, -1):
|
|
98
|
+
jobs = _attempt_jobs(port, expectation.workflow_run_id, attempt)
|
|
99
|
+
matched: set[str] = set()
|
|
100
|
+
for job in jobs:
|
|
101
|
+
name = job.get("name")
|
|
102
|
+
node_id = by_title.get(name) if isinstance(name, str) else None
|
|
103
|
+
if node_id is None or node_id in attempts:
|
|
104
|
+
continue
|
|
105
|
+
if node_id in matched:
|
|
106
|
+
message = f"ambiguous workflow jobs for node {node_id} attempt {attempt}"
|
|
107
|
+
raise ArtifactError(message)
|
|
108
|
+
matched.add(node_id)
|
|
109
|
+
conclusion = job.get("conclusion")
|
|
110
|
+
if (
|
|
111
|
+
job.get("run_id") != expectation.workflow_run_id
|
|
112
|
+
or job.get("run_attempt") != attempt
|
|
113
|
+
or job.get("status") != "completed"
|
|
114
|
+
or not isinstance(conclusion, str)
|
|
115
|
+
):
|
|
116
|
+
message = f"invalid workflow job evidence for node {node_id} attempt {attempt}"
|
|
117
|
+
raise ArtifactError(message)
|
|
118
|
+
conclusions[node_id] = conclusion
|
|
119
|
+
attempts.update(dict.fromkeys(matched, attempt))
|
|
120
|
+
if expectation.node_ids <= attempts.keys():
|
|
121
|
+
return replace(expectation, node_attempts=attempts, node_conclusions=conclusions)
|
|
122
|
+
message = "missing workflow job evidence for result artifacts"
|
|
123
|
+
raise ArtifactError(message)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _attempt_jobs(port: GitHubPort, run_id: int, attempt: int) -> list[dict[str, JsonValue]]:
|
|
127
|
+
jobs: list[dict[str, JsonValue]] = []
|
|
128
|
+
page = 1
|
|
129
|
+
while True:
|
|
130
|
+
response = port.request(
|
|
131
|
+
"GET",
|
|
132
|
+
f"/actions/runs/{run_id}/attempts/{attempt}/jobs?per_page={GITHUB_PAGE_SIZE}&page={page}",
|
|
133
|
+
)
|
|
134
|
+
values = response.get("jobs") if isinstance(response, dict) else None
|
|
135
|
+
if not isinstance(values, list) or any(not isinstance(job, dict) for job in values):
|
|
136
|
+
message = f"invalid workflow jobs response for attempt {attempt}"
|
|
137
|
+
raise ArtifactError(message)
|
|
138
|
+
jobs.extend(job for job in values if isinstance(job, dict))
|
|
139
|
+
if len(values) < GITHUB_PAGE_SIZE:
|
|
140
|
+
return jobs
|
|
141
|
+
page += 1
|
qg_github/github.py
CHANGED
|
@@ -95,7 +95,7 @@ class HttpGitHubPort:
|
|
|
95
95
|
raise GitHubError(method, path, response.status_code)
|
|
96
96
|
try:
|
|
97
97
|
return cast("JsonValue", response.json())
|
|
98
|
-
except json.JSONDecodeError as error:
|
|
98
|
+
except (json.JSONDecodeError, UnicodeDecodeError) as error:
|
|
99
99
|
message = f"GitHub {method} {path} returned invalid JSON"
|
|
100
100
|
raise RuntimeError(message) from error
|
|
101
101
|
|
qg_github/publication.py
CHANGED
|
@@ -6,11 +6,12 @@ import base64
|
|
|
6
6
|
import json
|
|
7
7
|
import time
|
|
8
8
|
import urllib.parse
|
|
9
|
+
from collections import Counter
|
|
9
10
|
from dataclasses import dataclass, replace
|
|
10
11
|
from typing import TYPE_CHECKING, cast
|
|
11
12
|
|
|
12
13
|
from qg_github.approvals import approval_ledger
|
|
13
|
-
from qg_github.artifacts import ArtifactError, ArtifactExpectation
|
|
14
|
+
from qg_github.artifacts import ArtifactError, ArtifactExpectation
|
|
14
15
|
from qg_github.comments import find_managed_comment, upsert_managed_comment
|
|
15
16
|
from qg_github.compiler import compile_graph
|
|
16
17
|
from qg_github.dashboard import (
|
|
@@ -23,12 +24,13 @@ from qg_github.dashboard import (
|
|
|
23
24
|
pending_dashboard,
|
|
24
25
|
render_dashboard,
|
|
25
26
|
)
|
|
27
|
+
from qg_github.declarations import read_pr_results
|
|
26
28
|
from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
|
|
27
29
|
from qg_github.labels import parse_label_state, reconcile_labels
|
|
28
30
|
from qg_github.presentation import pr_presentation_graph
|
|
29
31
|
from quality_graph_core.graph import Graph
|
|
30
32
|
from quality_graph_core.policy import effective_graph
|
|
31
|
-
from quality_graph_core.result import JsonValue, ResultStatus
|
|
33
|
+
from quality_graph_core.result import JsonValue, Provenance, ResultStatus
|
|
32
34
|
|
|
33
35
|
if TYPE_CHECKING:
|
|
34
36
|
from collections.abc import Callable, Mapping
|
|
@@ -200,18 +202,35 @@ def publish_workflow_jobs(
|
|
|
200
202
|
is_current: Callable[[], bool] = lambda: True,
|
|
201
203
|
) -> bool:
|
|
202
204
|
"""Merge authoritative job lifecycle into the single live dashboard."""
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
jobs = _workflow_jobs(port, run.id)
|
|
206
|
+
selected = _workflow_node_jobs(nodes, jobs, run)
|
|
207
|
+
statuses = {node_id: _workflow_job_status(job) for node_id, job in selected.items()}
|
|
208
|
+
current_attempt = run.attempt == 1 or any(
|
|
209
|
+
job.get("run_attempt") == run.attempt for job in selected.values()
|
|
210
|
+
)
|
|
211
|
+
terminal = (
|
|
212
|
+
current_attempt
|
|
213
|
+
and len(statuses) == len(nodes)
|
|
214
|
+
and all(
|
|
215
|
+
status not in {ResultStatus.WAITING, ResultStatus.IN_PROGRESS}
|
|
216
|
+
for status in statuses.values()
|
|
217
|
+
)
|
|
207
218
|
)
|
|
208
219
|
if terminal or not is_current():
|
|
209
220
|
return True
|
|
210
|
-
if len(statuses) < len(nodes) and _workflow_run_completed(
|
|
221
|
+
if (len(statuses) < len(nodes) or not current_attempt) and _workflow_run_completed(
|
|
222
|
+
port, run.id
|
|
223
|
+
):
|
|
211
224
|
return True
|
|
212
225
|
existing = find_managed_comment(port, number, DASHBOARD_MARKER)
|
|
213
226
|
previous_labels = parse_label_state(existing.body) if existing is not None else frozenset()
|
|
214
|
-
model = live_dashboard(
|
|
227
|
+
model = live_dashboard(
|
|
228
|
+
nodes,
|
|
229
|
+
statuses,
|
|
230
|
+
run,
|
|
231
|
+
managed_labels=tuple(sorted(previous_labels)),
|
|
232
|
+
job_urls=_workflow_job_urls(selected, run),
|
|
233
|
+
)
|
|
215
234
|
upsert_managed_comment(port, number, DASHBOARD_MARKER, render_dashboard(model))
|
|
216
235
|
return terminal
|
|
217
236
|
|
|
@@ -228,8 +247,7 @@ def _workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
|
|
|
228
247
|
response = _object(
|
|
229
248
|
port.request(
|
|
230
249
|
"GET",
|
|
231
|
-
f"/actions/runs/{run_id}/jobs?filter=
|
|
232
|
-
f"&per_page={GITHUB_PAGE_SIZE}&page={page}",
|
|
250
|
+
f"/actions/runs/{run_id}/jobs?filter=all&per_page={GITHUB_PAGE_SIZE}&page={page}",
|
|
233
251
|
),
|
|
234
252
|
"workflow jobs",
|
|
235
253
|
)
|
|
@@ -240,21 +258,11 @@ def _workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
|
|
|
240
258
|
page += 1
|
|
241
259
|
|
|
242
260
|
|
|
243
|
-
def
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)
|
|
248
|
-
"""Map declared nodes to authoritative GitHub workflow job statuses."""
|
|
249
|
-
by_title = {node.title: node.node_id for node in nodes}
|
|
250
|
-
statuses: dict[str, ResultStatus] = {}
|
|
251
|
-
for value in _workflow_jobs(port, run_id):
|
|
252
|
-
job = _object(value, "workflow job")
|
|
253
|
-
name = _string(job.get("name"), "workflow job name")
|
|
254
|
-
node_id = by_title.get(name)
|
|
255
|
-
if node_id is not None:
|
|
256
|
-
statuses[node_id] = _workflow_job_status(job)
|
|
257
|
-
return statuses
|
|
261
|
+
def _optional_workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
|
|
262
|
+
try:
|
|
263
|
+
return _workflow_jobs(port, run_id)
|
|
264
|
+
except (RuntimeError, TypeError):
|
|
265
|
+
return ()
|
|
258
266
|
|
|
259
267
|
|
|
260
268
|
def _workflow_job_status(job: Mapping[str, JsonValue]) -> ResultStatus:
|
|
@@ -292,25 +300,43 @@ def _completed_dashboard(
|
|
|
292
300
|
frozenset(node.id for node in graph.nodes),
|
|
293
301
|
graph.flow_id,
|
|
294
302
|
{node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
|
|
303
|
+
run_attempt=run.attempt,
|
|
295
304
|
)
|
|
296
305
|
try:
|
|
297
|
-
results =
|
|
306
|
+
graph, results = read_pr_results(port, graph, expectation)
|
|
298
307
|
except ArtifactError as error:
|
|
299
308
|
nodes = tuple(DashboardNode(node.id, node.title) for node in graph.nodes)
|
|
300
|
-
|
|
301
|
-
|
|
309
|
+
selected = _workflow_node_jobs(nodes, _optional_workflow_jobs(port, run.id), run)
|
|
310
|
+
statuses = {node_id: _workflow_job_status(job) for node_id, job in selected.items()}
|
|
311
|
+
fallback = live_dashboard(nodes, statuses, run, job_urls=_workflow_job_urls(selected, run))
|
|
302
312
|
return (
|
|
303
313
|
replace(
|
|
304
314
|
fallback,
|
|
305
315
|
status=ResultStatus.FAILED,
|
|
306
|
-
message=
|
|
316
|
+
message=(
|
|
317
|
+
f"The final dashboard could not be assembled: {error}. "
|
|
318
|
+
"Rows below show native job conclusions, not verified result artifacts."
|
|
319
|
+
),
|
|
307
320
|
),
|
|
308
321
|
None,
|
|
309
322
|
)
|
|
310
323
|
approvals = approval_ledger(port, pull.number)
|
|
311
324
|
effective = effective_graph(graph, results, approvals)
|
|
312
|
-
|
|
313
|
-
|
|
325
|
+
nodes = tuple(DashboardNode(node.id, node.title) for node in graph.nodes)
|
|
326
|
+
selected = _workflow_node_jobs(
|
|
327
|
+
nodes,
|
|
328
|
+
_optional_workflow_jobs(port, run.id),
|
|
329
|
+
run,
|
|
330
|
+
attempts={
|
|
331
|
+
node_id: result.provenance.run_attempt
|
|
332
|
+
for node_id, result in results.items()
|
|
333
|
+
if isinstance(result.provenance, Provenance)
|
|
334
|
+
},
|
|
335
|
+
)
|
|
336
|
+
model = final_dashboard(
|
|
337
|
+
graph, effective.results, run, job_urls=_workflow_job_urls(selected, run)
|
|
338
|
+
)
|
|
339
|
+
missing = {node.id for node in graph.nodes} - results.keys()
|
|
314
340
|
if missing:
|
|
315
341
|
model = replace(
|
|
316
342
|
model,
|
|
@@ -391,7 +417,7 @@ def _publish_check(port: GitHubPort, model: DashboardModel) -> None:
|
|
|
391
417
|
"head_sha": model.head_sha,
|
|
392
418
|
"external_id": external_id,
|
|
393
419
|
"status": "completed" if completed else "in_progress",
|
|
394
|
-
"details_url": next((row.
|
|
420
|
+
"details_url": next((row.summary_url.split("#", 1)[0] for row in model.rows), ""),
|
|
395
421
|
"output": {
|
|
396
422
|
"title": "Quality Graph",
|
|
397
423
|
"summary": model.message,
|
|
@@ -464,3 +490,69 @@ def _integer(value: JsonValue, context: str) -> int:
|
|
|
464
490
|
|
|
465
491
|
def _optional_integer(value: JsonValue, context: str) -> int | None:
|
|
466
492
|
return None if value is None else _integer(value, context)
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def _workflow_node_jobs(
|
|
496
|
+
nodes: tuple[DashboardNode, ...],
|
|
497
|
+
jobs: tuple[JsonValue, ...],
|
|
498
|
+
run: DashboardRun,
|
|
499
|
+
*,
|
|
500
|
+
attempts: Mapping[str, int] | None = None,
|
|
501
|
+
) -> dict[str, dict[str, JsonValue]]:
|
|
502
|
+
titles = Counter(node.title for node in nodes)
|
|
503
|
+
selected: dict[str, dict[str, JsonValue]] = {}
|
|
504
|
+
for node in nodes:
|
|
505
|
+
if titles[node.title] != 1:
|
|
506
|
+
continue
|
|
507
|
+
candidates = [
|
|
508
|
+
job
|
|
509
|
+
for job in jobs
|
|
510
|
+
if isinstance(job, dict)
|
|
511
|
+
and job.get("name") == node.title
|
|
512
|
+
and job.get("run_id", run.id) == run.id
|
|
513
|
+
and isinstance(attempt := job.get("run_attempt", run.attempt), int)
|
|
514
|
+
and not isinstance(attempt, bool)
|
|
515
|
+
and 0 < attempt <= run.attempt
|
|
516
|
+
and (attempts is None or attempt == attempts.get(node.node_id, run.attempt))
|
|
517
|
+
]
|
|
518
|
+
newest = max(
|
|
519
|
+
(
|
|
520
|
+
value
|
|
521
|
+
for job in candidates
|
|
522
|
+
if isinstance(value := job.get("run_attempt", run.attempt), int)
|
|
523
|
+
),
|
|
524
|
+
default=0,
|
|
525
|
+
)
|
|
526
|
+
matches = [job for job in candidates if job.get("run_attempt", run.attempt) == newest]
|
|
527
|
+
if len(matches) == 1:
|
|
528
|
+
selected[node.node_id] = matches[0]
|
|
529
|
+
return selected
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def _workflow_job_urls(
|
|
533
|
+
jobs: Mapping[str, Mapping[str, JsonValue]], run: DashboardRun
|
|
534
|
+
) -> dict[str, str]:
|
|
535
|
+
urls: dict[str, str] = {}
|
|
536
|
+
for node_id, job in jobs.items():
|
|
537
|
+
url = job.get("html_url")
|
|
538
|
+
identifier = job.get("id")
|
|
539
|
+
attempt = job.get("run_attempt")
|
|
540
|
+
if (
|
|
541
|
+
job.get("run_id") != run.id
|
|
542
|
+
or not isinstance(identifier, int)
|
|
543
|
+
or isinstance(identifier, bool)
|
|
544
|
+
or identifier <= 0
|
|
545
|
+
or not isinstance(attempt, int)
|
|
546
|
+
or isinstance(attempt, bool)
|
|
547
|
+
or not 0 < attempt <= run.attempt
|
|
548
|
+
or not isinstance(url, str)
|
|
549
|
+
):
|
|
550
|
+
continue
|
|
551
|
+
parsed = urllib.parse.urlsplit(url)
|
|
552
|
+
if (
|
|
553
|
+
parsed.scheme == "https"
|
|
554
|
+
and parsed.netloc
|
|
555
|
+
and not any(char in url for char in "\n\r()|")
|
|
556
|
+
):
|
|
557
|
+
urls[node_id] = url
|
|
558
|
+
return urls
|
qg_github/reporting.py
CHANGED
|
@@ -30,7 +30,7 @@ def render_job_summary(result: Result) -> str:
|
|
|
30
30
|
)
|
|
31
31
|
if result.findings:
|
|
32
32
|
lines.extend(("", "### Findings", ""))
|
|
33
|
-
lines.extend(
|
|
33
|
+
lines.extend(_finding_lines(result.findings[:MAX_SUMMARY_FINDINGS]))
|
|
34
34
|
omitted = len(result.findings) - MAX_SUMMARY_FINDINGS
|
|
35
35
|
if omitted > 0:
|
|
36
36
|
notice = f"_{omitted} additional findings are available in the result artifact._"
|
|
@@ -129,3 +129,12 @@ def _bounded(value: str, maximum: int) -> str:
|
|
|
129
129
|
if updated == omitted:
|
|
130
130
|
return value[:prefix] + notice
|
|
131
131
|
omitted = updated
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _finding_lines(findings: tuple[Finding, ...]) -> list[str]:
|
|
135
|
+
lines: list[str] = []
|
|
136
|
+
for group in dict.fromkeys(finding.group for finding in findings):
|
|
137
|
+
if group:
|
|
138
|
+
lines.extend((f"#### {html.escape(group)}", ""))
|
|
139
|
+
lines.extend(_finding_line(finding) for finding in findings if finding.group == group)
|
|
140
|
+
return lines
|
qg_github/runtime.py
CHANGED
|
@@ -97,8 +97,7 @@ def collect(request: CollectionRequest) -> Result:
|
|
|
97
97
|
"""Collect one command outcome through its selected adapter."""
|
|
98
98
|
try:
|
|
99
99
|
if request.adapter is AdapterKind.EXIT_CODE:
|
|
100
|
-
|
|
101
|
-
output = f"The declared command {state}."
|
|
100
|
+
output = ""
|
|
102
101
|
if request.report_path is not None:
|
|
103
102
|
try:
|
|
104
103
|
output = read_report(request.workspace, request.report_path).decode()
|
|
@@ -117,8 +116,10 @@ def collect(request: CollectionRequest) -> Result:
|
|
|
117
116
|
else:
|
|
118
117
|
result = adapt_junit(request.context, report)
|
|
119
118
|
return _with_policy_controls(request, result)
|
|
120
|
-
except AdapterError as error:
|
|
121
|
-
return _with_policy_controls(
|
|
119
|
+
except (AdapterError, OSError) as error:
|
|
120
|
+
return _with_policy_controls(
|
|
121
|
+
request, adapter_failure(request.context, AdapterError(str(error)))
|
|
122
|
+
)
|
|
122
123
|
|
|
123
124
|
|
|
124
125
|
def _with_policy_controls(request: CollectionRequest, result: Result) -> Result:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quality-graph-github
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: GitHub provider and Action runtime for Quality Graph
|
|
5
5
|
Project-URL: Homepage, https://quality-graph.xyz/
|
|
6
6
|
Project-URL: Documentation, https://quality-graph.xyz/
|
|
@@ -9,7 +9,7 @@ Requires-Python: >=3.12
|
|
|
9
9
|
Requires-Dist: httpx>=0.28.1
|
|
10
10
|
Requires-Dist: jinja2>=3.1.6
|
|
11
11
|
Requires-Dist: pyyaml>=6.0.2
|
|
12
|
-
Requires-Dist: quality-graph-core==0.
|
|
12
|
+
Requires-Dist: quality-graph-core==0.2.0
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
|
|
15
15
|
# Quality Graph GitHub Provider
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
qg_github/__init__.py,sha256=ud6DP1C10Vk64U_0T9SZ3f2YpMtJCzsbCGQ5BOtKhG4,106
|
|
2
|
+
qg_github/annotations.py,sha256=TwcYcY2g0tT__uVoSmEZuxFTkYrt3llf3mBt0VnG_ss,3217
|
|
3
|
+
qg_github/approvals.py,sha256=v4EDiSXVUgm93bvsH2ka6Olza4cPA8xSa2POf1ktOOM,6052
|
|
4
|
+
qg_github/artifacts.py,sha256=VBciKsppXcyXBPiWXjZaXqqfO87h1s9gF0Rz3v0IAUQ,9706
|
|
5
|
+
qg_github/commands.py,sha256=0bR1jKr6n7BlVDP_xd-EAO_e2aCuxeRQAxPhnIIn8kk,13221
|
|
6
|
+
qg_github/comments.py,sha256=8l6acI342hdsT6Cjx-4N406QU73Qv2wMFJsrylt06-8,3417
|
|
7
|
+
qg_github/compiler.py,sha256=wKLqdQP7AJ61wJqPWVq_V1xsxAGKiWs0dYK1LJzpLN4,33316
|
|
8
|
+
qg_github/controls.py,sha256=ePTADCzuTNNibNC9k7Q7uw6DNBB7YP7UYdMFPQfIDeM,2554
|
|
9
|
+
qg_github/dashboard.py,sha256=ZqAYOzSxTGLcaclz10JYJgwsYvAQCVv3AdXFMupfSDI,10269
|
|
10
|
+
qg_github/declarations.py,sha256=YIXGKjG6oileVdP8DFGtl3Ek48gqBSWoDQRbCkceEJA,6037
|
|
11
|
+
qg_github/github.py,sha256=smy9Wwv1GT6ttPBGTTsVGXhxnJO1VasgHW1yoJnx4Pw,7001
|
|
12
|
+
qg_github/labels.py,sha256=PT8MnIQZsu896dipMO2880KgUGVcyXH4IJNVQ1oG1zo,4720
|
|
13
|
+
qg_github/presentation.py,sha256=opUkhUfwKr1gUEYhg2L2X3KQqbjuZRtRhDx0qEokTI0,563
|
|
14
|
+
qg_github/provider.py,sha256=9vlC-YrcCYNNaz_CEjFmbQdqfnM8iCYQrcfBBUTn-_Q,578
|
|
15
|
+
qg_github/publication.py,sha256=Ihzdc32Ony_sJ7c0eOvZjeote9YZxkzfSLZV_P2xWnc,20195
|
|
16
|
+
qg_github/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
17
|
+
qg_github/reporting.py,sha256=fsNjoDArJZAS5M0KXf63-PXSDfFBsq0EhQ1gdS6x4K0,5169
|
|
18
|
+
qg_github/required_checks.py,sha256=6QgnNxAzdzr4kApERg8nL5tKmHjvlObgaH0xJx2mHX8,14312
|
|
19
|
+
qg_github/runtime.py,sha256=KPLdw6aJCKcwxWcke_JOX8qLOok1smclUMpWfM2wNu4,9263
|
|
20
|
+
quality_graph_github-0.2.0.dist-info/METADATA,sha256=lODfzIDyZk9Iti9f6kCp11JfarLcORlsHqHRETKWGwk,823
|
|
21
|
+
quality_graph_github-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
22
|
+
quality_graph_github-0.2.0.dist-info/entry_points.txt,sha256=cSP-mOVXpvGL9nCA7EEfxdrIafFMHwKJEq-wc7DOEyo,43
|
|
23
|
+
quality_graph_github-0.2.0.dist-info/RECORD,,
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
qg_github/__init__.py,sha256=ud6DP1C10Vk64U_0T9SZ3f2YpMtJCzsbCGQ5BOtKhG4,106
|
|
2
|
-
qg_github/annotations.py,sha256=TwcYcY2g0tT__uVoSmEZuxFTkYrt3llf3mBt0VnG_ss,3217
|
|
3
|
-
qg_github/approvals.py,sha256=v4EDiSXVUgm93bvsH2ka6Olza4cPA8xSa2POf1ktOOM,6052
|
|
4
|
-
qg_github/artifacts.py,sha256=uPYq8MuLrfr6KDeLMpVrHtkhicnt5T90jRl9qlYXV6o,8061
|
|
5
|
-
qg_github/commands.py,sha256=nvoPoFJuCrfidsTSPf-AB1aEQkx20Qo-qoNDmNMHgJY,13344
|
|
6
|
-
qg_github/comments.py,sha256=8l6acI342hdsT6Cjx-4N406QU73Qv2wMFJsrylt06-8,3417
|
|
7
|
-
qg_github/compiler.py,sha256=FTJKfQVy_XuStCDwkfdxVTkqEXLbiXws9eKDE3vRu6M,27890
|
|
8
|
-
qg_github/controls.py,sha256=ePTADCzuTNNibNC9k7Q7uw6DNBB7YP7UYdMFPQfIDeM,2554
|
|
9
|
-
qg_github/dashboard.py,sha256=ecAHs7ChHTpqjDJw5oVBnU04DbkHtsYwSFr8fu0iv-M,9881
|
|
10
|
-
qg_github/github.py,sha256=vx7_YhRd_XCCYpC_IvW0hk-tm-nmzGGcZONqQrx4f3A,6979
|
|
11
|
-
qg_github/labels.py,sha256=PT8MnIQZsu896dipMO2880KgUGVcyXH4IJNVQ1oG1zo,4720
|
|
12
|
-
qg_github/presentation.py,sha256=opUkhUfwKr1gUEYhg2L2X3KQqbjuZRtRhDx0qEokTI0,563
|
|
13
|
-
qg_github/provider.py,sha256=9vlC-YrcCYNNaz_CEjFmbQdqfnM8iCYQrcfBBUTn-_Q,578
|
|
14
|
-
qg_github/publication.py,sha256=am1tUkipO4ksDVNTpzjcAD8-Io0OvHFZmqmj4q1EL4Q,17104
|
|
15
|
-
qg_github/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
16
|
-
qg_github/reporting.py,sha256=1qo9TPJtf8OCKumRqmzax-nrlLo_2aqsWRaYB7ZuryI,4837
|
|
17
|
-
qg_github/required_checks.py,sha256=6QgnNxAzdzr4kApERg8nL5tKmHjvlObgaH0xJx2mHX8,14312
|
|
18
|
-
qg_github/runtime.py,sha256=S7miQLEZIEpegnlyt25hSnZdZGSfWFdG1JmNvhzZrVE,9321
|
|
19
|
-
quality_graph_github-0.1.9.dist-info/METADATA,sha256=8KPi0UsJRu6usyE42IopZhLZSvMuFZOsr5OJ9mOeS54,823
|
|
20
|
-
quality_graph_github-0.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
21
|
-
quality_graph_github-0.1.9.dist-info/entry_points.txt,sha256=cSP-mOVXpvGL9nCA7EEfxdrIafFMHwKJEq-wc7DOEyo,43
|
|
22
|
-
quality_graph_github-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
{quality_graph_github-0.1.9.dist-info → quality_graph_github-0.2.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|