-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
perf: replace goheader linter with custom check
#37599
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
silverwind
merged 31 commits into
go-gitea:main
from
silverwind:lint-go-replace-goheader
May 8, 2026
Merged
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
45c7833
perf: replace goheader linter with custom check
silverwind de88319
merge targets
silverwind c4357b0
chore: combine lint-go header check and golangci-lint into single stage
silverwind 01351e4
chore: preserve golangci-lint exit code over header check
silverwind 6f56264
fix: address copilot review feedback
silverwind 5d30738
refactor: simplify file read with os.ReadFile
silverwind ac2aa27
fix: build lint-go-header for host in lint-go-windows
silverwind 6e0d9a0
Merge branch 'main' into lint-go-replace-goheader
silverwind 9bbf547
refactor: extract lint-go orchestration to tools/lint-go.sh
silverwind 6a1cb97
refactor: consolidate lint-go targets through tools/lint-go.sh
silverwind 3475f75
refactor: inline lint-go.sh branches instead of array dispatch
silverwind 6c75a5b
refactor: inline exit-code capture into the same line
silverwind 9f6f4f4
refactor: pass GO from make and use it in lint-go.sh
silverwind df962f1
chore: drop orphaned goheader settings block
silverwind 8639048
fix
wxiaoguang f7df98a
fix
wxiaoguang 17f8753
fix: address review feedback on tools/lint-go-header.go
silverwind 5719a58
Merge branch 'main' into lint-go-replace-goheader
silverwind 4ccebfa
fix: skip top-level dirs by relative path
silverwind 9c60c59
fix
wxiaoguang 436902c
Apply suggestion from @silverwind
silverwind 8700e51
Apply suggestion from @wxiaoguang
wxiaoguang 65d154e
add lint-go-all.sh back
wxiaoguang 00182de
make "lint-go" to lint all
wxiaoguang 3ebe430
fix
wxiaoguang d3577be
fine tune
wxiaoguang 3ab0a37
fine tune
wxiaoguang a49302a
Merge branch 'main' into lint-go-replace-goheader
GiteaBot 5bab4db
Merge branch 'main' into lint-go-replace-goheader
silverwind e279ca6
Merge branch 'main' into lint-go-replace-goheader
GiteaBot 8b81aad
Merge branch 'main' into lint-go-replace-goheader
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "io/fs" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| ) | ||
|
|
||
| func lintGoHeader() bool { | ||
| headerRE := regexp.MustCompile(`^(// (Copyright [^\n]+|All rights reserved\.)\n)*// Copyright \d{4} (The Gogs Authors|The Gitea Authors|Gitea Authors|Gitea)\.( All rights reserved\.)?\n(// (Copyright [^\n]+|All rights reserved\.)\n)*// SPDX-License-Identifier: [\w.-]+`) | ||
| generatedRE := regexp.MustCompile(`(?m)^// (Code|This file is) [Gg]enerated.*DO NOT EDIT`) | ||
| skipDirs := map[string]bool{ | ||
| ".git": true, | ||
| ".venv": true, | ||
| "node_modules": true, | ||
| "public": true, | ||
| "vendor": true, | ||
| "web_src": true, | ||
| } | ||
| root, bad := ".", 0 | ||
| err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if d.IsDir() { | ||
| if rel, _ := filepath.Rel(root, path); skipDirs[filepath.ToSlash(rel)] { | ||
| return fs.SkipDir | ||
| } | ||
| return nil | ||
| } | ||
| if !strings.HasSuffix(path, ".go") { | ||
| return nil | ||
| } | ||
| f, err := os.Open(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| data, err := io.ReadAll(io.LimitReader(f, 512)) | ||
| _ = f.Close() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if generatedRE.Match(data) { | ||
| return nil | ||
| } | ||
| if !headerRE.Match(data) { | ||
| _, _ = fmt.Fprintf(os.Stderr, "%s: missing or invalid copyright header\n", path) | ||
| bad++ | ||
| } | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| _, _ = fmt.Fprintln(os.Stderr, err) | ||
| } | ||
| return err == nil && bad == 0 | ||
| } | ||
|
|
||
| func runCmd(env []string, name string, args []string) bool { | ||
| cmd := exec.Command(name, args...) | ||
| cmd.Env = append(os.Environ(), env...) | ||
| cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr | ||
| if err := cmd.Run(); err != nil { | ||
| _, _ = fmt.Fprintln(os.Stderr, err) | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| func main() { | ||
| // 'go run' can not have distinct GOOS/GOARCH for its build and run steps, | ||
| // so install a pre-compiled binary and run it for different target platforms. | ||
| _, _ = os.Unsetenv("GOOS"), os.Unsetenv("GOARCH") | ||
| envGolangciLintPackage := os.Getenv("GOLANGCI_LINT_PACKAGE") | ||
| envGo := os.Getenv("GO") | ||
|
wxiaoguang marked this conversation as resolved.
|
||
| if !runCmd(nil, envGo, []string{"install", envGolangciLintPackage}) { | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintln(os.Stdout, "lint go header ...") | ||
| succeed := lintGoHeader() | ||
| _, _ = fmt.Fprintln(os.Stdout, "lint for linux ...") | ||
| succeed = runCmd([]string{"GOOS=linux", "TAGS=bindata"}, "golangci-lint", append([]string{"run"}, os.Args[1:]...)) && succeed | ||
| _, _ = fmt.Fprintln(os.Stdout, "lint for windows ...") | ||
| succeed = runCmd([]string{"GOOS=windows", "TAGS=gogit"}, "golangci-lint", append([]string{"run"}, os.Args[1:]...)) && succeed | ||
|
wxiaoguang marked this conversation as resolved.
wxiaoguang marked this conversation as resolved.
|
||
| if !succeed { | ||
| os.Exit(1) | ||
| } | ||
|
wxiaoguang marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.