Peter Kurfer
c1c1667d9f
lint-pr runs golangci-lint, captures the result and uses it directly without temporary files It also allows to automatically retrieve the PRs base commit and run golangci-lint only against changes in the current PR
42 lines
608 B
Go
42 lines
608 B
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
"github.com/magefile/mage/sh"
|
|
)
|
|
|
|
func Lint(ctx context.Context) {
|
|
mg.CtxDeps(ctx, Generate)
|
|
mg.CtxDeps(ctx, Format)
|
|
mg.Deps(LintGo)
|
|
}
|
|
|
|
func LintGo() (err error) {
|
|
if IsPRBuild {
|
|
return lintGoPR()
|
|
}
|
|
|
|
return sh.RunV(
|
|
"golangci-lint",
|
|
"run",
|
|
"-v",
|
|
"--issues-exit-code=1",
|
|
)
|
|
}
|
|
|
|
func lintGoPR() error {
|
|
return GoRun(
|
|
"main.go",
|
|
"gitea",
|
|
"lint-pr",
|
|
"--from-pr-base",
|
|
fmt.Sprintf("--namespace=%s", repoOwner),
|
|
fmt.Sprintf("--repo=%s", repoName),
|
|
fmt.Sprintf("--pull-index=%d", prIndex),
|
|
)
|
|
}
|