From 0a1884a7db073d49919b937d2679ceb607d037d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan-Luis=20de=20Sousa-Valadas=20Casta=C3=B1o?= Date: Tue, 6 May 2025 16:53:18 +0200 Subject: [PATCH 1/4] Run make lint in a docker container like in k0s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Golangci-lint <1.58.0 doesn't work because mdm, and >=1.58.0 have several linter issues. I tried older versions of golang too but I couldn't find a working combination. Lint has been broken for a while, merge this as is and fix the linting issues in separate PR. Signed-off-by: Juan-Luis de Sousa-Valadas Castaño --- .gitignore | 2 ++ Makefile | 44 ++++++++++++++++++++++++++++++++++++-------- build/Dockerfile | 22 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 build/Dockerfile diff --git a/.gitignore b/.gitignore index e1534127..d19e8c54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +/build/cache/* test/rigtest test/footloose.yaml test/Library test/.ssh test/*.iid +/.rigbuild.docker-image.k0s diff --git a/Makefile b/Makefile index 6efa1d05..ff7b4148 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,38 @@ GO_TESTS := $(shell find . -type f -name '*_test.go') INT_TESTS := $(shell git ls-files test/) +alpine_version = 3.21 +alpine_patch_version = $(alpine_version).3 +go_version = 1.24.2 +golang_buildimage=docker.io/library/golang:$(go_version)-alpine$(alpine_version) + +GOLANG_IMAGE ?= $(golang_buildimage) + +RIG_GO_BUILD_CACHE ?= build/cache +DOCKER ?= docker +BUILD_UID ?= $(shell id -u) +BUILD_GID ?= $(shell id -g) + +$(RIG_GO_BUILD_CACHE): + mkdir -p -- '$@' + +.rigbuild.docker-image.k0s: build/Dockerfile | $(RIG_GO_BUILD_CACHE) + $(DOCKER) build --progress=plain --iidfile '$@' \ + --build-arg BUILDIMAGE=$(GOLANG_IMAGE) \ + -t rigbuild.docker-image.k0s - Date: Tue, 6 May 2025 17:10:55 +0200 Subject: [PATCH 2/4] Fix linter issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan-Luis de Sousa-Valadas Castaño --- protocol/ssh/signals.go | 4 ++-- remotefs/posixfs.go | 3 ++- remotefs/withname.go | 24 ++++++++++++++++-------- sshconfig/printer.go | 4 ++-- sshconfig/set.go | 6 +++--- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/protocol/ssh/signals.go b/protocol/ssh/signals.go index e43d4b0d..a781bcbc 100644 --- a/protocol/ssh/signals.go +++ b/protocol/ssh/signals.go @@ -57,8 +57,8 @@ func termSizeWNCH() []byte { binary.BigEndian.PutUint32(size, 40) binary.BigEndian.PutUint32(size[4:], 80) } else { - binary.BigEndian.PutUint32(size, uint32(cols)) - binary.BigEndian.PutUint32(size[4:], uint32(rows)) + binary.BigEndian.PutUint32(size, uint32(cols)) // #nosec G115 -- ignore "integer overflow conversion int -> uint32" + binary.BigEndian.PutUint32(size[4:], uint32(rows)) // #nosec G115 -- ignore "integer overflow conversion int -> uint32" } return size diff --git a/remotefs/posixfs.go b/remotefs/posixfs.go index 483c9b02..cf5e6a39 100644 --- a/remotefs/posixfs.go +++ b/remotefs/posixfs.go @@ -154,7 +154,8 @@ func posixBitsToFileMode(bits int64) fs.FileMode { } // Mapping permission bits - mode |= fs.FileMode(bits & 0o777) // Owner, group, and other permissions + // Owner, group, and other permissions + mode |= fs.FileMode(bits & 0o777) // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64" // Mapping special permission bits if bits&0o4000 != 0 { // Set-user-ID diff --git a/remotefs/withname.go b/remotefs/withname.go index 33e437ab..7f4b9e65 100644 --- a/remotefs/withname.go +++ b/remotefs/withname.go @@ -3,14 +3,22 @@ package remotefs import "io/fs" const ( - OpClose = "close" // OpClose Close operation - OpOpen = "open" // OpOpen Open operation - OpRead = "read" // OpRead Read operation - OpSeek = "seek" // OpSeek Seek operation - OpStat = "stat" // OpStat Stat operation - OpWrite = "write" // OpWrite Write operation - OpCopyTo = "copy-to" // OpCopyTo CopyTo operation - OpCopyFrom = "copy-from" // OpCopyFrom CopyFrom operation + // OpClose Close operation. + OpClose = "close" + // OpOpen Open operation. + OpOpen = "open" + // OpRead Read operation. + OpRead = "read" + // OpSeek Seek operation. + OpSeek = "seek" + // OpStat Stat operation. + OpStat = "stat" + // OpWrite Write operation. + OpWrite = "write" + // OpCopyTo CopyTo operation. + OpCopyTo = "copy-to" + // OpCopyFrom CopyFrom operation. + OpCopyFrom = "copy-from" ) type withPath struct { diff --git a/sshconfig/printer.go b/sshconfig/printer.go index 7f6cfeae..0d54fde5 100644 --- a/sshconfig/printer.go +++ b/sshconfig/printer.go @@ -128,9 +128,9 @@ func (p *printer) number(key string) (string, bool) { } if field, err := p.get(key, reflect.Uint); err == nil { if key == "StreamLocalBindMask" { - return "0" + strconv.FormatInt(int64(field.Uint()), 8), true + return "0" + strconv.FormatInt(int64(field.Uint()), 8), true // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64" } - return strconv.FormatInt(int64(field.Uint()), 10), true + return strconv.FormatInt(int64(field.Uint()), 10), true // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64" } return "", false } diff --git a/sshconfig/set.go b/sshconfig/set.go index 9e77883d..78c98545 100644 --- a/sshconfig/set.go +++ b/sshconfig/set.go @@ -1125,7 +1125,7 @@ func (s *Setter) expandToken(token string) (string, error) { //nolint:cyclop if f, err := s.get("Port", reflect.Uint); err == nil { if f.Uint() > 0 { - return strconv.Itoa(int(f.Uint())), nil + return strconv.Itoa(int(f.Uint())), nil // #nosec G115 -- ignore "integer overflow conversion uint64 -> int" } } if f, err := s.get("Port", reflect.String); err == nil { @@ -1349,7 +1349,7 @@ func (s *Setter) matchesHost(conditions ...string) (bool, error) { // matchesMatch checks if the Match directive conditions are met. func (s *Setter) matchesMatch(conditions ...string) (bool, error) { //nolint:funlen,cyclop // TODO extract functions log.Trace(context.Background(), "matching Match directive", "conditions", conditions) - for i := range len(conditions) { + for i := range conditions { condition := conditions[i] log.Trace(context.Background(), "matching Match directive", "condition", condition) var negate bool @@ -1607,7 +1607,7 @@ func (s *Setter) canonicalizeMaxDots() int { if md, err := s.get("CanonicalizeMaxDots", reflect.Int); err == nil { return int(md.Int()) } else if md, err := s.get("CanonicalizeMaxDots", reflect.Uint); err == nil { - return int(md.Uint()) + return int(md.Uint()) // #nosec G115 -- ignore "integer overflow conversion int64 -> uint64" } return 1 } From f64a0093a82503dce1bc65def612d9e6d6f20875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan-Luis=20de=20Sousa-Valadas=20Casta=C3=B1o?= Date: Tue, 6 May 2025 17:16:38 +0200 Subject: [PATCH 3/4] Modiy lint workflow so that it uses make lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan-Luis de Sousa-Valadas Castaño --- .github/workflows/golangci-lint.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 75d859b7..6c27ff2d 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -35,10 +35,6 @@ jobs: - name: Check go.mod/go.sum to be consistent run: go mod tidy -v && git diff --exit-code - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: latest - skip-cache: true - only-new-issues: false - args: --verbose + - name: Run linter + run: | + make lint From 25500b185f302088dbea8747d50be90919277bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan-Luis=20de=20Sousa-Valadas=20Casta=C3=B1o?= Date: Wed, 7 May 2025 13:14:17 +0200 Subject: [PATCH 4/4] Add make clean-gocache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan-Luis de Sousa-Valadas Castaño --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index ff7b4148..9b40e05d 100644 --- a/Makefile +++ b/Makefile @@ -52,3 +52,8 @@ GO_LINT_DIRS ?= $(shell ls -d */ | grep -v build/) lint: .rigbuild.docker-image.k0s $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 $(GO_ENV) golangci-lint run --verbose --build-tags=$(subst $(space),$(comma),$(BUILD_GO_TAGS)) $(GOLANGCI_LINT_FLAGS) $(GO_LINT_DIRS) + +.PHONY: clean-gocache +clean-gocache: + -chmod -R u+w -- '$(RIG_GO_BUILD_CACHE)/go/mod' + rm -rf -- '$(RIG_GO_BUILD_CACHE)/go'