I'm using some pre-commit hooks for Buf to help me check Protobuf files before compiling them to Go:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 # Use the ref you want to point at
hooks:
# Git style
- id: check-added-large-files
args: ["--maxkb=512"]
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: forbid-new-submodules
# Common errors
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-merge-conflict
- id: check-executables-have-shebangs
# Cross platform
- id: check-case-conflict
- repo: https://github.com/yoheimuta/protolint
rev: v0.53.0
hooks:
- id: protolint
files: protos/.
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.3
hooks:
- id: check-github-workflows
- repo: https://github.com/bufbuild/buf
rev: v1.50.1
hooks:
- id: buf-dep-update
- id: buf-dep-prune
- id: buf-breaking
args: ["--against", ".git/subdir=start/protos"]
I'm not sure why, but when I run this locally, I always get the following error message:
An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang
I can tell this is happening at the Buf pre-commit hook as I can remove it and the process runs properly. However, I do have Go installed already:
> go version
go version go1.24.1 linux/amd64
> which go
/usr/local/go/bin/go
Trying this locally:
> which go && pre-commit run
/usr/local/go/bin/go
[INFO] Installing environment for https://github.com/bufbuild/buf.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang
Check the log at /home/{user}/.cache/pre-commit/pre-commit.log
Since go
isn't installed in the home directory, I don't see how this wouldn't work. And it does run properly on GitHub. How can I get this pre-commit hook to run properly?
one of your language: golang
hooks sets language_version: ...
to some value.
the version of pre-commit
you're using is too old to understand language_version:
-- you'll need to upgrade to at least version 3.0.0
(released 2023-01-23)
disclaimer: I wrote pre-commit