quality-graph-gitlab 0.2.0__tar.gz → 0.2.1__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.
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/PKG-INFO +2 -2
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/pyproject.toml +2 -2
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/__init__.py +2 -1
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/api.py +9 -14
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/compiler.py +50 -48
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/runtime.py +4 -23
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/.gitignore +0 -0
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/README.md +0 -0
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/admission.py +0 -0
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/markers.py +0 -0
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/publication.py +0 -0
- {quality_graph_gitlab-0.2.0 → quality_graph_gitlab-0.2.1}/src/qg_gitlab/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quality-graph-gitlab
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: GitLab provider and CI 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: anyio>=4.0
|
|
10
10
|
Requires-Dist: httpx>=0.28.1
|
|
11
11
|
Requires-Dist: pyyaml>=6.0.2
|
|
12
|
-
Requires-Dist: quality-graph-core==0.2.
|
|
12
|
+
Requires-Dist: quality-graph-core==0.2.1
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
|
|
15
15
|
# Quality Graph GitLab
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "quality-graph-gitlab"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "GitLab provider and CI runtime for Quality Graph"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -13,7 +13,7 @@ dependencies = [
|
|
|
13
13
|
"anyio>=4.0",
|
|
14
14
|
"httpx>=0.28.1",
|
|
15
15
|
"pyyaml>=6.0.2",
|
|
16
|
-
"quality-graph-core==0.2.
|
|
16
|
+
"quality-graph-core==0.2.1",
|
|
17
17
|
]
|
|
18
18
|
|
|
19
19
|
[project.urls]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Expose the independently installed GitLab provider."""
|
|
2
2
|
|
|
3
|
-
from qg_gitlab.compiler import compile_graph, starter
|
|
3
|
+
from qg_gitlab.compiler import CAPABILITIES, compile_graph, starter
|
|
4
4
|
from quality_graph_core.graph import Graph
|
|
5
5
|
from quality_graph_core.provider import GeneratedProject
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ class GitLabProvider:
|
|
|
9
9
|
"""Own GitLab compilation and provider-native initialization."""
|
|
10
10
|
|
|
11
11
|
name = "gitlab"
|
|
12
|
+
capabilities = CAPABILITIES
|
|
12
13
|
|
|
13
14
|
def generate(self, graph: Graph) -> GeneratedProject:
|
|
14
15
|
"""Return the complete deterministic GitLab project."""
|
|
@@ -12,6 +12,8 @@ from typing import TYPE_CHECKING, Self, cast
|
|
|
12
12
|
|
|
13
13
|
import httpx
|
|
14
14
|
|
|
15
|
+
from quality_graph_core.json_values import JSON
|
|
16
|
+
|
|
15
17
|
if TYPE_CHECKING:
|
|
16
18
|
from collections.abc import Iterator, Mapping
|
|
17
19
|
from types import TracebackType
|
|
@@ -26,32 +28,25 @@ RETRY_STATUSES = {409, 429, 502, 503, 504}
|
|
|
26
28
|
|
|
27
29
|
def object_value(value: JsonValue, context: str) -> dict[str, JsonValue]:
|
|
28
30
|
"""Require a JSON object at an external interface."""
|
|
29
|
-
|
|
30
|
-
message = f"{context} must be an object"
|
|
31
|
-
raise TypeError(message)
|
|
32
|
-
return value
|
|
31
|
+
return JSON.object(value, context)
|
|
33
32
|
|
|
34
33
|
|
|
35
34
|
def integer(value: JsonValue, context: str) -> int:
|
|
36
35
|
"""Require a positive integer identity without coercion."""
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
raise TypeError(message)
|
|
40
|
-
if value < 1:
|
|
36
|
+
result = JSON.integer(value, context)
|
|
37
|
+
if result < 1:
|
|
41
38
|
message = f"{context} must be positive"
|
|
42
39
|
raise ValueError(message)
|
|
43
|
-
return
|
|
40
|
+
return result
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
def string(value: JsonValue, context: str) -> str:
|
|
47
44
|
"""Require a nonempty string at an external interface."""
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
raise TypeError(message)
|
|
51
|
-
if not value:
|
|
45
|
+
result = JSON.string(value, context)
|
|
46
|
+
if not result:
|
|
52
47
|
message = f"{context} must not be empty"
|
|
53
48
|
raise ValueError(message)
|
|
54
|
-
return
|
|
49
|
+
return result
|
|
55
50
|
|
|
56
51
|
|
|
57
52
|
def server_url(value: str) -> str:
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import hashlib
|
|
6
6
|
import json
|
|
7
|
-
from dataclasses import asdict
|
|
7
|
+
from dataclasses import asdict
|
|
8
8
|
from importlib.metadata import version
|
|
9
9
|
from pathlib import PurePosixPath
|
|
10
10
|
from typing import TYPE_CHECKING
|
|
@@ -12,11 +12,11 @@ from typing import TYPE_CHECKING
|
|
|
12
12
|
import yaml
|
|
13
13
|
|
|
14
14
|
from qg_gitlab.api import integer, server_url, string
|
|
15
|
-
from quality_graph_core.
|
|
16
|
-
from quality_graph_core.provider import GeneratedFile, GeneratedProject
|
|
15
|
+
from quality_graph_core.projection import project_event
|
|
16
|
+
from quality_graph_core.provider import GeneratedFile, GeneratedProject, ProviderCapabilities
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
|
-
from quality_graph_core.graph import Node, Profile
|
|
19
|
+
from quality_graph_core.graph import Graph, Node, Profile
|
|
20
20
|
from quality_graph_core.result import JsonValue
|
|
21
21
|
|
|
22
22
|
RUNTIME_VERSION = version("quality-graph-gitlab")
|
|
@@ -27,6 +27,16 @@ INSTALL_RUNTIME = (
|
|
|
27
27
|
f"python -m pip install --disable-pip-version-check quality-graph-gitlab=={RUNTIME_VERSION}"
|
|
28
28
|
)
|
|
29
29
|
|
|
30
|
+
CAPABILITIES = ProviderCapabilities(
|
|
31
|
+
events=frozenset({"pull-request", "push", "workflow-dispatch"}),
|
|
32
|
+
presentations={
|
|
33
|
+
"none": frozenset({"pull-request", "push", "workflow-dispatch"}),
|
|
34
|
+
"gitlab-mr": frozenset({"pull-request"}),
|
|
35
|
+
"release": frozenset({"push", "workflow-dispatch"}),
|
|
36
|
+
},
|
|
37
|
+
execution_modes=frozenset({"design-only", "github-actions"}),
|
|
38
|
+
)
|
|
39
|
+
|
|
30
40
|
|
|
31
41
|
def configuration(graph: Graph) -> dict[str, JsonValue]:
|
|
32
42
|
"""Validate GitLab settings independently of every other provider."""
|
|
@@ -108,24 +118,14 @@ def execution_graphs(graph: Graph) -> tuple[tuple[str, str, Graph], ...]:
|
|
|
108
118
|
)
|
|
109
119
|
raise ValueError(message)
|
|
110
120
|
events.add(flow.trigger)
|
|
111
|
-
|
|
121
|
+
projected = project_event(graph, flow.trigger, flow_id=flow.id)
|
|
122
|
+
result.append((flow.id, flow.trigger, projected))
|
|
112
123
|
return tuple(result)
|
|
113
124
|
result = []
|
|
114
125
|
for event, flow_id in (("pull-request", "mr"), ("push", "push")):
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
selected = tuple(
|
|
119
|
-
replace(
|
|
120
|
-
node,
|
|
121
|
-
needs=tuple(need for need in node.needs if need in membership)
|
|
122
|
-
if dependencies is DependencyPolicy.GRAPH
|
|
123
|
-
else (),
|
|
124
|
-
)
|
|
125
|
-
for node in selected
|
|
126
|
-
)
|
|
127
|
-
if selected:
|
|
128
|
-
result.append((flow_id, event, replace(graph, nodes=selected)))
|
|
126
|
+
projected = project_event(graph, event)
|
|
127
|
+
if projected.nodes:
|
|
128
|
+
result.append((flow_id, event, projected))
|
|
129
129
|
return tuple(result)
|
|
130
130
|
|
|
131
131
|
|
|
@@ -165,7 +165,7 @@ def _validate_node(node: Node, profile: Profile) -> None:
|
|
|
165
165
|
"GitLab quality jobs do not accept deployment permissions or service escape hatches"
|
|
166
166
|
)
|
|
167
167
|
raise ValueError(message)
|
|
168
|
-
if profile.permissions not in ({}, {"contents": "read"}):
|
|
168
|
+
if profile.permissions not in (None, {}, {"contents": "read"}):
|
|
169
169
|
message = "GitHub permissions cannot be applied to GitLab quality jobs"
|
|
170
170
|
raise ValueError(message)
|
|
171
171
|
if profile.runner not in {None, "ubuntu-latest"}:
|
|
@@ -204,11 +204,32 @@ def _execution_job(
|
|
|
204
204
|
return item
|
|
205
205
|
|
|
206
206
|
|
|
207
|
+
def _execution_rule(graph: Graph, flow_id: str, event: str, settings: dict[str, JsonValue]) -> str:
|
|
208
|
+
rule = (
|
|
209
|
+
'$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
210
|
+
if event == "pull-request"
|
|
211
|
+
else '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH'
|
|
212
|
+
)
|
|
213
|
+
if event == "pull-request":
|
|
214
|
+
target_branch = json.dumps(settings["default-branch"], ensure_ascii=False)
|
|
215
|
+
rule += f" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == {target_branch}"
|
|
216
|
+
if graph.flows and event == "push":
|
|
217
|
+
declared = next(flow for flow in graph.flows if flow.id == flow_id)
|
|
218
|
+
if declared.branches:
|
|
219
|
+
choices = " || ".join(
|
|
220
|
+
f"$CI_COMMIT_BRANCH == {json.dumps(branch, ensure_ascii=False)}"
|
|
221
|
+
for branch in declared.branches
|
|
222
|
+
)
|
|
223
|
+
rule = f"({rule}) && ({choices})"
|
|
224
|
+
return rule
|
|
225
|
+
|
|
226
|
+
|
|
207
227
|
def compile_graph(graph: Graph) -> GeneratedProject:
|
|
208
228
|
"""Generate CI, its execution manifest and a trusted publisher template."""
|
|
209
229
|
settings = configuration(graph)
|
|
210
230
|
digest = graph_digest(graph)
|
|
211
|
-
|
|
231
|
+
CAPABILITIES.validate(graph)
|
|
232
|
+
profiles = graph.expanded_profiles(CAPABILITIES.profile_defaults)
|
|
212
233
|
flows = execution_graphs(graph)
|
|
213
234
|
if not flows:
|
|
214
235
|
message = "GitLab requires at least one executable MR or branch flow"
|
|
@@ -218,21 +239,14 @@ def compile_graph(graph: Graph) -> GeneratedProject:
|
|
|
218
239
|
):
|
|
219
240
|
message = "GitLab MR publication requires a declared publisher-user-id"
|
|
220
241
|
raise ValueError(message)
|
|
242
|
+
rules: list[JsonValue] = [
|
|
243
|
+
{"if": _execution_rule(graph, flow_id, event, settings)} for flow_id, event, _ in flows
|
|
244
|
+
]
|
|
245
|
+
rules.append({"when": "never"})
|
|
221
246
|
workflow: dict[str, JsonValue] = {
|
|
222
247
|
"workflow": {
|
|
223
248
|
"auto_cancel": {"on_new_commit": "interruptible"},
|
|
224
|
-
"rules":
|
|
225
|
-
{"if": '$CI_PIPELINE_SOURCE == "merge_request_event"'},
|
|
226
|
-
{
|
|
227
|
-
"if": (
|
|
228
|
-
'$CI_PIPELINE_SOURCE == "push" && '
|
|
229
|
-
"$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
|
|
230
|
-
),
|
|
231
|
-
"when": "never",
|
|
232
|
-
},
|
|
233
|
-
{"if": '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH'},
|
|
234
|
-
{"when": "never"},
|
|
235
|
-
],
|
|
249
|
+
"rules": rules,
|
|
236
250
|
},
|
|
237
251
|
"stages": ["quality"],
|
|
238
252
|
"default": {
|
|
@@ -243,21 +257,7 @@ def compile_graph(graph: Graph) -> GeneratedProject:
|
|
|
243
257
|
}
|
|
244
258
|
manifests: list[JsonValue] = []
|
|
245
259
|
for flow_id, event, projected in flows:
|
|
246
|
-
rule = (
|
|
247
|
-
'$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
248
|
-
if event == "pull-request"
|
|
249
|
-
else '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH'
|
|
250
|
-
)
|
|
251
|
-
if event == "pull-request":
|
|
252
|
-
target_branch = json.dumps(settings["default-branch"])
|
|
253
|
-
rule += f" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == {target_branch}"
|
|
254
|
-
if graph.flows and event == "push":
|
|
255
|
-
declared = next(flow for flow in graph.flows if flow.id == flow_id)
|
|
256
|
-
if declared.branches:
|
|
257
|
-
choices = " || ".join(
|
|
258
|
-
f"$CI_COMMIT_BRANCH == {json.dumps(branch)}" for branch in declared.branches
|
|
259
|
-
)
|
|
260
|
-
rule = f"({rule}) && ({choices})"
|
|
260
|
+
rule = _execution_rule(graph, flow_id, event, settings)
|
|
261
261
|
for node in projected.nodes:
|
|
262
262
|
profile = profiles[node.profile]
|
|
263
263
|
_validate_node(node, profile)
|
|
@@ -317,6 +317,7 @@ def compile_graph(graph: Graph) -> GeneratedProject:
|
|
|
317
317
|
PurePosixPath(string(settings["ci-path"], "CI path")),
|
|
318
318
|
GENERATED_HEADER
|
|
319
319
|
+ yaml.safe_dump(workflow, sort_keys=False, width=80, explicit_start=True),
|
|
320
|
+
overwrite_marker=GENERATED_HEADER,
|
|
320
321
|
),
|
|
321
322
|
GeneratedFile(
|
|
322
323
|
PurePosixPath(".qg/gitlab.json"), json.dumps(manifest, indent=2, sort_keys=True) + "\n"
|
|
@@ -325,6 +326,7 @@ def compile_graph(graph: Graph) -> GeneratedProject:
|
|
|
325
326
|
PurePosixPath(".qg/gitlab-publisher.yml"),
|
|
326
327
|
GENERATED_HEADER
|
|
327
328
|
+ yaml.safe_dump(publisher, sort_keys=False, width=80, explicit_start=True),
|
|
329
|
+
overwrite_marker=GENERATED_HEADER,
|
|
328
330
|
),
|
|
329
331
|
)
|
|
330
332
|
return GeneratedProject(digest, files)
|
|
@@ -23,17 +23,9 @@ from qg_gitlab.compiler import (
|
|
|
23
23
|
)
|
|
24
24
|
from qg_gitlab.markers import execution_marker, gate_marker
|
|
25
25
|
from qg_gitlab.publication import publish_from_environment
|
|
26
|
-
from quality_graph_core.adapters import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
adapt_exit,
|
|
30
|
-
adapt_junit,
|
|
31
|
-
adapt_native,
|
|
32
|
-
adapt_sarif,
|
|
33
|
-
adapter_failure,
|
|
34
|
-
read_report,
|
|
35
|
-
)
|
|
36
|
-
from quality_graph_core.graph import AdapterKind, Graph
|
|
26
|
+
from quality_graph_core.adapters import AdapterContext
|
|
27
|
+
from quality_graph_core.collection import collect_report
|
|
28
|
+
from quality_graph_core.graph import Graph
|
|
37
29
|
from quality_graph_core.result import FailureKind, GitLabProvenance, Result
|
|
38
30
|
|
|
39
31
|
if TYPE_CHECKING:
|
|
@@ -110,18 +102,7 @@ def run_step(step: Step, root: Path, environment: Mapping[str, str]) -> bool:
|
|
|
110
102
|
|
|
111
103
|
def collect(context: AdapterContext, node: Node, root: Path) -> Result:
|
|
112
104
|
"""Adapt the existing command execution without rerunning any checks."""
|
|
113
|
-
|
|
114
|
-
return adapt_exit(context)
|
|
115
|
-
try:
|
|
116
|
-
report = read_report(root, node.result.path or "")
|
|
117
|
-
adapters = {
|
|
118
|
-
AdapterKind.NATIVE: adapt_native,
|
|
119
|
-
AdapterKind.JUNIT: adapt_junit,
|
|
120
|
-
AdapterKind.SARIF: adapt_sarif,
|
|
121
|
-
}
|
|
122
|
-
return adapters[node.result.kind](context, report)
|
|
123
|
-
except (AdapterError, OSError, ValueError) as error:
|
|
124
|
-
return adapter_failure(context, AdapterError(str(error)))
|
|
105
|
+
return collect_report(context, node.result.kind, root, node.result.path)
|
|
125
106
|
|
|
126
107
|
|
|
127
108
|
def execute(root: Path, flow_id: str, node_id: str) -> int:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|