Skip to content

Commit bc53256

Browse files
yardenshoham6543
andauthored
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>
1 parent b9cd6fb commit bc53256

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

build/code-batch-process.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ Example:
206206
`, "file-batch-exec")
207207
}
208208

209+
func getGoVersion() string {
210+
goModFile, err := os.ReadFile("go.mod")
211+
if err != nil {
212+
log.Fatalf(`Faild to read "go.mod": %v`, err)
213+
os.Exit(1)
214+
}
215+
goModVersionRegex := regexp.MustCompile(`go \d+\.\d+`)
216+
goModVersionLine := goModVersionRegex.Find(goModFile)
217+
return string(goModVersionLine[3:])
218+
}
219+
209220
func newFileCollectorFromMainOptions(mainOptions map[string]string) (fc *fileCollector, err error) {
210221
fileFilter := mainOptions["file-filter"]
211222
if fileFilter == "" {
@@ -270,7 +281,7 @@ func main() {
270281
log.Print("the -d option is not supported by gitea-fmt")
271282
}
272283
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-l"), containsString(subArgs, "-w")))
273-
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", "1.17"}, substArgs...)))
284+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...)))
274285
case "misspell":
275286
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("MISSPELL_PACKAGE")}, substArgs...)))
276287
default:

0 commit comments

Comments
 (0)