Skip to content

Commit 12d3cc0

Browse files
authored
Add auto-regen state.md pre-commit hook + idempotent generator write (SAN-821) (#89)
Mirror the sanna-ts state.md drift control into sanna-repo: a local pre-commit hook regenerates docs/state.md and fails the commit if it was stale - a local mirror of the CI "Validate state doc" --check gate. Make the generator's write mode idempotent (skip when only the timestamp would change, reusing _comparable) so the hook does not churn docs/state.md on every commit.
1 parent 45a97b2 commit 12d3cc0

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ repos:
44
hooks:
55
- id: detect-private-key
66
name: Block PEM private keys
7+
- repo: local
8+
hooks:
9+
- id: state-doc
10+
name: Regenerate docs/state.md (fails if it was stale)
11+
entry: python3 tools/generate_state_doc.py
12+
language: system
13+
pass_filenames: false
14+
always_run: true

tools/generate_state_doc.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,16 @@ def main() -> None:
224224
timestamp = datetime.datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
225225
content = generate_full(root, timestamp)
226226
(root / "docs").mkdir(exist_ok=True)
227-
state_path.write_text(content)
228-
print(
229-
f"Generated docs/state.md "
230-
f"(version={get_version(root)}, tests={count_test_files(root)})"
231-
)
227+
if state_path.exists() and _comparable(state_path.read_text()) == _comparable(content):
228+
# Idempotent: only the volatile timestamp would change. Skip the write so
229+
# the auto-regen pre-commit hook does not churn docs/state.md every commit.
230+
print("docs/state.md is already up to date (timestamp-only change skipped).")
231+
else:
232+
state_path.write_text(content)
233+
print(
234+
f"Generated docs/state.md "
235+
f"(version={get_version(root)}, tests={count_test_files(root)})"
236+
)
232237

233238

234239
if __name__ == "__main__":

0 commit comments

Comments
 (0)