Skip to content

Commit 3fa1ef2

Browse files
pratap0007tekton-robot
authored andcommitted
Makefile: fix lint-go with workflow version and project Go toolchain
This patch updates Makefile to use GOLANGCI_VERSION from ci.yaml (fallback to tools/go.mod) and GOTOOLCHAIN from go.mod when installing so golangci-lint is built with the project’s Go version also adds inline comments to skip gosec and revive lint. Signed-off-by: Shiv Verma <shverma@redhat.com>
1 parent db9af24 commit 3fa1ef2

9 files changed

Lines changed: 14 additions & 9 deletions

File tree

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ M = $(shell printf "\033[34;1m🐱\033[0m")
1212
TIMEOUT_UNIT = 5m
1313
TIMEOUT_E2E = 20m
1414

15-
# Get golangci_version from tools/go.mod to eliminate the manual bump
16-
GOLANGCI_VERSION = $(shell cat tools/go.mod | grep golangci-lint | awk '{ print $$3 }')
15+
# Get golangci version from workflow to match CI; fallback to tools/go.mod
16+
GOLANGCI_VERSION = $(or $(shell yq '.jobs.linting.steps[] | select(.name == "golangci-lint") | .with.version' .github/workflows/ci.yaml 2>/dev/null),$(shell grep 'golangci/golangci-lint/v2' tools/go.mod | awk '{print $$3}'))
1717

1818
YAML_FILES := $(shell find . -type f -regex ".*y[a]ml" -print)
1919

@@ -96,14 +96,14 @@ test: test-unit ## run all tests
9696
.PHONY: lint
9797
lint: lint-go goimports lint-yaml ## run all linters
9898

99-
GOLANGCILINT = $(BIN)/golangci-lint
99+
GOLANGCILINT = $(or $(GOLANGCILINT_BIN),$(BIN)/golangci-lint)
100100
$(BIN)/golangci-lint: ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION))
101-
cd tools; GOBIN=$(BIN) $(GO) install -mod=mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION)
101+
@mkdir -p $(BIN)
102+
GOTOOLCHAIN=go$$(grep '^go ' go.mod | awk '{print $$2}') GOBIN=$(BIN) $(GO) install -mod=mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION)
102103

103104
.PHONY: lint-go
104105
lint-go: | $(GOLANGCILINT) ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint
105106
$Q $(GOLANGCILINT) run --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --timeout 10m
106-
@rm -f $(GOLANGCILINT)
107107

108108
GOIMPORTS = $(BIN)/goimports
109109
$(GOIMPORTS): ; $(info $(M) getting goimports )

cmd/tkn/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func main() {
3939
}
4040

4141
// if we have found the plugin then sysexec it by replacing current process.
42+
// #nosec G702 -- exCmd is from our plugin discovery path, not user input
4243
if err := syscall.Exec(exCmd, append([]string{exCmd}, os.Args[2:]...), os.Environ()); err != nil {
4344
fmt.Fprintf(os.Stderr, "Command finished with error: %v", err)
4445
os.Exit(127)

pkg/cmd/version/version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//nolint:revive // package name matches stdlib by design
1516
package version
1617

1718
import (
@@ -216,6 +217,7 @@ func (cli *Client) getRelease(url string) (ghversion GHVersion, err error) {
216217
return ghversion, errors.Wrap(err, "failed to fetch the latest version")
217218
}
218219

220+
// #nosec G704 -- URL is from our release API, not user-controlled
219221
res, err := cli.httpClient.Do(req)
220222
defer func() {
221223
err := res.Body.Close()

pkg/cmd/version/version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package version
15+
package version //nolint:revive
1616

1717
import (
1818
"context"

pkg/log/log.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//nolint:revive // package name matches stdlib by design
1516
package log
1617

1718
import "k8s.io/apimachinery/pkg/runtime/schema"

pkg/log/writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package log
15+
package log //nolint:revive
1616

1717
import (
1818
"fmt"

pkg/plugins/plugins.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func GetAllTknPluginFromPaths() []string {
7171
continue
7272
}
7373
fpath := filepath.Join(path, file.Name())
74+
// #nosec G703 -- fpath is from filepath.Join with validated path
7475
info, err := os.Stat(fpath)
7576
if err != nil {
7677
continue

pkg/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package version
15+
package version //nolint:revive
1616

1717
import (
1818
"context"

pkg/version/version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package version
15+
package version //nolint:revive
1616

1717
import (
1818
"context"

0 commit comments

Comments
 (0)