forked from jflournoy/for-funsies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_workflow_yaml.py
More file actions
38 lines (30 loc) · 954 Bytes
/
Copy pathcheck_workflow_yaml.py
File metadata and controls
38 lines (30 loc) · 954 Bytes
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
#!/usr/bin/env python3
"""Fail if any workflow file is not valid YAML.
A malformed workflow does not fail loudly — GitHub simply declines to run it,
which on this repository would mean bounty submissions silently stop being
checked. Better to break the build.
Usage: python scripts/check_workflow_yaml.py
"""
import glob
import sys
import yaml
def main() -> int:
paths = sorted(
glob.glob(".github/workflows/*.yml") + glob.glob(".github/workflows/*.yaml")
)
if not paths:
print("No workflows found.")
return 0
failed = False
for path in paths:
try:
yaml.safe_load(open(path, encoding="utf-8"))
except yaml.YAMLError as e:
print(f"::error file={path}::Invalid YAML: {e}")
failed = True
if failed:
return 1
print(f"Workflow YAML valid in {len(paths)} file(s): OK")
return 0
if __name__ == "__main__":
raise SystemExit(main())