Skip to content

golangci-lint-config-verify pre-commit hook fails with 404 #5478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 of 7 tasks
matthewhughes934 opened this issue Feb 26, 2025 · 12 comments · Fixed by #5479
Closed
6 of 7 tasks

golangci-lint-config-verify pre-commit hook fails with 404 #5478

matthewhughes934 opened this issue Feb 26, 2025 · 12 comments · Fixed by #5479
Labels
area: pre-commit bug Something isn't working

Comments

@matthewhughes934
Copy link
Contributor

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

I don't know

Description of the problem

This hook will try to fetch https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json and fail (see reproduction below). I think the reason it tries to fetch this is:

  • pre-commit will do a shallow clone before go install ./... and so not have git tags available
  • Without any git flags version defaults to v0.0 when fetching, and hits the 404

I'm a bit confused how this worked before: even dropping the rev in the pre-commit hook to an earlier version, that I knew to work, it fails with the same error. Maybe https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json did resolve at some point? Though I can't think of a sensible value for it: if you use the latest value, then older clients could break.

Ideas for fixes:

  • Avoid fetching the JSON schema: would it be possible to embed the schema in the binary for validation?
  • Drop the hook?

Version of golangci-lint

N/A managed through pre-commit

Configuration

no relevant (any config will trigger this)

Go environment

$ go version && go env
# paste output here

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

A minimal reproducible example or link to a public repository

reproduction script:

#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

git init repo
cd repo

cat <<'EOF' > .pre-commit-config.yaml
repos:
-   repo: https://github.com/golangci/golangci-lint
    rev: v1.64.5
    hooks:
    -   id: golangci-lint-config-verify
EOF

git add .pre-commit-config.yaml
git commit --message 'Add pre-commit'

touch .golangci.yaml
git add .golangci.yaml

pre-commit run --all-files

The relevant output:

golangci-lint-config-verify..............................................Failed
- hook id: golangci-lint-config-verify
- exit code: 3

Failed executing command with error: [.golangci.yaml] validate: compile schema: failing loading "https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json": https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json returned status code 404

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@matthewhughes934 matthewhughes934 added the bug Something isn't working label Feb 26, 2025
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Feb 26, 2025
@ldez
Copy link
Member

ldez commented Feb 26, 2025

Hello,

The problem is the way to install golangci-lint.

These installations aren't recommended because of the following points:
...
The resulting binary was not tested and is not guaranteed to work.
https://golangci-lint.run/welcome/install/#install-from-sources

@matthewhughes934
Copy link
Contributor Author

digging deeper: looks like something changed between Go 1.23 and Go 1.24. The build process for pre-commit is something like:

$ git init repo
$ cd repo
$ git remote add origin https://github.com/golangci/golangci-lint.git
$ git fetch origin v1.64.5 --depth 1
$ git checkout FETCH_HEAD
$ go install ./...

testing the go install step with different Go versions:

$ go1.24.0 install ./...
$ golangci-lint version
golangci-lint has version v0.0.0-20250213211019-0a603e49e5e9 built with go1.24.0 from (0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5, modified: false, mod sum: "") on 2025-02-13T21:10:19Z
$ golangci-lint config verify
Failed executing command with error: [.golangci.yml] validate: compile schema: failing loading "https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json": https://golangci-lint.run/jsonschema/golangci.v0.0.jsonschema.json returned status code 404

vs Go 1.23:

$ go1.23.0 install ./...
$ golangci-lint version
golangci-lint has version (devel) built with go1.23.0 from (0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5, modified: false, mod sum: "") on 2025-02-13T21:10:19Z
$ golangci-lint config verify
# runs successfully

@ldez
Copy link
Member

ldez commented Feb 26, 2025

Avoid fetching the JSON schema: would it be possible to embed the schema in the binary for validation?

We will not embed the JSON Schema, I provided an explanation here: #4527

@ldez
Copy link
Member

ldez commented Feb 26, 2025

#5478 (comment)

I think I know where the root of the new behavior is.

@ldez
Copy link
Member

ldez commented Feb 26, 2025

But I want to be clear that your approach based on shallow clone doesn't work even with go1.23.

Because the version will be devel and so the JSON Schema used to validate the configuration is the future JSON schema and not the current and latest version.

@matthewhughes934
Copy link
Contributor Author

The problem is the way to install golangci-lint.

But I want to be clear that your approach based on shallow clone doesn't work even with go1.23.
Because the version will be devel and so the JSON Schema used to validate the configuration is the future JSON schema and not the current and latest version.

If that's the case, then maybe the hook isn't viable? I can't imagine pre-commit is willing to special case an installation, e.g.to install the binary directly for a single application

@ldez
Copy link
Member

ldez commented Feb 26, 2025

I don't use pre-commit but for me, pre-commit doesn't imply compiling a binary.

@ldez
Copy link
Member

ldez commented Feb 26, 2025

You can use our script to install the binaries: https://golangci-lint.run/welcome/install/#other-ci

@ldez
Copy link
Member

ldez commented Feb 26, 2025

For the explanation of the new behavior:

The go build command now sets the main module’s version in the compiled binary based on the version control system tag and/or commit.
https://go.dev/doc/go1.24#tools

@matthewhughes934
Copy link
Contributor Author

I don't use pre-commit but for me, pre-commit doesn't imply compiling a binary.

For clarity: pre-commit installs the repo you point it to in the config (based on the language of the hook, ignoring the special system language) , the install process for go is go install ./... https://pre-commit.com/#golang

@ldez
Copy link
Member

ldez commented Feb 26, 2025

I need to check something, give me a few minutes.

@ldez
Copy link
Member

ldez commented Feb 26, 2025

The discussion is happening on Slack

@ldez ldez added area: pre-commit bug Something isn't working and removed question Further information is requested labels Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: pre-commit bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants