-
Notifications
You must be signed in to change notification settings - Fork 11
/
golangcilint.go
88 lines (69 loc) · 2.58 KB
/
golangcilint.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package golang
import (
"fmt"
"path/filepath"
"github.com/talos-systems/kres/internal/dag"
"github.com/talos-systems/kres/internal/output/dockerfile"
"github.com/talos-systems/kres/internal/output/dockerfile/step"
"github.com/talos-systems/kres/internal/output/golangci"
"github.com/talos-systems/kres/internal/output/makefile"
"github.com/talos-systems/kres/internal/project/meta"
)
// GolangciLint provides golangci-lint.
type GolangciLint struct {
dag.BaseNode
meta *meta.Options
Version string
}
// NewGolangciLint builds golangci-lint node.
func NewGolangciLint(meta *meta.Options) *GolangciLint {
meta.SourceFiles = append(meta.SourceFiles, ".golangci.yml")
meta.BuildArgs = append(meta.BuildArgs, "GOLANGCILINT_VERSION")
return &GolangciLint{
BaseNode: dag.NewBaseNode("lint-golangci-lint"),
meta: meta,
Version: "v1.47.3",
}
}
// CompileGolangci implements golangci.Compiler.
func (lint *GolangciLint) CompileGolangci(output *golangci.Output) error {
output.Enable()
output.CanonicalPath(lint.meta.CanonicalPath)
return nil
}
// CompileMakefile implements makefile.Compiler.
func (lint *GolangciLint) CompileMakefile(output *makefile.Output) error {
output.Target("lint-golangci-lint").Description("Runs golangci-lint linter.").
Script("@$(MAKE) target-$@")
output.VariableGroup(makefile.VariableGroupCommon).
Variable(makefile.OverridableVariable("GOLANGCILINT_VERSION", lint.Version))
return nil
}
// ToolchainBuild implements common.ToolchainBuilder hook.
func (lint *GolangciLint) ToolchainBuild(stage *dockerfile.Stage) error {
stage.
Step(step.Arg("GOLANGCILINT_VERSION")).
Step(step.Script(
fmt.Sprintf(
"go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \\\n"+
"\t&& mv /go/bin/golangci-lint %s/golangci-lint", lint.meta.BinPath),
))
return nil
}
// CompileDockerfile implements dockerfile.Compiler.
func (lint *GolangciLint) CompileDockerfile(output *dockerfile.Output) error {
output.Stage("lint-golangci-lint").
Description("runs golangci-lint").
From("base").
Step(step.Copy(".golangci.yml", ".")).
Step(step.Env("GOGC", "50")).
Step(step.Run("golangci-lint", "run", "--config", ".golangci.yml").
MountCache(filepath.Join(lint.meta.CachePath, "go-build")).
MountCache(filepath.Join(lint.meta.CachePath, "golangci-lint")).
MountCache(filepath.Join(lint.meta.GoPath, "pkg")),
)
return nil
}