From 5cc725504690480f904aa7750c98090111343858 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 17 Oct 2024 13:45:13 +0500 Subject: [PATCH 1/7] Update go to 1.23 Signed-off-by: Vladislav Byrgazov --- .github/workflows/ci.yaml | 10 +++++----- .golangci.yml | 30 +++++++----------------------- go.mod | 2 +- go.sum | 1 + 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca01cee..98cde32 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,9 +28,9 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: Setup Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: 1.20.5 + go-version: 1.23.2 - name: Build run: go build -race ./... - name: Test @@ -46,13 +46,13 @@ jobs: with: fetch-depth: 0 - name: Setup Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: 1.20.5 + go-version: 1.23.2 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.53.3 + version: v1.60.3 excludeFmtErrorf: name: exclude fmt.Errorf diff --git a/.golangci.yml b/.golangci.yml index f07f682..5e3ba2c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.17" + go: "1.23" timeout: 2m issues-exit-code: 1 tests: true @@ -17,7 +17,8 @@ linters-settings: check-type-assertions: false check-blank: false govet: - check-shadowing: true + enable: + - shadow settings: printf: funcs: @@ -25,27 +26,15 @@ linters-settings: - (github.com/sirupsen/logrus.FieldLogger).Warnf - (github.com/sirupsen/logrus.FieldLogger).Errorf - (github.com/sirupsen/logrus.FieldLogger).Fatalf - golint: - min-confidence: 0.8 goimports: local-prefixes: github.com/networkservicemesh/api gocyclo: min-complexity: 15 - maligned: - suggest-new: true dupl: threshold: 150 goconst: min-len: 2 min-occurrences: 2 - depguard: - list-type: blacklist - include-go-root: false - packages: - - errors - packages-with-error-message: - # specify an error message to output when a blacklisted package is used - - errors: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" misspell: locale: US unparam: @@ -56,6 +45,9 @@ linters-settings: simple: true range-loops: true for-loops: false + gosec: + excludes: + - G115 gocritic: enabled-checks: - appendAssign @@ -127,10 +119,8 @@ linters-settings: linters: disable-all: true enable: - # - rowserrcheck - goheader - bodyclose - - deadcode - dogsled - dupl - errcheck @@ -141,25 +131,19 @@ linters: - gocyclo - gofmt - goimports - - golint - gosec - gosimple - govet - ineffassign - - interfacer - # - lll - misspell - nakedret - - scopelint - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - # - unused - - varcheck - whitespace + - unused issues: exclude-use-default: false max-issues-per-linter: 0 diff --git a/go.mod b/go.mod index 1998f11..0723278 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/networkservicemesh/api -go 1.20 +go 1.23 require ( github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index a5ef9ef..cf44b5c 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From ec461e6ccb08c9216204bc0ca60c902698188a8f Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Mon, 11 Nov 2024 16:17:41 +0500 Subject: [PATCH 2/7] Update copyright-holder regexp Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 5e3ba2c..55646e7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,7 @@ linters-settings: values: regexp: company: .* - copyright-holder: Copyright \(c\) ({{year-range}}) {{company}}\n\n + copyright-holder: Copyright \(c\) ({{mod-year-range}}) {{company}}\n\n copyright-holders: ({{copyright-holder}})+ errcheck: check-type-assertions: false From 058345839b1f428c0a0c10f6cf53089bc1e662f7 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Mon, 11 Nov 2024 16:24:22 +0500 Subject: [PATCH 3/7] Fix set of enabled linters Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 55646e7..118e88e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -119,6 +119,7 @@ linters-settings: linters: disable-all: true enable: + - rowserrcheck - goheader - bodyclose - dogsled @@ -135,6 +136,7 @@ linters: - gosimple - govet - ineffassign + # - lll - misspell - nakedret - staticcheck @@ -142,25 +144,13 @@ linters: - typecheck - unconvert - unparam - - whitespace - unused + - whitespace issues: exclude-use-default: false max-issues-per-linter: 0 max-same-issues: 0 exclude-rules: - - path: pkg/api/networkservice/mechanism_helpers.go - linters: - - interfacer - text: "can be `github.com/golang/protobuf/proto.Message" - - path: pkg/api/networkservice/connection_helpers.go - linters: - - interfacer - text: "can be `github.com/golang/protobuf/proto.Message" - - path: pkg/api/networkservice/path_segment_helpers.go - linters: - - interfacer - text: "can be `github.com/golang/protobuf/proto.Message" - path: pkg/api/networkservice/connectioncontext_helpers_test.go linters: - funlen From c26cb4a158b2adb471b6a52fd689a90ef554b79e Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Tue, 12 Nov 2024 09:58:00 +0500 Subject: [PATCH 4/7] Fix go-version Signed-off-by: Vladislav Byrgazov --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 98cde32..6328995 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.23.2 + go-version: 1.23.3 - name: Build run: go build -race ./... - name: Test @@ -48,7 +48,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.23.2 + go-version: 1.23.3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: @@ -85,7 +85,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v1 with: - go-version: 1.20.5 + go-version: 1.23.3 - run: go mod tidy - name: Check for changes in go.mod or go.sum run: | @@ -102,7 +102,7 @@ jobs: version: '3.14.0' - uses: actions/setup-go@v1 with: - go-version: 1.20.5 + go-version: 1.23.3 - name: Generate files run: go generate ./... - name: Check for changes in generated code From 5c5b19c068e467b6b1f63901ce5136172f9b0169 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Tue, 12 Nov 2024 16:49:49 +0500 Subject: [PATCH 5/7] Reuse jobs from .github Signed-off-by: Vladislav Byrgazov --- .github/workflows/ci.yaml | 100 ++++++-------------------------------- 1 file changed, 14 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6328995..6e5021d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,90 +7,26 @@ on: - 'release/**' jobs: yamllint: - name: yamllint - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - name: yaml-lint - uses: ibiqlik/action-yamllint@v1 - with: - config_file: .ci/yamllint.yml - strict: true + uses: networkservicemesh/.github/.github/workflows/yamllint.yaml@main + with: + config_file: .ci/yamllint.yml build-and-test: - name: build and test - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: 1.23.3 - - name: Build - run: go build -race ./... - - name: Test - run: go test -race ./... + uses: networkservicemesh/.github/.github/workflows/build-and-test.yaml@main + with: + os: '["ubuntu-latest", "macos-latest", "windows-latest"]' golangci-lint: - name: golangci-lint - runs-on: ubuntu-latest - if: github.repository != 'networkservicemesh/cmd-template' - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: 1.23.3 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.60.3 + uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main - excludeFmtErrorf: - name: exclude fmt.Errorf - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Exclude fmt.Errorf - run: | - if grep -r --include=*.go fmt.Errorf . ; then - echo "Please use errors.Errorf (or errors.New or errors.Wrap or errors.Wrapf) as appropriate rather than fmt.Errorf" - exit 1 - fi + exclude-fmt-errorf: + uses: networkservicemesh/.github/.github/workflows/exclude-fmt-errorf.yaml@main - restrictNSMDeps: - name: Restrict dependencies on github.com/networkservicemesh/* - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Restrict dependencies on github.com/networkservicemesh/* - run: | - for i in $(grep github.com/networkservicemesh/ go.mod | grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[^ ]*\).*;\1;g');do - echo Dependency on "${i}" is forbidden - exit 1 - done + restrict-nsm-deps: + uses: networkservicemesh/.github/.github/workflows/restrict-nsm-deps.yaml@main checkgomod: - name: check go.mod and go.sum - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v1 - with: - go-version: 1.23.3 - - run: go mod tidy - - name: Check for changes in go.mod or go.sum - run: | - git diff --name-only --exit-code go.mod || ( echo "Run go tidy" && false ) - git diff --name-only --exit-code go.sum || ( echo "Run go tidy" && false ) + uses: networkservicemesh/.github/.github/workflows/checkgomod.yaml@main gogenerate: name: Check generated files @@ -109,13 +45,5 @@ jobs: run: | git diff -- '*.pb.go' || (echo "Rerun go generate ./... locally and resubmit" && exit -1) - excludereplace: - name: Exclude replace in go.mod - runs-on: ubuntu-latest - steps: - - name: Check out the code - uses: actions/checkout@v2 - - name: Exclude replace in go.mod - run: | - grep ^replace go.mod || exit 0 - exit 1 + exclude-replace: + uses: networkservicemesh/.github/.github/workflows/exclude-replace.yaml@main From 80654b3badd74b9d58ca6b4770611e036ca87b90 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Tue, 12 Nov 2024 16:52:45 +0500 Subject: [PATCH 6/7] Fix estrict-nsm-deps workflow Signed-off-by: Vladislav Byrgazov --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6e5021d..5300832 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,8 @@ jobs: restrict-nsm-deps: uses: networkservicemesh/.github/.github/workflows/restrict-nsm-deps.yaml@main + with: + allowed_repositories: "" checkgomod: uses: networkservicemesh/.github/.github/workflows/checkgomod.yaml@main From d9b3092ee2de7144ea9856fc9f92e72aec8cddc1 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 14 Nov 2024 09:41:06 +0500 Subject: [PATCH 7/7] Improve golangci config Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 75 ++++++++++--------- .../mechanisms/kernel/helpers.go | 3 +- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 118e88e..083e85d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,6 +26,35 @@ linters-settings: - (github.com/sirupsen/logrus.FieldLogger).Warnf - (github.com/sirupsen/logrus.FieldLogger).Errorf - (github.com/sirupsen/logrus.FieldLogger).Fatalf + depguard: + rules: + main: + deny: + - pkg: "errors" + desc: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" + revive: + confidence: 0.8 + rules: + - name: exported + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: increment-decrement + - name: var-naming + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: superfluous-else + - name: unreachable-code goimports: local-prefixes: github.com/networkservicemesh/api gocyclo: @@ -35,6 +64,8 @@ linters-settings: goconst: min-len: 2 min-occurrences: 2 + lll: + line-length: 160 misspell: locale: US unparam: @@ -45,80 +76,46 @@ linters-settings: simple: true range-loops: true for-loops: false - gosec: - excludes: - - G115 gocritic: enabled-checks: - - appendAssign - - assignOp - appendCombine - - argOrder - - badCall - - badCond - boolExprSimplify - builtinShadow - - captLocal - - caseOrder - - codegenComment - - commentFormatting - commentedOutCode - commentedOutImport - - defaultCaseOrder - - deprecatedComment - docStub - - dupArg - - dupBranchBody - - dupCase - dupImport - - dupSubExpr - - elseif - emptyFallthrough - emptyStringTest - equalFold - evalOrder - - exitAfterDefer - - flagDeref - - flagName - hexLiteral - hugeParam - - ifElseChain - importShadow - indexAlloc - initClause - methodExprCall - nestingReduce - - newDeref - nilValReturn - octalLiteral - - offBy1 - paramTypeCombine - - ptrToRefParam - rangeExprCopy - rangeValCopy - - regexpMust - regexpPattern - - singleCaseSwitch - - sloppyLen - sloppyReassign - stringXbytes - - switchTrue - typeAssertChain - - typeSwitchVar - typeUnparen - unlabelStmt - unnamedResult - unnecessaryBlock - - underef - - unlambda - - unslice - - valSwap - weakCond - - wrapperFunc - yodaStyleExpr linters: disable-all: true enable: + - depguard + - revive - rowserrcheck - goheader - bodyclose @@ -136,7 +133,7 @@ linters: - gosimple - govet - ineffassign - # - lll + - lll - misspell - nakedret - staticcheck @@ -155,3 +152,7 @@ issues: linters: - funlen text: "Function 'TestParsePortRange' is too long" + - path: pkg/api/networkservice + linters: + - gosec + text: "G115" diff --git a/pkg/api/networkservice/mechanisms/kernel/helpers.go b/pkg/api/networkservice/mechanisms/kernel/helpers.go index 1565208..6c53f29 100644 --- a/pkg/api/networkservice/mechanisms/kernel/helpers.go +++ b/pkg/api/networkservice/mechanisms/kernel/helpers.go @@ -23,12 +23,13 @@ package kernel import ( "bytes" - "errors" "net" "strconv" "strings" "text/template" + "github.com/pkg/errors" + "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" )