Skip to content

Commit fdfcad2

Browse files
committed
Catch catalog drift vs generated hooks
Add generated hook comments to help contributors, instructing them to modify the catalog.py + a GHA job to check for catalog discrepancies. Contributors easily modify `.pre-commit-hooks.yaml` without modifying the catalog file, which puts us in the state that changes can easily be accidentally reverted. The job enforces that if regenerating the hooks produces a change, the PR fails in CI, and the comments help contributors avoid failing CI.
1 parent 69f50c9 commit fdfcad2

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.github/workflows/build.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,38 @@ jobs:
9999
# collate and report
100100
- run: python ./scripts/aggregate-pytest-reports.py artifacts/*/pytest.*.xml
101101

102+
# this job ensures that any changes to the hook config are reflected properly
103+
# in hook config generation
104+
# if it fails, please see the CONTRIBUTING.md for the repo and read the section titled
105+
# "Adding new hooks"
106+
ensure-catalog-matches-hook-config:
107+
runs-on: ubuntu-latest
108+
steps:
109+
- uses: actions/checkout@v3
110+
111+
- name: get date for caching
112+
run: /bin/date -u "+%U" > cachedate.txt
113+
shell: bash
114+
115+
- uses: actions/setup-python@v4
116+
id: setup-python
117+
with:
118+
python-version: "3.x"
119+
cache: "pip"
120+
cache-dependency-path: |
121+
.github/workflows/build.yaml
122+
setup.cfg
123+
tox.ini
124+
cachedate.txt
125+
126+
- run: python -m pip install tox
127+
128+
- name: regenerate hook config
129+
run: tox run -e generate-hooks-config
130+
131+
- name: fail if .pre-commit-hooks.yaml changed
132+
run: git diff --exit-code -- .pre-commit-hooks.yaml
133+
102134
self-check:
103135
name: "Self-Check"
104136
runs-on: ubuntu-latest

.pre-commit-hooks.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
# --AUTOGEN_HOOKS_START-- #
2020

21+
# this hook is autogenerated from a script
22+
# to modify this hook, update `src/check_jsonschema/catalog.py`
23+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
2124
- id: check-azure-pipelines
2225
name: Validate Azure Pipelines
2326
description: 'Validate Azure Pipelines config against the schema provided by Microsoft'
@@ -26,6 +29,9 @@
2629
files: ^(\.)?azure-pipelines.(yml|yaml)$
2730
types: [yaml]
2831

32+
# this hook is autogenerated from a script
33+
# to modify this hook, update `src/check_jsonschema/catalog.py`
34+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
2935
- id: check-bamboo-spec
3036
name: Validate Bamboo Specs
3137
description: 'Validate Bamboo Specs against the schema provided by SchemaStore'
@@ -34,6 +40,9 @@
3440
files: ^bamboo-specs/.*\.(yml|yaml)$
3541
types: [yaml]
3642

43+
# this hook is autogenerated from a script
44+
# to modify this hook, update `src/check_jsonschema/catalog.py`
45+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
3746
- id: check-buildkite
3847
name: Validate Buildkite Pipelines
3948
description: 'Validate Buildkite Pipelines against the schema provided by Buildkite'
@@ -48,6 +57,9 @@
4857
)$
4958
types_or: [json,yaml]
5059

60+
# this hook is autogenerated from a script
61+
# to modify this hook, update `src/check_jsonschema/catalog.py`
62+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
5163
- id: check-dependabot
5264
name: Validate Dependabot Config (v2)
5365
description: 'Validate Dependabot Config (v2) against the schema provided by SchemaStore'
@@ -56,6 +68,9 @@
5668
files: ^\.github/dependabot.(yml|yaml)$
5769
types: [yaml]
5870

71+
# this hook is autogenerated from a script
72+
# to modify this hook, update `src/check_jsonschema/catalog.py`
73+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
5974
- id: check-github-actions
6075
name: Validate GitHub Actions
6176
description: 'Validate GitHub Actions against the schema provided by SchemaStore'
@@ -68,6 +83,9 @@
6883
)$
6984
types: [yaml]
7085

86+
# this hook is autogenerated from a script
87+
# to modify this hook, update `src/check_jsonschema/catalog.py`
88+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
7189
- id: check-github-workflows
7290
name: Validate GitHub Workflows
7391
description: 'Validate GitHub Workflows against the schema provided by SchemaStore'
@@ -76,6 +94,9 @@
7694
files: ^\.github/workflows/[^/]+$
7795
types: [yaml]
7896

97+
# this hook is autogenerated from a script
98+
# to modify this hook, update `src/check_jsonschema/catalog.py`
99+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
79100
- id: check-gitlab-ci
80101
name: Validate GitLab CI config
81102
description: 'Validate GitLab CI config against the schema provided by SchemaStore'
@@ -84,6 +105,9 @@
84105
files: ^.*\.gitlab-ci.yml$
85106
types: [yaml]
86107

108+
# this hook is autogenerated from a script
109+
# to modify this hook, update `src/check_jsonschema/catalog.py`
110+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
87111
- id: check-readthedocs
88112
name: Validate ReadTheDocs Config
89113
description: 'Validate ReadTheDocs config against the schema provided by ReadTheDocs'
@@ -92,6 +116,9 @@
92116
files: ^\.readthedocs.(yml|yaml)$
93117
types: [yaml]
94118

119+
# this hook is autogenerated from a script
120+
# to modify this hook, update `src/check_jsonschema/catalog.py`
121+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
95122
- id: check-renovate
96123
name: Validate Renovate Config
97124
description: 'Validate Renovate config against the schema provided by Renovate (does not support renovate config in package.json)'
@@ -104,6 +131,9 @@
104131
\.renovaterc(\.json)?
105132
)$
106133
134+
# this hook is autogenerated from a script
135+
# to modify this hook, update `src/check_jsonschema/catalog.py`
136+
# and run `make generate-hooks` or `tox run -e generate-hooks-config`
107137
- id: check-travis
108138
name: Validate Travis Config
109139
description: 'Validate Travis Config against the schema provided by SchemaStore'

scripts/generate-hooks-config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def update_hook_config(new_config: str) -> None:
4242

4343

4444
def generate_hook_lines(config) -> t.Iterator[str]:
45+
yield "# this hook is autogenerated from a script"
46+
yield "# to modify this hook, update `src/check_jsonschema/catalog.py`"
47+
yield "# and run `make generate-hooks` or `tox run -e generate-hooks-config`"
4548
yield f"- id: {config['id']}"
4649
yield f" name: {config['name']}"
4750
yield f" description: '{config['description']}'"

0 commit comments

Comments
 (0)