Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofmt on CI #471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
3 changes: 2 additions & 1 deletion bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build ignore
//go:build ignore
// +build ignore

package main

Expand Down
3 changes: 2 additions & 1 deletion install_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build CI
//go:build CI
// +build CI

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/alias/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/args/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/compiled/custom.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// Compiled package description.
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/context/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/func.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_nonwindows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage && !windows
// +build mage,!windows

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/invalid_alias/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/keep_flag/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/list/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// This is a comment on the package which should get turned into output with the
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mageimport/oneline/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package sametarget
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/pkg/mage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package pkg

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
2 changes: 1 addition & 1 deletion mage/testdata/mixed_lib_files/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

package lib

func Build() {]}
func Build() {}
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/mage_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mixed_lib_files/subdir/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/mage_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/namespaces/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/no_default/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/onlyStdLib/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/panic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setdir/setdir.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setworkdir/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/signals/signals.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/transitiveDeps/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/wrong_dep/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
20 changes: 12 additions & 8 deletions mg/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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.
//
Expand Down
4 changes: 2 additions & 2 deletions mg/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/alias.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/func.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion parse/testdata/importself/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
2 changes: 1 addition & 1 deletion parse/testdata/importself/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import "fmt"

func Stuff() {
fmt.Println("stuff")
}
}
1 change: 1 addition & 0 deletions parse/testdata/repeating_synopsis.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion parse/testdata/subcommand_1.9.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage,go1.9
//go:build mage && go1.9
// +build mage,go1.9

package main

Expand Down
1 change: 1 addition & 0 deletions parse/testdata/subcommands.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
23 changes: 12 additions & 11 deletions sh/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down