quality-graph-github 0.1.9__tar.gz → 0.1.10__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.
Files changed (23) hide show
  1. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/PKG-INFO +2 -2
  2. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/pyproject.toml +2 -2
  3. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/artifacts.py +12 -2
  4. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/commands.py +3 -2
  5. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/compiler.py +134 -19
  6. quality_graph_github-0.1.10/src/qg_github/declarations.py +69 -0
  7. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/publication.py +3 -2
  8. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/.gitignore +0 -0
  9. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/README.md +0 -0
  10. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/__init__.py +0 -0
  11. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/annotations.py +0 -0
  12. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/approvals.py +0 -0
  13. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/comments.py +0 -0
  14. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/controls.py +0 -0
  15. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/dashboard.py +0 -0
  16. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/github.py +0 -0
  17. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/labels.py +0 -0
  18. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/presentation.py +0 -0
  19. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/provider.py +0 -0
  20. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/py.typed +0 -0
  21. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/reporting.py +0 -0
  22. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/required_checks.py +0 -0
  23. {quality_graph_github-0.1.9 → quality_graph_github-0.1.10}/src/qg_github/runtime.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-graph-github
3
- Version: 0.1.9
3
+ Version: 0.1.10
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.1.9
12
+ Requires-Dist: quality-graph-core==0.1.10
13
13
  Description-Content-Type: text/markdown
14
14
 
15
15
  # Quality Graph GitHub Provider
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-github"
7
- version = "0.1.9"
7
+ version = "0.1.10"
8
8
  description = "GitHub provider and Action runtime for Quality Graph"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -13,7 +13,7 @@ dependencies = [
13
13
  "httpx>=0.28.1",
14
14
  "jinja2>=3.1.6",
15
15
  "pyyaml>=6.0.2",
16
- "quality-graph-core==0.1.9",
16
+ "quality-graph-core==0.1.10",
17
17
  ]
18
18
 
19
19
  [project.urls]
@@ -30,12 +30,16 @@ 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
@@ -189,7 +193,13 @@ def _validate_result(
189
193
  provenance.flow_id,
190
194
  provenance.operation_id,
191
195
  )
192
- if result.node_id != descriptor.node_id or observed != expected:
196
+ if result.node_id != descriptor.node_id or observed[:5] != expected[:5]:
197
+ message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
198
+ raise ArtifactError(message)
199
+ if provenance.graph_digest != expectation.graph_digest:
200
+ message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
201
+ raise DeclarationMismatchError(message)
202
+ if observed[5:] != expected[5:]:
193
203
  message = f"artifact provenance does not match workflow metadata: {descriptor.id}"
194
204
  raise ArtifactError(message)
195
205
 
@@ -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, download_results
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
@@ -220,7 +221,7 @@ def _command_context(port: GitHubPort, number: int) -> CommandContext:
220
221
  graph.flow_id,
221
222
  {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
222
223
  )
223
- results = download_results(port, expectation)
224
+ graph, results = read_pr_results(port, graph, expectation)
224
225
  if any(result.provenance.run_attempt > attempt for result in results.values()):
225
226
  message = "result artifact attempt exceeds the latest workflow attempt"
226
227
  raise ValueError(message)
@@ -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
- _validate_step(node.step)
143
+ _validate_node_contract(node, graph.expanded_profiles()[node.profile], allow_write=False)
142
144
  for operation in graph.operations:
143
- _validate_step(operation.step)
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.trigger != "workflow-dispatch"
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,24 @@ 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:
239
251
  for branch in flow.branches:
240
252
  _default_branch(branch)
253
+ _validate_release_contract(graph, flow)
254
+ for node in graph.for_flow(flow.id).nodes:
255
+ _validate_node_contract(
256
+ node, graph.expanded_profiles()[node.profile], allow_write=flow.is_release
257
+ )
241
258
  if flow.presentation == "github-pr":
242
259
  titles = [node.title for node in graph.for_flow(flow.id).nodes]
243
260
  if len(set(titles)) != len(titles):
@@ -245,6 +262,44 @@ def _validate_explicit_flows(graph: Graph) -> None:
245
262
  raise ValueError(message)
246
263
 
247
264
 
