Built for Go monorepos using go.work. Run commands only on affected modules.
Use cases:
- CI: Test only what changed in a PR
- Pre-commit: Format only modified modules
- Local dev: Run commands on specific modules
go install github.com/nicolasgere/knit@latestknit test # Run tests on all modules
knit fmt # Format all modules
knit affected # List changed modules
knit graph # Show dependency graph-p, --path Workspace root
-t, --target Specific module
-a, --affected Run on affected modules only
-b, --base Git ref to compare (with --affected)
-c, --color Colored output# Run all tests with color
knit test --color
# Run tests on affected modules (CI)
knit test --affected
# Run tests on affected modules (compare against develop)
knit test --affected --base develop
# Format affected modules
knit fmt --affected
# Test specific module
knit test -t example.com/api
# Get list of affected modules
knit affected --merge-base
# Visualize dependencies
knit graph -f dot | dot -Tpng -o deps.png# Simple: test affected modules
- run: knit test --affected --color
# Or parallelize with GitHub matrix
- id: affected
run: echo "matrix=$(knit affected --merge-base -f github-matrix)" >> $GITHUB_OUTPUT
- strategy:
matrix: ${{ fromJson(steps.affected.outputs.matrix) }}
run: knit test -t ${{ matrix.module }}# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: knit-fmt
name: Format affected modules
entry: knit fmt --affected --base HEAD
language: system
pass_filenames: false