Debian Codegraph @

ansible_collections/community/general/tests/sanity/extra/aliases.py

raw
1 #!/usr/bin/env python
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5 """Check extra collection docs with antsibull-docs."""
6
7 from __future__ import annotations
8
9 import glob
10 import sys
11
12 import yaml
13
14
15 def main():
16 """Main entry point."""
17 with open(".azure-pipelines/azure-pipelines.yml", "rb") as f:
18 azp = yaml.safe_load(f)
19
20 allowed_targets = {"azp/generic/1"}
21 for stage in azp["stages"]:
22 if stage["stage"].startswith(("Sanity", "Unit", "Generic", "Summary")):
23 continue
24 for job in stage["jobs"]:
25 for group in job["parameters"]["groups"]:
26 allowed_targets.add(f"azp/posix/{group}")
27
28 paths = glob.glob("tests/integration/targets/*/aliases")
29
30 has_errors = False
31 for path in paths:
32 targets = []
33 skip = False
34 with open(path) as f:
35 for line in f:
36 if "#" in line:
37 line = line[: line.find("#")]
38 line = line.strip()
39 if line.startswith("needs/"):
40 continue
41 if line.startswith("skip/"):
42 continue
43 if line.startswith("cloud/"):
44 continue
45 if line.startswith("context/"):
46 continue
47 if line in ("unsupported", "disabled", "hidden"):
48 skip = True
49 if line in ("destructive",):
50 continue
51 if "/" not in line:
52 continue
53 targets.append(line)
54 if skip:
55 continue
56 if not targets:
57 if "targets/setup_" in path:
58 continue
59 print(f"{path}: found no targets")
60 has_errors = True
61 for target in targets:
62 if target not in allowed_targets:
63 print(f'{path}: found invalid target "{target}"')
64 has_errors = True
65
66 return 1 if has_errors else 0
67
68
69 if __name__ == "__main__":
70 sys.exit(main())