Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
GO_BIN="./build/pre-commit"
RUNS=5

cd "$(dirname "$0")"
cd "$(dirname "$0")/.."

echo "================================================================"
echo " Pre-commit Performance Benchmark"
Expand Down
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ action.yml # Composite GitHub Action (repo root) — see CI/CD bel
internal/
cli/ # Command definitions; each command implements cli.Command
config/ # .pre-commit-config.yaml parsing; holds Version (ldflags target)
fsutil/ # Filesystem helpers
git/ # Git operations — staging, refs, hooks dir
hook/ # Hook execution engine and runner
identify/ # File type identification by extension, filename, shebang
Expand Down Expand Up @@ -93,7 +94,7 @@ Releases: push a `v*` tag → GoReleaser (`.goreleaser.yaml`) builds, signs, and
- `go.mod`'s `go` directive is authoritative and must match `.tool-versions`' `golang` pin **exactly** — enforced by the `check-go-version-sync` hook from [blairham/pre-commit-hooks](https://github.com/blairham/pre-commit-hooks), pinned by `rev` in `.pre-commit-config.yaml`
- golangci-lint and gofumpt are pinned in `go.mod`'s `tool` block — invoke as `go tool <name>`, never a separately installed binary
- Keep the `golangci-lint` pre-commit `rev`, the `go.mod` tool pin, and the CI action version in lockstep
- goreleaser is pinned in `.tool-versions` (2.15.3), not `go.mod`
- goreleaser is pinned in `.tool-versions`, not `go.mod`

## Key Dependencies

Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ A Go reimplementation of [pre-commit](https://github.com/pre-commit/pre-commit)

## Installation

### Homebrew

```bash
brew install blairham/tap/pre-commit
```

### Pre-built binaries

Download the latest release from the [Releases page](https://github.com/blairham/go-pre-commit/releases). Archives are available for Linux, macOS, and Windows (amd64/arm64).
Expand All @@ -35,6 +41,8 @@ sudo mv pre-commit /usr/local/bin/
go install github.com/blairham/go-pre-commit/v4@latest
```

Note: `go install` names the binary `go-pre-commit` (Go strips the `/v4` suffix). Rename it to `pre-commit` on your PATH — the git hooks it installs invoke it by that name.

### Build from source

```bash
Expand Down Expand Up @@ -62,12 +70,13 @@ Inputs:
```yaml
- uses: blairham/go-pre-commit@main
with:
version: latest # release to install, e.g. "v4.5.4"
version: latest # release to install, e.g. "v4.6.6"
extra_args: --all-files # passed to `pre-commit run`
cache: 'true' # cache hook environments between runs
install-only: 'false' # set 'true' to install the binary but skip `pre-commit run`
```

Hooks run as `pre-commit run --show-diff-on-failure --color=always <extra_args>`, and hook environments (`~/.cache/pre-commit`) are cached keyed on `.pre-commit-config.yaml`, so warm runs skip environment setup entirely. Hooks that need extra tools on `PATH` (e.g. `language: system` hooks) still require you to install those tools in earlier steps.
Hooks run as `pre-commit run --show-diff-on-failure --color=always <extra_args>`, and hook environments (`~/.cache/pre-commit`) are cached keyed on `.pre-commit-config.yaml`, so warm runs skip environment setup entirely. Hooks that need extra tools on `PATH` (e.g. `language: system` hooks) still require you to install those tools in earlier steps. With `install-only: 'true'` the action puts the binary on `PATH` (and still caches) but skips the run step, for workflows that drive pre-commit themselves.

## Usage

Expand Down Expand Up @@ -169,29 +178,33 @@ Benchmarked against Python pre-commit v4.5.1 on the same config (macOS, Apple Si

Python-based hooks (pre-commit-hooks) see the largest improvement since Go avoids spawning a Python interpreter for each hook. Hooks that shell out to external tools (golangci-lint) show similar performance since the tool itself dominates.

Run the benchmark yourself: `bash bench.sh`
Run the benchmark yourself: `bash .github/bench.sh`

## Development

```bash
make build # Build binary
make test # Run tests
make lint # Run linter
make fmt # Format code
make build # Build binary to build/pre-commit
make test # Run tests (with -race)
make test-cover # Tests + HTML coverage report
make lint # Run golangci-lint
make fmt # Format code (gofumpt)
make vet # Run go vet
make tidy # go mod tidy
make check # Format + vet + test
```

Note that `make check` does not run the linter — run `make lint` separately before opening a PR.

## Releasing

Releases are automated with [GoReleaser](https://goreleaser.com) via GitHub Actions. To create a release:

```bash
git tag v4.6.0
git push origin v4.6.0
git tag v4.6.7
git push origin v4.6.7
```

CI will build cross-platform binaries and publish a GitHub release automatically.
CI builds, signs, and notarizes cross-platform binaries, publishes a GitHub release, and updates the Homebrew formula in [blairham/homebrew-tap](https://github.com/blairham/homebrew-tap) automatically. Versions track upstream parity: `v4.6.x` means feature parity with Python pre-commit 4.6.

## License

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ branding:
inputs:
version:
description: >-
Release of go-pre-commit to install (e.g. "v4.5.4"), or "latest".
Release of go-pre-commit to install (e.g. "v4.6.6"), or "latest".
required: false
default: latest
extra_args:
Expand Down