-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
58 lines (44 loc) · 1.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"os"
"os/exec"
"strings"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
)
func installedInPath(name string) bool {
cmd := exec.Command("which", name)
outBytes, err := cmd.Output()
return err == nil && strings.TrimSpace(string(outBytes)) != ""
}
func failf(format string, args ...interface{}) {
log.Errorf(format, args...)
os.Exit(1)
}
func main() {
packages := os.Getenv("packages")
log.Infof("Configs:")
log.Printf("- packages: %s", packages)
if packages == "" {
failf("Required input not defined: packages")
}
if !installedInPath("golint") {
cmd := command.New("go", "get", "-u", "golang.org/x/lint/golint")
cmd.SetDir("/") // workaround for https://github.com/golang/go/issues/30515 to install the package globally
log.Infof("\nInstalling golint")
log.Donef("$ %s", cmd.PrintableCommandArgs())
if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil {
failf("Failed to install golint: %s", out)
}
}
log.Infof("\nRunning golint...")
for _, p := range strings.Split(packages, "\n") {
cmd := command.New("golint", "-set_exit_status", p)
log.Printf("$ %s", cmd.PrintableCommandArgs())
if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil || strings.TrimSpace(out) != "" {
log.Errorf("golint failed")
log.Printf(out)
failf("golint failed: %s", err)
}
}
}