This directory contains reusable Taskfile templates for pre-commit operations, including hook installation, cache management, and automated code quality checks.
- Task installed (
brew install go-task/tap/go-task) - pre-commit installed (
pip install pre-commitorbrew install pre-commit) - Python 3.6+ (for pre-commit)
- Git repository initialized
The taskfile requires the following configuration:
-
Ensure you have a
.pre-commit-config.yamlfile in your repository root with your desired hooks configured -
(Optional) Create a
.envfile for any environment-specific settings:# Example: Skip specific hooks during local development SKIP=pylint,mypy
Installs pre-commit hooks into your git repository. This enables automatic hook
execution on git commit.
task install-pc-hooksClears the pre-commit cache. Useful when hooks are misbehaving or after updating hook versions.
task clear-cacheRuns all configured pre-commit hooks against all files in the repository. Shows differences on failure.
task run-hooksComplete pre-commit workflow: installs hooks, updates them, clears cache, and runs all hooks. This is the recommended task for CI/CD pipelines or fresh setups.
task run-pre-commitUpdates all pre-commit hooks to their latest versions as specified in the configuration.
task update-hooks-
Initial setup for a new developer:
task install-pc-hooks
-
Run all hooks before committing:
task run-hooks
-
Full pre-commit workflow (recommended for CI):
task run-pre-commit
-
Update hooks to latest versions:
task update-hooks
-
Fix hook issues by clearing cache:
task clear-cache task run-hooks
You can extend these tasks in your own Taskfile by importing this template and adding project-specific tasks. Here's an example:
version: "3"
includes:
precommit:
taskfile: ./pre-commit.yml
optional: true
tasks:
# Override or extend existing tasks
lint:
deps: [precommit:run-hooks]
cmds:
- echo "Additional linting completed"
# Add new tasks that use the base tasks
ci-check:
desc: "Run all CI checks"
cmds:
- task: precommit:run-pre-commit
- task: test
- task: build
# Run specific hooks only
format:
desc: "Run only formatting hooks"
cmds:
- pre-commit run black --all-files
- pre-commit run isort --all-files- Pre-commit hooks run automatically on
git commitafter installation - Use
git commit --no-verifyto bypass hooks in emergencies (not recommended) - The
run-pre-committask includesinstall-pc-hooksas a dependency to ensure hooks are always installed - Hook configurations are stored in
.pre-commit-config.yaml - Individual hooks can be skipped using the
SKIPenvironment variable:SKIP=flake8 git commit - The
--show-diff-on-failureflag helps identify what changes hooks would make - Regular hook updates (
task update-hooks) ensure you're using the latest security fixes and features
- Run hooks before pushing: Always run
task run-hooksbefore pushing code - Keep hooks updated: Regularly run
task update-hooksto get the latest versions - Clear cache when needed: If hooks behave unexpectedly, run
task clear-cache - CI/CD Integration: Use
task run-pre-commitin your CI pipeline for consistency - Team consistency: Ensure all team members run
task install-pc-hooksafter cloning the repository