aboutsummaryrefslogtreecommitdiffhomepage
path: root/magefile.go
diff options
context:
space:
mode:
Diffstat (limited to 'magefile.go')
-rw-r--r--magefile.go41
1 files changed, 9 insertions, 32 deletions
diff --git a/magefile.go b/magefile.go
index c8542dad7..d4c7b65de 100644
--- a/magefile.go
+++ b/magefile.go
@@ -185,42 +185,15 @@ func TestRace() error {
// Run gofmt linter
func Fmt() error {
- if !isGoLatest() {
+ if !isGoLatest() && !isUnix() {
return nil
}
- pkgs, err := hugoPackages()
+ s, err := sh.Output("./check_gofmt.sh")
if err != nil {
- return err
- }
- failed := false
- first := true
- for _, pkg := range pkgs {
- files, err := filepath.Glob(filepath.Join(pkg, "*.go"))
- if err != nil {
- return nil
- }
- for _, f := range files {
- // gofmt doesn't exit with non-zero when it finds unformatted code
- // so we have to explicitly look for output, and if we find any, we
- // should fail this target.
- s, err := sh.Output("gofmt", "-l", f)
- if err != nil {
- fmt.Printf("ERROR: running gofmt on %q: %v\n", f, err)
- failed = true
- }
- if s != "" {
- if first {
- fmt.Println("The following files are not gofmt'ed:")
- first = false
- }
- failed = true
- fmt.Println(s)
- }
- }
- }
- if failed {
- return errors.New("improperly formatted go files")
+ fmt.Println(s)
+ return fmt.Errorf("gofmt needs to be run: %s", err)
}
+
return nil
}
@@ -332,6 +305,10 @@ func isGoLatest() bool {
return strings.Contains(runtime.Version(), "1.21")
}
+func isUnix() bool {
+ return runtime.GOOS != "windows"
+}
+
func isCI() bool {
return os.Getenv("CI") != ""
}