File size: 3,961 Bytes
e965652
 
 
 
 
 
 
 
 
 
21ff762
e965652
 
 
 
21ff762
e965652
 
 
21ff762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e965652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21ff762
 
e965652
 
 
 
916f576
 
 
 
e965652
 
 
 
916f576
 
 
 
e965652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916f576
e965652
 
 
 
 
 
916f576
e965652
 
 
 
 
 
 
 
 
21ff762
 
 
 
 
 
 
e965652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Validate GitHub Actions dependency results for the stable CI check."""

from __future__ import annotations

import json
import os
from typing import Any

CHEAP_PR_SKIPPABLE_JOBS = {
    "clean-host-contract",
    "contract-compat",
    "e2e-canary",
    "no-test-no-merge",
    "package-build",
    "package-smoke",
    "similarity-integration",
    "static",
    "unit-linux",
}
REQUIRED_JOBS = {
    "browser-security",
    "classify",
    "clean-host-contract",
    "contract-compat",
    "docs-check",
    "e2e-canary",
    "graph-check",
    "no-test-no-merge",
    "package-build",
    "package-smoke",
    "similarity-integration",
    "static",
    "test",
    "unit-linux",
}


def _job_output(

    needs: dict[str, dict[str, Any]],

    job_name: str,

    output_name: str,

) -> str | None:
    outputs = needs.get(job_name, {}).get("outputs", {})
    if not isinstance(outputs, dict):
        return None
    output = outputs.get(output_name)
    return output if isinstance(output, str) else None


def failed_required_jobs(

    needs: dict[str, dict[str, Any]],

    *,

    event_name: str,

) -> dict[str, str | None]:
    failures: dict[str, str | None] = {}
    for name in sorted(REQUIRED_JOBS - set(needs)):
        failures[name] = "missing"
    docs_only_pr = (
        event_name == "pull_request"
        and _job_output(needs, "classify", "docs_only") == "true"
    )
    docs_changed_pr = (
        event_name == "pull_request"
        and _job_output(needs, "classify", "docs_changed") == "true"
    )
    graph_only_pr = (
        event_name == "pull_request"
        and _job_output(needs, "classify", "graph_only") == "true"
    )
    graph_artifact_changed_pr = (
        event_name == "pull_request"
        and _job_output(needs, "classify", "graph_artifact_changed") == "true"
    )
    cheap_pr = docs_only_pr or graph_only_pr
    for name, details in sorted(needs.items()):
        result = details.get("result")
        if result == "success":
            continue
        if (
            event_name != "pull_request"
            and name in {"docs-check", "graph-check", "no-test-no-merge"}
            and result == "skipped"
        ):
            continue
        if cheap_pr and name in CHEAP_PR_SKIPPABLE_JOBS and result == "skipped":
            continue
        if (
            event_name == "pull_request"
            and name == "docs-check"
            and result == "skipped"
            and not docs_changed_pr
        ):
            continue
        if (
            event_name == "pull_request"
            and name == "graph-check"
            and result == "skipped"
            and not graph_artifact_changed_pr
        ):
            continue
        if (
            event_name == "pull_request"
            and name == "browser-security"
            and result == "skipped"
            and _job_output(needs, "classify", "browser_changed") == "false"
        ):
            continue
        if (
            event_name == "pull_request"
            and name == "similarity-integration"
            and result == "skipped"
            and _job_output(needs, "classify", "similarity_changed") == "false"
        ):
            continue
        if event_name == "pull_request" and name == "test" and result == "skipped":
            continue
        failures[name] = result
    return failures


def main() -> int:
    event_name = os.environ["EVENT_NAME"]
    needs = json.loads(os.environ["NEEDS_JSON"])
    bad = failed_required_jobs(needs, event_name=event_name)

    for name, details in sorted(needs.items()):
        print(f"{name}: {details.get('result')}")

    if bad:
        for name, result in bad.items():
            print(f"::error::{name} finished with {result}")
        return 1
    return 0


if __name__ == "__main__":
    raise SystemExit(main())