Skip to content

nicolasgere/knit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knit

Knit

Zero-config tool for Go workspace monorepos

Why Knit?

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

Install

go install github.com/nicolasgere/knit@latest

Commands

knit test              # Run tests on all modules
knit fmt               # Format all modules
knit affected          # List changed modules
knit graph             # Show dependency graph

Options

-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

Examples

# 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

CI

# 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

# .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

About

Go workspace monorepo tool

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages