Skip to content

fix: use commit hash when version is v0.0.0 #5479

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

Merged
merged 1 commit into from
Feb 27, 2025
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
57 changes: 41 additions & 16 deletions pkg/commands/config_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,58 @@ func createSchemaURL(flags *pflag.FlagSet, buildInfo BuildInfo) (string, error)
return "", fmt.Errorf("parse version: %w", err)
}

schemaURL = fmt.Sprintf("https://golangci-lint.run/jsonschema/golangci.v%d.%d.jsonschema.json",
version.Segments()[0], version.Segments()[1])
if version.Core().Equal(hcversion.Must(hcversion.NewVersion("v0.0.0"))) {
commit, err := extractCommitHash(buildInfo)
if err != nil {
return "", err
}

case buildInfo.Commit != "" && buildInfo.Commit != "?":
if buildInfo.Commit == "unknown" {
return "", errors.New("unknown commit information")
return fmt.Sprintf("https://raw.githubusercontent.com/golangci/golangci-lint/%s/jsonschema/golangci.next.jsonschema.json",
commit), nil
}

commit := buildInfo.Commit
return fmt.Sprintf("https://golangci-lint.run/jsonschema/golangci.v%d.%d.jsonschema.json",
version.Segments()[0], version.Segments()[1]), nil

if strings.HasPrefix(commit, "(") {
c, _, ok := strings.Cut(strings.TrimPrefix(commit, "("), ",")
if !ok {
return "", errors.New("commit information not found")
}

commit = c
case buildInfo.Commit != "" && buildInfo.Commit != "?":
commit, err := extractCommitHash(buildInfo)
if err != nil {
return "", err
}

schemaURL = fmt.Sprintf("https://raw.githubusercontent.com/golangci/golangci-lint/%s/jsonschema/golangci.next.jsonschema.json",
commit)
return fmt.Sprintf("https://raw.githubusercontent.com/golangci/golangci-lint/%s/jsonschema/golangci.next.jsonschema.json",
commit), nil

default:
return "", errors.New("version not found")
}
}

func extractCommitHash(buildInfo BuildInfo) (string, error) {
if buildInfo.Commit == "" || buildInfo.Commit == "?" {
return "", errors.New("empty commit information")
}

if buildInfo.Commit == "unknown" {
return "", errors.New("unknown commit information")
}

commit := buildInfo.Commit

if strings.HasPrefix(commit, "(") {
c, _, ok := strings.Cut(strings.TrimPrefix(commit, "("), ",")
if !ok {
return "", errors.New("commit information not found")
}

commit = c
}

if commit == "unknown" {
return "", errors.New("unknown commit information")
}

return schemaURL, nil
return commit, nil
}

func validateConfiguration(schemaPath, targetFile string) error {
Expand Down
26 changes: 25 additions & 1 deletion pkg/commands/config_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ func Test_createSchemaURL(t *testing.T) {
},
expected: "https://raw.githubusercontent.com/golangci/golangci-lint/cd8b11773c6c1f595e8eb98c0d4310af20ae20df/jsonschema/golangci.next.jsonschema.json",
},
{
desc: "v0 version",
info: BuildInfo{
Version: "v0.0.0-20250213211019-0a603e49e5e9",
Commit: `(0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5, modified: "false", mod sum: "123")`,
},
expected: "https://raw.githubusercontent.com/golangci/golangci-lint/0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5/jsonschema/golangci.next.jsonschema.json",
},
{
desc: "dirty",
info: BuildInfo{
Version: "v1.64.6-0.20250225205237-3eecab1ebde9+dirty",
Commit: `(3eecab1ebde9, modified: "false", mod sum: "123")`,
},
expected: "https://golangci-lint.run/jsonschema/golangci.v1.64.jsonschema.json",
},
}

for _, test := range testCases {
Expand Down Expand Up @@ -87,12 +103,20 @@ func Test_createSchemaURL_error(t *testing.T) {
expected string
}{
{
desc: "commit unknown",
desc: "unknown commit",
info: BuildInfo{
Commit: "unknown",
},
expected: "unknown commit information",
},
{
desc: "detailed unknown commit",
info: BuildInfo{
Version: "",
Commit: `(unknown, modified: ?, mod sum: "")`,
},
expected: "unknown commit information",
},
{
desc: "commit ?",
info: BuildInfo{
Expand Down
Loading