265
+ def _validate_node_contract(node: Node, profile: Profile, *, allow_write: bool) -> None:
266
+ effective = (
267
+ replace(profile, permissions=node.permissions) if node.permissions is not None else profile
268
+ )
269
+ _validate_permissions(effective, allow_write=allow_write)
270
+ if node.deployment_environment and not allow_write:
271
+ message = "deployment environments are only allowed in release flows"
272
+ raise ValueError(message)
273
+ for step in node.steps or (node.step,):
274
+ _validate_step(step)
275
+
276
+
277
+ def _validate_release_contract(graph: Graph, flow: Flow) -> None:
278
+ for pattern in flow.tags:
279
+ if (
280
+ pattern.startswith("!")
281
+ or "${{" in pattern
282
+ or re.search(r"[\x00-\x20\x7f]", pattern)
283
+ or len(pattern) > MAX_BRANCH_NAME_LENGTH
284
+ ):
285
+ message = "release tag patterns must be literal nonnegative filters without whitespace"
286
+ raise ValueError(message)
287
+ if not flow.is_release or flow.execution_mode != "github-actions":
288
+ return
289
+ if any(node.checkpoint for node in flow.nodes):
290
+ message = (
291
+ "executable release checkpoints require a resumable provider; use design-only mode"
292
+ )
293
+ raise ValueError(message)
294
+ profiles = graph.expanded_profiles()
295
+ for node in graph.for_flow(flow.id).nodes:
296
+ profile = profiles[node.profile]
297
+ for step in (*profile.setup, *(node.steps or (node.step,))):
298
+ if step.uses is not None and re.fullmatch(r"[^@]+@[0-9a-f]{40}", step.uses) is None:
299
+ message = "executable release actions must be pinned to a 40-character commit"
300
+ raise ValueError(message)
301
+
302
+
248
303
  def _default_branch(value: JsonValue) -> str:
249
304
  branch = "main" if value is None else value
250
305
  if not isinstance(branch, str) or not 1 <= len(branch) <= MAX_BRANCH_NAME_LENGTH:
@@ -280,12 +335,12 @@ def _upload_artifact_action(runtime: Mapping[str, JsonValue]) -> str:
280
335
  return _runtime_action(runtime["upload-artifact-action"], "upload artifact")
281
336
 
282
337
 
283
- def _validate_permissions(profile: Profile) -> None:
338
+ def _validate_permissions(profile: Profile, *, allow_write: bool = False) -> None:
284
339
  for permission, access in profile.permissions.items():
285
340
  if permission not in PERMISSION_NAMES:
286
341
  message = f"unknown GitHub permission: {permission}"
287
342
  raise ValueError(message)
288
- if access not in {"none", "read"}:
343
+ if access not in ({"none", "read", "write"} if allow_write else {"none", "read"}):
289
344
  message = f"GitHub execution permission must be none or read: {permission}={access}"
290
345
  raise ValueError(message)
291
346
 
@@ -366,21 +421,44 @@ def _compile_flows(graph: Graph, configuration: _GitHubConfiguration) -> Generat
366
421
  manifest.update({"graphDigest": digest, "_generated": GENERATED_NOTICE})
367
422
  files: list[GeneratedFile] = []
368
423
  for flow in graph.flows:
369
- if flow.trigger == "workflow-dispatch":
424
+ if flow.execution_mode == "design-only":
370
425
  continue
371
426
  projection = EventProjection(flow.trigger, graph.for_flow(flow.id).nodes, flow.dependencies)
372
- workflow = _execution_workflow(graph, projection, configuration, digest, flow=flow)
427
+ flow_configuration = configuration
428
+ if (
429
+ flow.is_release
430
+ and configuration.upload_artifact_action == DEFAULT_UPLOAD_ARTIFACT_ACTION
431
+ ):
432
+ flow_configuration = replace(
433
+ configuration, upload_artifact_action=RELEASE_UPLOAD_ARTIFACT_ACTION
434
+ )
435
+ workflow = _execution_workflow(graph, projection, flow_configuration, digest, flow=flow)
373
436
  if flow.concurrency is not None:
374
437
  workflow["concurrency"] = {
375
438
  "group": f"quality-graph-{flow.concurrency}",
376
439
  "cancel-in-progress": False,
377
440
  }
378
- if flow.trigger == "push":
441
+ if flow.is_release:
442
+ workflow["name"] = "Release"
443
+ workflow["on"] = (
444
+ {"push": {"tags": list(flow.tags)}}
445
+ if flow.tags
446
+ else {"workflow_dispatch": {"inputs": dict(flow.inputs)}}
447
+ )
448
+ elif flow.trigger == "push":
379
449
  workflow["on"] = {"push": {"branches": list(flow.branches)}}
380
450
  else:
381
451
  workflow["on"] = {"pull_request": {"branches": [configuration.default_branch]}}
382
- path = EXECUTION_WORKFLOW if flow.trigger == "pull-request" else PUSH_WORKFLOW
383
- files.append(GeneratedFile(path, _yaml_file(workflow)))
452
+ path = (
453
+ RELEASE_WORKFLOW
454
+ if flow.is_release
455
+ else EXECUTION_WORKFLOW
456
+ if flow.trigger == "pull-request"
457
+ else PUSH_WORKFLOW
458
+ )
459
+ files.append(
460
+ GeneratedFile(path, _yaml_file(workflow, width=80 if flow.is_release else 1_000))
461
+ )
384
462
  if any(flow.presentation == "github-pr" for flow in graph.flows):
385
463
  files.append(
386
464
  GeneratedFile(
@@ -395,18 +473,20 @@ def _compile_flows(graph: Graph, configuration: _GitHubConfiguration) -> Generat
395
473
  for path in (EXECUTION_WORKFLOW, PUSH_WORKFLOW, PUBLICATION_WORKFLOW)
396
474
  if path not in paths
397
475
  )
398
- return GeneratedProject(digest, tuple(files), retired)
476
+ return GeneratedProject(
477
+ digest, tuple(files), retired, () if RELEASE_WORKFLOW in paths else (RELEASE_WORKFLOW,)
478
+ )
399
479
 
400
480
 
401
481
  def _flow_value(flow: Flow) -> dict[str, JsonValue]:
402
- return {
482
+ value: dict[str, JsonValue] = {
403
483
  "trigger": flow.trigger,
404
484
  "branches": list(flow.branches),
405
485
  "inputs": dict(flow.inputs),
406
486
  "dependencies": flow.dependencies.value,
407
487
  "presentation": flow.presentation,
408
488
  "concurrency": flow.concurrency,
409
- "execution": "design-only" if flow.trigger == "workflow-dispatch" else "github-actions",
489
+ "execution": flow.execution_mode,
410
490
  "nodes": [
411
491
  {
412
492
  "id": node.id,
@@ -417,6 +497,9 @@ def _flow_value(flow: Flow) -> dict[str, JsonValue]:
417
497
  for node in flow.nodes
418
498
  ],
419
499
  }
500
+ if flow.tags:
501
+ value["tags"] = list(flow.tags)
502
+ return value
420
503
 
421
504
 
422
505
  def _manifest_value(
@@ -493,6 +576,13 @@ def _node_value(node: Node, profile: Profile) -> dict[str, JsonValue]:
493
576
  "env": {**profile.environment, **node.environment},
494
577
  }
495
578
  _put_optional(value, "timeoutMinutes", node.timeout_minutes or profile.timeout_minutes)
579
+ if node.steps:
580
+ value.pop("step")
581
+ value["steps"] = [_step_value(step) for step in node.steps]
582
+ if node.permissions is not None:
583
+ value["permissions"] = dict(node.permissions)
584
+ if node.deployment_environment:
585
+ value["environment"] = dict(node.deployment_environment)
496
586
  if isinstance(node.failing_label, LabelSpec):
497
587
  value["failingLabel"] = _label_value(node.failing_label)
498
588
  elif node.failing_label is False:
@@ -521,6 +611,23 @@ def _labels_value(graph: Graph) -> dict[str, JsonValue]:
521
611
  return value
522
612
 
523
613
 
614
+ def pr_contract(graph: Graph) -> dict[str, JsonValue]:
615
+ """Describe effective PR checks and governance independently of pin revisions."""
616
+ profiles = graph.expanded_profiles()
617
+ configuration = dict(graph.provider.values)
618
+ runtime = cast("dict[str, JsonValue]", configuration.pop("runtime"))
619
+ return {
620
+ "provider": graph.provider.name,
621
+ "configuration": configuration,
622
+ "runtimeRepository": _runtime_action(runtime.get("action"), "runtime").partition("@")[0],
623
+ "uploadArtifactRepository": _upload_artifact_action(runtime).partition("@")[0],
624
+ "nodes": [_node_value(node, profiles[node.profile]) for node in graph.nodes],
625
+ "profiles": {node.profile: _profile_value(profiles[node.profile]) for node in graph.nodes},
626
+ "labels": _labels_value(graph),
627
+ "administration": list(graph.administrator_roles),
628
+ }
629
+
630
+
524
631
  def _label_value(label: LabelSpec) -> dict[str, JsonValue]:
525
632
  return {
526
633
  "name": label.name,
@@ -621,7 +728,7 @@ def _execution_job(
621
728
  "permissions": dict(profile.permissions),
622
729
  "steps": [
623
730
  *(_workflow_step(step) for step in profile.setup),
624
- command,
731
+ *([_workflow_step(step) for step in node.steps] if node.steps else [command]),
625
732
  collect,
626
733
  upload,
627
734
  enforce,
@@ -629,6 +736,12 @@ def _execution_job(
629
736
  }
630
737
  if node.needs:
631
738
  value["needs"] = list(node.needs)
739
+ if node.permissions is not None:
740
+ value["permissions"] = dict(node.permissions)
741
+ if node.deployment_environment:
742
+ value["environment"] = dict(node.deployment_environment)
743
+ if flow is not None and flow.is_release:
744
+ value["if"] = "startsWith(github.ref, 'refs/tags/')"
632
745
  environment = _json_string_mapping(profile.environment)
633
746
  environment.update(_json_string_mapping(node.environment))
634
747
  if flow is not None:
@@ -664,6 +777,8 @@ def _collection_inputs(node: Node, graph_digest: str, flow: Flow | None) -> dict
664
777
  "approval-files": str(node.policy.approvals.files).lower(),
665
778
  "approval-node": str(node.policy.approvals.node).lower(),
666
779
  }
780
+ if node.steps:
781
+ inputs["command-outcome"] = "${{ job.status }}"
667
782
  if flow is not None:
668
783
  inputs.update(
669
784
  {
@@ -750,13 +865,13 @@ def _publication_workflow(runtime_action: str) -> dict[str, JsonValue]:
750
865
  }
751
866
 
752
867
 
753
- def _yaml_file(value: Mapping[str, JsonValue]) -> str:
868
+ def _yaml_file(value: Mapping[str, JsonValue], *, width: int = 1_000) -> str:
754
869
  body = yaml.dump(
755
870
  dict(value),
756
871
  Dumper=WorkflowDumper,
757
872
  default_flow_style=False,
758
873
  sort_keys=False,
759
- width=1_000,
874
+ width=width,
760
875
  )
761
876
  return GENERATED_HEADER + body
762
877
 
@@ -0,0 +1,69 @@
1
+ """Accept declaration migrations only when the trusted PR contract is unchanged."""
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 DeclarationMismatchError, download_results
11
+ from qg_github.compiler import compile_graph, pr_contract
12
+ from qg_github.github import 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 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 and allow only semantically identical PR declaration migrations."""
28
+ try:
29
+ return graph, download_results(port, expectation)
30
+ except DeclarationMismatchError as mismatch:
31
+ try:
32
+ head = _head_declaration(port, expectation.head_sha)
33
+ compiled = compile_graph(head)
34
+ projected = pr_presentation_graph(head)
35
+ except (GitHubError, ValueError, TypeError) as error:
36
+ raise mismatch from error
37
+ if (
38
+ projected is None
39
+ or compiled.graph_digest == expectation.graph_digest
40
+ or pr_contract(projected) != pr_contract(graph)
41
+ ):
42
+ raise
43
+ current = replace(
44
+ expectation,
45
+ graph_digest=compiled.graph_digest,
46
+ flow_id=projected.flow_id,
47
+ operation_ids={
48
+ node.id: node.operation_id
49
+ for node in projected.nodes
50
+ if node.operation_id is not None
51
+ },
52
+ )
53
+ return projected, download_results(port, current)
54
+
55
+
56
+ def _head_declaration(port: GitHubPort, sha: str) -> Graph:
57
+ value = port.request("GET", f"/contents/qg.yaml?ref={quote(sha, safe='')}")
58
+ if not isinstance(value, dict):
59
+ message = "head declaration response must be an object"
60
+ raise TypeError(message)
61
+ content = value.get("content")
62
+ if not isinstance(content, str):
63
+ message = "head declaration must be text"
64
+ raise TypeError(message)
65
+ decoded = base64.b64decode("".join(content.split()), validate=True)
66
+ if len(decoded) > MAX_DECLARATION_BYTES:
67
+ message = "head declaration exceeds the size limit"
68
+ raise ValueError(message)
69
+ return Graph.from_yaml(decoded.decode())
@@ -10,7 +10,7 @@ from dataclasses import dataclass, replace
10
10
  from typing import TYPE_CHECKING, cast
11
11
 
12
12
  from qg_github.approvals import approval_ledger
13
- from qg_github.artifacts import ArtifactError, ArtifactExpectation, download_results
13
+ from qg_github.artifacts import ArtifactError, ArtifactExpectation
14
14
  from qg_github.comments import find_managed_comment, upsert_managed_comment
15
15
  from qg_github.compiler import compile_graph
16
16
  from qg_github.dashboard import (
@@ -23,6 +23,7 @@ from qg_github.dashboard import (
23
23
  pending_dashboard,
24
24
  render_dashboard,
25
25
  )
26
+ from qg_github.declarations import read_pr_results
26
27
  from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
27
28
  from qg_github.labels import parse_label_state, reconcile_labels
28
29
  from qg_github.presentation import pr_presentation_graph
@@ -294,7 +295,7 @@ def _completed_dashboard(
294
295
  {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
295
296
  )
296
297
  try:
297
- results = download_results(port, expectation)
298
+ graph, results = read_pr_results(port, graph, expectation)
298
299
  except ArtifactError as error:
299
300
  nodes = tuple(DashboardNode(node.id, node.title) for node in graph.nodes)
300
301
  statuses = _workflow_node_statuses(port, nodes, run.id)