diff options
author | Yarden Shoham <hrsi88@gmail.com> | 2022-10-15 23:10:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 21:10:25 +0100 |
commit | bc532563169b14cf6e51db6ca7190289fd81c0f1 (patch) | |
tree | cc0f4f7c21f2ea114b6604dcd88e93ca330de23a /build | |
parent | b9cd6fb70370b97496e03c61be35e0d3ceedc52d (diff) | |
download | gitea-bc532563169b14cf6e51db6ca7190289fd81c0f1.tar.gz gitea-bc532563169b14cf6e51db6ca7190289fd81c0f1.zip |
Use own Go version instead of hardcoded 1.17 for `make fmt` (#21457)
We should make sure we're using the same version across the codebase.
* We upgraded in #19918 but forgot about the following line
https://github.com/go-gitea/gitea/blob/6bb6a108e0c03b323402b452fc05c6845f7d00df/build/code-batch-process.go#L273
Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'build')
-rw-r--r-- | build/code-batch-process.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/build/code-batch-process.go b/build/code-batch-process.go index 24b13470ab..dce5288cf3 100644 --- a/build/code-batch-process.go +++ b/build/code-batch-process.go @@ -206,6 +206,17 @@ Example: `, "file-batch-exec") } +func getGoVersion() string { + goModFile, err := os.ReadFile("go.mod") + if err != nil { + log.Fatalf(`Faild to read "go.mod": %v`, err) + os.Exit(1) + } + goModVersionRegex := regexp.MustCompile(`go \d+\.\d+`) + goModVersionLine := goModVersionRegex.Find(goModFile) + return string(goModVersionLine[3:]) +} + func newFileCollectorFromMainOptions(mainOptions map[string]string) (fc *fileCollector, err error) { fileFilter := mainOptions["file-filter"] if fileFilter == "" { @@ -270,7 +281,7 @@ func main() { log.Print("the -d option is not supported by gitea-fmt") } cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-l"), containsString(subArgs, "-w"))) - cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", "1.17"}, substArgs...))) + cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...))) case "misspell": cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("MISSPELL_PACKAGE")}, substArgs...))) default: |