Skip to content

Add pre-commit hooks for maintaining version match#579

Open
dncrews wants to merge 1 commit into
igorshubovych:masterfrom
dncrews:feat/version-match
Open

Add pre-commit hooks for maintaining version match#579
dncrews wants to merge 1 commit into
igorshubovych:masterfrom
dncrews:feat/version-match

Conversation

@dncrews
Copy link
Copy Markdown

@dncrews dncrews commented Nov 21, 2025

Pre-commit Hook for Version Synchronization

Summary

Adds automated version synchronization using pre-commit hooks to ensure version consistency
across all project files.

Problem

The project maintains version references in multiple files (package.json, markdownlint.js, README.md, .pre-commit-hooks.yaml). When updating versions, it's easy to miss updating one or more files, leading to inconsistencies.

See dncrews#2 for a demonstration where tests pass (because package.json and markdownlint.js match) but the pre-commit hook correctly fails because README.md and .pre-commit-hooks.yaml weren't updated.

Solution

  • Pre-commit hook: Automatically syncs all version references to match package.json before each commit
  • CI enforcement: GitHub Actions workflow runs pre-commit checks on all PRs
  • Developer documentation: Added Contributing section to README with setup instructions for all platforms

Changes

  • Added .pre-commit-config.yaml with version sync hook
  • Added .github/scripts/sync-version-on-commit.mjs to handle version synchronization
  • Added .github/workflows/pre-commit.yml to run hooks in CI
  • Updated README.md with contributor setup instructions

How It Works

When any version-related file is modified:

  1. Pre-commit hook reads version from package.json (source of truth)
  2. Updates all other files to match
  3. If files were modified, commit fails with instructions to review and stage changes
  4. Developer reviews changes, stages them, and retries commit

Benefits

Next Steps

For maintainers: To make this check mandatory, add pre-commit as a required status check in the branch protection rules for master (Settings → Branches → Branch protection rules).

@DavidAnson
Copy link
Copy Markdown
Collaborator

I'll leave this PR open for comment, but my initial thoughts are captured here and explain why I'm not merging this right now: #578 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pin markdownlint-fix-docker to the released version

2 participants