Skip to content

Commit 30e1ee3

Browse files
committed
test: ensure every Renovate preset is validated
1 parent f6d6044 commit 30e1ee3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import pathlib
4+
5+
ROOT = pathlib.Path(__file__).resolve().parent.parent.parent
6+
CONFIG_FILE = ROOT / ".pre-commit-config.yaml"
7+
8+
9+
def main(argv: list[str]) -> int:
10+
if not CONFIG_FILE.exists():
11+
print(".pre-commit-config.yaml not found in repo root")
12+
return 1
13+
14+
config_text = CONFIG_FILE.read_text()
15+
16+
missing = []
17+
for file_arg in argv:
18+
path = pathlib.Path(file_arg)
19+
20+
# only care about JSONs in repo root
21+
if path.suffix == ".json" and path.parent.resolve() == ROOT:
22+
print(f"Checking {path.name}...", flush=True)
23+
if path.name not in config_text:
24+
missing.append(path.name)
25+
26+
if missing:
27+
print("\nThese JSON files are missing from .pre-commit-config.yaml:")
28+
for m in missing:
29+
print(f" - {m}")
30+
return 1
31+
32+
return 0
33+
34+
35+
if __name__ == "__main__":
36+
sys.exit(main(sys.argv[1:]))

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# See https://pre-commit.com/hooks.html for more hooks
44

55
repos:
6+
- repo: local
7+
hooks:
8+
- id: check-json-in-config
9+
name: Check Renovate presets are listed in pre-commit-config.yaml
10+
entry: .cicd/hooks/check-json-in-config.py
11+
language: python
12+
types: [json]
613
- repo: https://github.com/pre-commit/pre-commit-hooks
714
rev: v6.0.0
815
hooks:
@@ -31,6 +38,7 @@ repos:
3138
(^|/).?renovate(?:rc)?(?:\.json5?)?$|
3239
default.json|
3340
copier.json|
41+
groupManager.json|
3442
pre-commit.json|
3543
monthly.json|
3644
weekly.json|

0 commit comments

Comments
 (0)