diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dc45c2e..0a10a54c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,3 +32,18 @@ jobs: go test -tags CI -race ./... env: GOPATH: /home/runner/go + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Lint + uses: Jerome1337/gofmt-action@v1.0.5 + with: + gofmt-path: './' + gofmt-flags: '-l -d' diff --git a/bootstrap.go b/bootstrap.go index c37f6fc8..136aa66a 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -1,4 +1,5 @@ -//+build ignore +//go:build ignore +// +build ignore package main diff --git a/install_test.go b/install_test.go index d7923c8d..8e3cf9e7 100644 --- a/install_test.go +++ b/install_test.go @@ -1,4 +1,5 @@ -//+build CI +//go:build CI +// +build CI package main diff --git a/mage/testdata/alias/magefile.go b/mage/testdata/alias/magefile.go index d68326d3..97b86f6d 100644 --- a/mage/testdata/alias/magefile.go +++ b/mage/testdata/alias/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/args/magefile.go b/mage/testdata/args/magefile.go index e7f7b262..de0f262e 100644 --- a/mage/testdata/args/magefile.go +++ b/mage/testdata/args/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/command.go b/mage/testdata/command.go index ac2b7350..74b2b845 100644 --- a/mage/testdata/command.go +++ b/mage/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/compiled/custom.go b/mage/testdata/compiled/custom.go index 41aaabe3..2a1bdfd1 100644 --- a/mage/testdata/compiled/custom.go +++ b/mage/testdata/compiled/custom.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage // Compiled package description. diff --git a/mage/testdata/context/context.go b/mage/testdata/context/context.go index aaf08fbe..876bc520 100644 --- a/mage/testdata/context/context.go +++ b/mage/testdata/context/context.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/error.go b/mage/testdata/error.go index bb98a097..a639fd60 100644 --- a/mage/testdata/error.go +++ b/mage/testdata/error.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/func.go b/mage/testdata/func.go index b33fe4b3..503ccdf7 100644 --- a/mage/testdata/func.go +++ b/mage/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/goos_magefiles/magefile_nonwindows.go b/mage/testdata/goos_magefiles/magefile_nonwindows.go index 420f4f89..3be85d86 100644 --- a/mage/testdata/goos_magefiles/magefile_nonwindows.go +++ b/mage/testdata/goos_magefiles/magefile_nonwindows.go @@ -1,3 +1,4 @@ +//go:build mage && !windows // +build mage,!windows package main diff --git a/mage/testdata/goos_magefiles/magefile_windows.go b/mage/testdata/goos_magefiles/magefile_windows.go index 1b8248bb..15173da0 100644 --- a/mage/testdata/goos_magefiles/magefile_windows.go +++ b/mage/testdata/goos_magefiles/magefile_windows.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/invalid_alias/magefile.go b/mage/testdata/invalid_alias/magefile.go index e3f985f1..59e013eb 100644 --- a/mage/testdata/invalid_alias/magefile.go +++ b/mage/testdata/invalid_alias/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/keep_flag/magefile.go b/mage/testdata/keep_flag/magefile.go index ce97b22a..1ab8e212 100644 --- a/mage/testdata/keep_flag/magefile.go +++ b/mage/testdata/keep_flag/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/list/command.go b/mage/testdata/list/command.go index ae36007e..3795cec4 100644 --- a/mage/testdata/list/command.go +++ b/mage/testdata/list/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage // This is a comment on the package which should get turned into output with the diff --git a/mage/testdata/mageimport/magefile.go b/mage/testdata/mageimport/magefile.go index f37a8953..ec69c14c 100644 --- a/mage/testdata/mageimport/magefile.go +++ b/mage/testdata/mageimport/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/oneline/magefile.go b/mage/testdata/mageimport/oneline/magefile.go index fdbbc213..d8b5c9fe 100644 --- a/mage/testdata/mageimport/oneline/magefile.go +++ b/mage/testdata/mageimport/oneline/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go index 5c585304..edf4078b 100644 --- a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package sametarget diff --git a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go index aebacbb6..c93b2d2f 100644 --- a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/tagged/magefile.go b/mage/testdata/mageimport/tagged/magefile.go index c04d933b..9efe85fe 100644 --- a/mage/testdata/mageimport/tagged/magefile.go +++ b/mage/testdata/mageimport/tagged/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/tagged/pkg/mage.go b/mage/testdata/mageimport/tagged/pkg/mage.go index d5991482..014e2fa2 100644 --- a/mage/testdata/mageimport/tagged/pkg/mage.go +++ b/mage/testdata/mageimport/tagged/pkg/mage.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package pkg diff --git a/mage/testdata/main.go b/mage/testdata/main.go index a3f23b4b..53c564a8 100644 --- a/mage/testdata/main.go +++ b/mage/testdata/main.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/mage/testdata/mixed_lib_files/lib.go b/mage/testdata/mixed_lib_files/lib.go index 908909ab..bab93c64 100644 --- a/mage/testdata/mixed_lib_files/lib.go +++ b/mage/testdata/mixed_lib_files/lib.go @@ -5,4 +5,4 @@ package lib -func Build() {]} +func Build() {} diff --git a/mage/testdata/mixed_lib_files/mage_helpers.go b/mage/testdata/mixed_lib_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_lib_files/mage_helpers.go +++ b/mage/testdata/mixed_lib_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/magefile.go b/mage/testdata/mixed_lib_files/magefile.go index 3c30feba..ce6b9c47 100644 --- a/mage/testdata/mixed_lib_files/magefile.go +++ b/mage/testdata/mixed_lib_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/subdir/magefile.go b/mage/testdata/mixed_lib_files/subdir/magefile.go index 20a9fe49..63584509 100644 --- a/mage/testdata/mixed_lib_files/subdir/magefile.go +++ b/mage/testdata/mixed_lib_files/subdir/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mixed_main_files/mage_helpers.go b/mage/testdata/mixed_main_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_main_files/mage_helpers.go +++ b/mage/testdata/mixed_main_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_main_files/magefile.go b/mage/testdata/mixed_main_files/magefile.go index f4248496..63584509 100644 --- a/mage/testdata/mixed_main_files/magefile.go +++ b/mage/testdata/mixed_main_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/namespaces/magefile.go b/mage/testdata/namespaces/magefile.go index d1ae0456..c2b8f4da 100644 --- a/mage/testdata/namespaces/magefile.go +++ b/mage/testdata/namespaces/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/no_default/magefile.go b/mage/testdata/no_default/magefile.go index 4e3d4941..a0046682 100644 --- a/mage/testdata/no_default/magefile.go +++ b/mage/testdata/no_default/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/onlyStdLib/command.go b/mage/testdata/onlyStdLib/command.go index 3822a80a..e1c4b825 100644 --- a/mage/testdata/onlyStdLib/command.go +++ b/mage/testdata/onlyStdLib/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/panic.go b/mage/testdata/panic.go index 3714c0d5..2cd54a9e 100644 --- a/mage/testdata/panic.go +++ b/mage/testdata/panic.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/setdir/setdir.go b/mage/testdata/setdir/setdir.go index 3fc20d83..9b8571d6 100644 --- a/mage/testdata/setdir/setdir.go +++ b/mage/testdata/setdir/setdir.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/setworkdir/magefile.go b/mage/testdata/setworkdir/magefile.go index 2eb93235..d0c0ab78 100644 --- a/mage/testdata/setworkdir/magefile.go +++ b/mage/testdata/setworkdir/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/signals/signals.go b/mage/testdata/signals/signals.go index 96d62552..07d0e942 100644 --- a/mage/testdata/signals/signals.go +++ b/mage/testdata/signals/signals.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/transitiveDeps/magefile.go b/mage/testdata/transitiveDeps/magefile.go index 379d6eab..336f1c0d 100644 --- a/mage/testdata/transitiveDeps/magefile.go +++ b/mage/testdata/transitiveDeps/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/wrong_dep/magefile.go b/mage/testdata/wrong_dep/magefile.go index 8da309d8..30c441d7 100644 --- a/mage/testdata/wrong_dep/magefile.go +++ b/mage/testdata/wrong_dep/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mg/deps.go b/mg/deps.go index f0c2509b..b00aca3e 100644 --- a/mg/deps.go +++ b/mg/deps.go @@ -72,10 +72,12 @@ func SerialCtxDeps(ctx context.Context, fns ...interface{}) { // CtxDeps runs the given functions as dependencies of the calling function. // Dependencies must only be of type: -// func() -// func() error -// func(context.Context) -// func(context.Context) error +// +// func() +// func() error +// func(context.Context) +// func(context.Context) error +// // Or a similar method on a mg.Namespace type. // Or an mg.Fn interface. // @@ -148,10 +150,12 @@ func checkFns(fns []interface{}) []Fn { // Deps runs the given functions in parallel, exactly once. Dependencies must // only be of type: -// func() -// func() error -// func(context.Context) -// func(context.Context) error +// +// func() +// func() error +// func(context.Context) +// func(context.Context) error +// // Or a similar method on a mg.Namespace type. // Or an mg.Fn interface. // diff --git a/mg/fn_test.go b/mg/fn_test.go index 8ca481c8..d1fb2827 100644 --- a/mg/fn_test.go +++ b/mg/fn_test.go @@ -117,11 +117,11 @@ func TestFuncCheck(t *testing.T) { } defer func() { - if r := recover(); r !=nil { + if r := recover(); r != nil { t.Error("expected a nil function argument to be handled gracefully") } }() - _, _, err = checkF(nil, []interface{}{1,2}) + _, _, err = checkF(nil, []interface{}{1, 2}) if err == nil { t.Error("expected a nil function argument to be invalid") } diff --git a/parse/testdata/alias.go b/parse/testdata/alias.go index 0c5d3136..6b1c111f 100644 --- a/parse/testdata/alias.go +++ b/parse/testdata/alias.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/command.go b/parse/testdata/command.go index d8e6f74a..ab54994c 100644 --- a/parse/testdata/command.go +++ b/parse/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/func.go b/parse/testdata/func.go index 94927756..ffc81fda 100644 --- a/parse/testdata/func.go +++ b/parse/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/importself/magefile.go b/parse/testdata/importself/magefile.go index e1978e52..4440b9dd 100644 --- a/parse/testdata/importself/magefile.go +++ b/parse/testdata/importself/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/parse/testdata/importself/targets.go b/parse/testdata/importself/targets.go index 268fc2fa..eaa800c0 100644 --- a/parse/testdata/importself/targets.go +++ b/parse/testdata/importself/targets.go @@ -4,4 +4,4 @@ import "fmt" func Stuff() { fmt.Println("stuff") -} \ No newline at end of file +} diff --git a/parse/testdata/repeating_synopsis.go b/parse/testdata/repeating_synopsis.go index bcac14d4..602516f1 100644 --- a/parse/testdata/repeating_synopsis.go +++ b/parse/testdata/repeating_synopsis.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/subcommand_1.9.go b/parse/testdata/subcommand_1.9.go index 21d1d95d..ee820ae5 100644 --- a/parse/testdata/subcommand_1.9.go +++ b/parse/testdata/subcommand_1.9.go @@ -1,4 +1,5 @@ -//+build mage,go1.9 +//go:build mage && go1.9 +// +build mage,go1.9 package main diff --git a/parse/testdata/subcommands.go b/parse/testdata/subcommands.go index 4eb31bdb..502f00e2 100644 --- a/parse/testdata/subcommands.go +++ b/parse/testdata/subcommands.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/sh/cmd.go b/sh/cmd.go index 312de65a..7ddf73b8 100644 --- a/sh/cmd.go +++ b/sh/cmd.go @@ -16,19 +16,19 @@ import ( // useful for creating command aliases to make your scripts easier to read, like // this: // -// // in a helper file somewhere -// var g0 = sh.RunCmd("go") // go is a keyword :( +// // in a helper file somewhere +// var g0 = sh.RunCmd("go") // go is a keyword :( // -// // somewhere in your main code -// if err := g0("install", "github.com/gohugo/hugo"); err != nil { -// return err -// } +// // somewhere in your main code +// if err := g0("install", "github.com/gohugo/hugo"); err != nil { +// return err +// } // // Args passed to command get baked in as args to the command when you run it. // Any args passed in when you run the returned function will be appended to the // original args. For example, this is equivalent to the above: // -// var goInstall = sh.RunCmd("go", "install") goInstall("github.com/gohugo/hugo") +// var goInstall = sh.RunCmd("go", "install") goInstall("github.com/gohugo/hugo") // // RunCmd uses Exec underneath, so see those docs for more details. func RunCmd(cmd string, args ...string) func(args ...string) error { @@ -133,17 +133,18 @@ func run(env map[string]string, stdout, stderr io.Writer, cmd string, args ...st c.Stdout = stdout c.Stdin = os.Stdin - var quoted []string - for i := range args { - quoted = append(quoted, fmt.Sprintf("%q", args[i])); - } // To protect against logging from doing exec in global variables if mg.Verbose() { + var quoted []string + for i := range args { + quoted = append(quoted, fmt.Sprintf("%q", args[i])) + } log.Println("exec:", cmd, strings.Join(quoted, " ")) } err = c.Run() return CmdRan(err), ExitStatus(err), err } + // CmdRan examines the error to determine if it was generated as a result of a // command running via os/exec.Command. If the error is nil, or the command ran // (even if it exited with a non-zero exit code), CmdRan reports true. If the