-
Notifications
You must be signed in to change notification settings - Fork 5
/
lint.go
114 lines (86 loc) · 2.17 KB
/
lint.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package mage
import (
"context"
"fmt"
"github.com/magefile/mage/mg"
)
type Lint mg.Namespace
func (Lint) All(ctx context.Context) {
mg.CtxDeps(
ctx,
Lint.Go,
Lint.Proto,
Lint.Helm,
)
}
func (Lint) Go(ctx context.Context) error {
fmt.Println("Running Go linter")
client, err := getDaggerClient(ctx)
if err != nil {
return err
}
defer client.Close()
src := getSource(client)
golangciLint := client.Container().From(GolangCILintImage)
golangciLint = golangciLint.
WithMountedDirectory("/src", src).
WithWorkdir("/src").
With(goCache(client))
// Set up the environment for the linter per the settings of each binary.
// This could lead to conflicts if the binaries have different settings.
for _, config := range binaries {
for key, value := range config.buildEnv {
golangciLint = golangciLint.WithEnvVariable(key, value)
}
for _, execStmt := range config.buildExecStmts {
golangciLint = golangciLint.WithExec(execStmt)
}
}
golangciLint = golangciLint.WithExec([]string{
"golangci-lint", "-v", "run", "--modules-download-mode", "readonly", "--timeout", "5m",
})
return printOutput(ctx, golangciLint)
}
func (Lint) Proto(ctx context.Context) error {
fmt.Println("Running Protobuf linter")
client, err := getDaggerClient(ctx)
if err != nil {
return err
}
defer client.Close()
src := getProtoSource(client)
protoLint := client.Container().From(ProtolintImage)
protoLint = protoLint.
WithMountedDirectory("/api", src).
WithWorkdir("/api")
protoLint = protoLint.WithExec([]string{
"lint", ".",
})
return printOutput(ctx, protoLint)
}
func (Lint) Helm(ctx context.Context) error {
fmt.Println("Running Helm linter")
client, err := getDaggerClient(ctx)
if err != nil {
return err
}
defer client.Close()
src := getChartsSource(client)
helmLint := client.Container().From(HelmImage)
helmLint = helmLint.
WithMountedDirectory("/charts", src).
WithWorkdir("/charts")
entries, err := src.Entries(ctx)
if err != nil {
return err
}
for _, entry := range entries {
helmLint = helmLint.WithExec([]string{
"lint", entry,
})
if err := printOutput(ctx, helmLint); err != nil {
return err
}
}
return nil
}