pytorch

Форк
0
/
ensure_actions_will_cancel.py 
75 строк · 2.5 Кб
1
#!/usr/bin/env python3
2

3
import sys
4

5
from pathlib import Path
6

7
import yaml
8

9

10
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
11
WORKFLOWS = REPO_ROOT / ".github" / "workflows"
12
EXPECTED_GROUP_PREFIX = (
13
    "${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}"
14
)
15
EXPECTED_GROUP = (
16
    EXPECTED_GROUP_PREFIX + "-${{ github.event_name == 'workflow_dispatch' }}"
17
)
18

19

20
def should_check(filename: Path) -> bool:
21
    with open(filename) as f:
22
        content = f.read()
23

24
    data = yaml.safe_load(content)
25
    on = data.get("on", data.get(True, {}))
26
    return "pull_request" in on
27

28

29
if __name__ == "__main__":
30
    errors_found = False
31
    files = [f for f in WORKFLOWS.glob("*.yml") if should_check(f)]
32
    names = set()
33
    for filename in files:
34
        with open(filename) as f:
35
            data = yaml.safe_load(f)
36

37
        name = data.get("name")
38
        if name is not None and name in names:
39
            print("ERROR: duplicate workflow name:", name, file=sys.stderr)
40
            errors_found = True
41
        names.add(name)
42
        actual = data.get("concurrency", {})
43
        if filename.name == "create_release.yml":
44
            if not actual.get("group", "").startswith(EXPECTED_GROUP_PREFIX):
45
                print(
46
                    f"'concurrency' incorrect or not found in '{filename.relative_to(REPO_ROOT)}'",
47
                    file=sys.stderr,
48
                )
49
                print(
50
                    f"concurrency group should start with {EXPECTED_GROUP_PREFIX} but found {actual.get('group', None)}",
51
                    file=sys.stderr,
52
                )
53
                errors_found = True
54
        elif not actual.get("group", "").startswith(EXPECTED_GROUP):
55
            print(
56
                f"'concurrency' incorrect or not found in '{filename.relative_to(REPO_ROOT)}'",
57
                file=sys.stderr,
58
            )
59
            print(
60
                f"concurrency group should start with {EXPECTED_GROUP} but found {actual.get('group', None)}",
61
                file=sys.stderr,
62
            )
63
            errors_found = True
64
        if not actual.get("cancel-in-progress", False):
65
            print(
66
                f"'concurrency' incorrect or not found in '{filename.relative_to(REPO_ROOT)}'",
67
                file=sys.stderr,
68
            )
69
            print(
70
                f"concurrency cancel-in-progress should be True but found {actual.get('cancel-in-progress', None)}",
71
                file=sys.stderr,
72
            )
73

74
    if errors_found:
75
        sys.exit(1)
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.