Skip to content

feat: extend pre-commit check with file-type coverage - #81

Merged
ineedjet merged 2 commits into
mainfrom
feat/check-precommit-coverage
Jul 2, 2026
Merged

ineedjet merged 2 commits into
mainfrom
feat/check-precommit-coverage

Conversation

@ineedjet

@ineedjet ineedjet commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends check-precommit-sync with a second check: coverage.

Previously the script only verified that .pre-commit-config.yaml hooks match CI linters (sync check). Now it also scans the repo's files using the identify library and verifies that every hook whose file type is present in the repo is actually configured.

Two checks, one script:

  1. Coverage — git ls-files → identify.tags_from_path() → needed hooks → must all be in .pre-commit-config.yaml
  2. Sync — .pre-commit-config.yaml hooks must match inputs.linters

Other changes:

  • setup-runtimes: installs pyyaml + identify when pre-commit is in linters
  • Baseline own .pre-commit-config.yaml / lint.yml: ruff added back — hooks/ now contains Python scripts

Note

Same bootstrap caveat as #79: CI for this PR runs against check-precommit-sync@v0.7 (old version, sync-only). Will need to update the v0.7 tag and cut a patch release after merge.

check-precommit-sync now runs two checks:
1. Coverage: scans repo files with identify, finds which baseline hooks
   are needed based on file types, fails if any are missing from
   .pre-commit-config.yaml
2. Sync: existing check — configured hooks must match CI linters

setup-runtimes installs pyyaml + identify when pre-commit is in linters.

Also adds ruff back to baseline own config/lint since hooks/ now
contains Python scripts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 077517fa6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

print("::error::.pre-commit-config.yaml not found — required when pre-commit is in linters.")
sys.exit(1)
import yaml
from identify.identify import tags_from_path

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Install check dependencies before running the sync action

🤖 [rubykatzen/baseline]: When pre-commit is in inputs.linters, .github/workflows/lint-shared.yml invokes check-precommit-sync before setup-runtimes, so this new top-level identify import runs before the pyyaml identify install added to setup-runtimes. On a clean runner without these Python packages, the action exits with ModuleNotFoundError before any sync check can run; install the dependencies in the check action itself or move runtime setup ahead of the check.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the repository’s check-precommit-sync enforcement so it can validate not only that CI linters match .pre-commit-config.yaml (sync), but also that .pre-commit-config.yaml includes all baseline hooks relevant to file types present in the repo (coverage). It also updates baseline’s own linting inputs/config to account for Python hooks.

Changes:

  • Add a “coverage” check to hooks/check-precommit-sync.py by scanning tracked files (git ls-files) and mapping them to identify tags to determine which baseline hooks are required.
  • Update baseline’s .pre-commit-config.yaml and CI lint.yml to include ruff.
  • Extend setup-runtimes to treat pre-commit as a supported value and install Python deps (pyyaml, identify) when pre-commit is enabled.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
hooks/check-precommit-sync.py Adds coverage detection via identify + git ls-files, and reports missing/extra hooks plus sync mismatches.
.pre-commit-config.yaml Enables the ruff baseline hook in baseline’s own pre-commit config.
.github/workflows/lint.yml Adds ruff to baseline’s self-lint linters input list.
.github/actions/setup-runtimes/action.yml Installs Python deps needed for the new coverage logic when pre-commit is included.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to +20
if: >
contains(inputs.linters, 'yamllint') ||
contains(inputs.linters, 'pymarkdown') ||
contains(inputs.linters, 'ruff')
contains(inputs.linters, 'ruff') ||
contains(inputs.linters, 'pre-commit')
Comment on lines +8 to +9
import yaml
from identify.identify import tags_from_path
pyyaml and identify must be installed before the sync script runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ineedjet

ineedjet commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot перепроверь коменты, зарезольвь исправленное

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown

@copilot перепроверь коменты, зарезольвь исправленное

🧠 [rubykatzen/baseline]: Both comments are now addressed:

  1. Ordering fix — already resolved in the previous commit: setup-runtimes now runs before check-precommit-sync in lint-shared.yml.
  2. Import guard — added in fix: add import guard for pyyaml/identify with actionable error message: bare imports of yaml and tags_from_path are now wrapped in a try/except ImportError that emits ::error::Missing Python dependency: ... Install with: pip install pyyaml identify and exits cleanly.

@ineedjet
ineedjet force-pushed the feat/check-precommit-coverage branch from 7ce778c to 9dce051 Compare July 2, 2026 20:03
@ineedjet
ineedjet merged commit 186fc0c into main Jul 2, 2026
3 checks passed
This was referenced Aug 12, 2026
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.

3 participants