aboutsummaryrefslogtreecommitdiffhomepage
path: root/magefile.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-01-30 11:43:20 +0100
committerBjørn Erik Pedersen <[email protected]>2024-01-30 20:12:19 +0100
commit5b7cb258ec26d7de690099f5dc39935b8d728155 (patch)
tree53544c8ab46e3fffda4a1e33c5d6e705183e2652 /magefile.go
parent80595bbe3e7901ecd6200e59d43af142c3c85b6b (diff)
downloadhugo-5b7cb258ec26d7de690099f5dc39935b8d728155.tar.gz
hugo-5b7cb258ec26d7de690099f5dc39935b8d728155.zip
Create default link and image render hooks
Fixes #11933
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") != ""
}