-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add govulncheck to Go linters. Signed-off-by: Noel Georgi <[email protected]>
- Loading branch information
Showing
5 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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/siderolabs/kres/internal/dag" | ||
"github.com/siderolabs/kres/internal/output/dockerfile" | ||
"github.com/siderolabs/kres/internal/output/dockerfile/step" | ||
"github.com/siderolabs/kres/internal/output/makefile" | ||
"github.com/siderolabs/kres/internal/project/meta" | ||
) | ||
|
||
// GoVulnCheck provides GoVulnCheck linter. | ||
// | ||
//nolint:govet | ||
type GoVulnCheck struct { | ||
dag.BaseNode | ||
|
||
meta *meta.Options | ||
} | ||
|
||
// NewGoVulnCheck builds GoVulnCheck node. | ||
func NewGoVulnCheck(meta *meta.Options) *GoVulnCheck { | ||
return &GoVulnCheck{ | ||
BaseNode: dag.NewBaseNode("lint-govulncheck"), | ||
|
||
meta: meta, | ||
} | ||
} | ||
|
||
// CompileMakefile implements makefile.Compiler. | ||
func (lint *GoVulnCheck) CompileMakefile(output *makefile.Output) error { | ||
output.Target("lint-govulncheck").Description("Runs govulncheck linter."). | ||
Script("@$(MAKE) target-$@") | ||
|
||
return nil | ||
} | ||
|
||
// ToolchainBuild implements common.ToolchainBuilder hook. | ||
func (lint *GoVulnCheck) ToolchainBuild(stage *dockerfile.Stage) error { | ||
stage. | ||
Step(step.Script(fmt.Sprintf( | ||
`go install golang.org/x/vuln/cmd/govulncheck@latest \ | ||
&& mv /go/bin/govulncheck %s/govulncheck`, lint.meta.BinPath))) | ||
|
||
return nil | ||
} | ||
|
||
// CompileDockerfile implements dockerfile.Compiler. | ||
func (lint *GoVulnCheck) CompileDockerfile(output *dockerfile.Output) error { | ||
output.Stage("lint-govulncheck"). | ||
Description("runs govulncheck"). | ||
From("base"). | ||
Step(step.Script( | ||
`govulncheck ./...`, | ||
). | ||
MountCache(filepath.Join(lint.meta.CachePath, "go-build")). | ||
MountCache(filepath.Join(lint.meta.GoPath, "pkg"))) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/siderolabs/kres/internal/output/dockerfile" | ||
"github.com/siderolabs/kres/internal/output/makefile" | ||
"github.com/siderolabs/kres/internal/project/common" | ||
"github.com/siderolabs/kres/internal/project/golang" | ||
) | ||
|
||
func TestGoVulnCheckInterfaces(t *testing.T) { | ||
assert.Implements(t, (*dockerfile.Compiler)(nil), new(golang.GoVulnCheck)) | ||
assert.Implements(t, (*makefile.Compiler)(nil), new(golang.GoVulnCheck)) | ||
assert.Implements(t, (*common.ToolchainBuilder)(nil), new(golang.GoVulnCheck)) | ||
} |