Repository navigation
Expand file tree
/
Copy pathrequired_workflows.py
More file actions
68 lines (54 loc) · 2.39 KB
/
Copy pathrequired_workflows.py
File metadata and controls
68 lines (54 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Required-workflows check.
For each repo, compare the set of workflow filenames present under
``.github/workflows/`` against the per-type ``required_workflows`` list
resolved from ``standards/drift-checker.config.json``.
A workflow that is required but absent -> ``error``.
Extra or unexpected workflows are never flagged; this check is presence-
only and never emits "this workflow should not be here" findings.
Policy lives entirely in config (``types.<repo-type>.required_workflows``),
merged via the additive-strictness tier logic in ``DriftConfig.resolve``.
No workflow names are hardcoded here.
Edge cases:
* ``repo_type == "unknown"`` -> silent; we cannot know what is required.
* ``required_workflows`` empty (absent from config) -> silent; permissive
by default, same posture as ``required-refs``.
* ``skip_checks`` contains this check's name -> silent for that repo.
* No per-file pragma support; suppression is via ``skip_checks`` in
config, because the check operates at repo level (no file to annotate
when the workflow is absent).
"""
from __future__ import annotations
from typing import Iterable, List
from ..types import Finding, RepoSnapshot
NAME = "required-workflows"
class RequiredWorkflowsCheck:
name: str = NAME
def run(self, snapshot: RepoSnapshot) -> Iterable[Finding]:
if NAME in snapshot.config.skip_checks:
return ()
# Cannot determine requirements for unknown repo types.
if snapshot.repo_type == "unknown":
return ()
required = snapshot.config.required_workflows
if not required:
return ()
out: List[Finding] = []
for workflow in sorted(required):
if workflow not in snapshot.present_workflows:
out.append(
Finding(
repo=snapshot.slug,
file=None,
check=NAME,
severity="error",
message=(
f"required workflow '{workflow}' is absent"
f" (required for {snapshot.repo_type} repos)"
),
suggested_fix=(
f"add .github/workflows/{workflow} following"
f" the scaffold template or ci-cd.md"
),
)
)
return out