diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca01cee..5300832 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,90 +7,28 @@ 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@v1 - with: - go-version: 1.20.5 - - 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@v1 - with: - go-version: 1.20.5 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.53.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 + with: + allowed_repositories: "" 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.20.5 - - 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 @@ -102,20 +40,12 @@ 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 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 diff --git a/.golangci.yml b/.golangci.yml index f07f682..083e85d 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 @@ -11,13 +11,14 @@ 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 check-blank: false govet: - check-shadowing: true + enable: + - shadow settings: printf: funcs: @@ -25,27 +26,46 @@ 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 + 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: 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" + lll: + line-length: 160 misspell: locale: US unparam: @@ -58,79 +78,47 @@ linters-settings: for-loops: false 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: - # - rowserrcheck + - depguard + - revive + - rowserrcheck - goheader - bodyclose - - deadcode - dogsled - dupl - errcheck @@ -141,43 +129,30 @@ linters: - gocyclo - gofmt - goimports - - golint - gosec - gosimple - govet - ineffassign - - interfacer - # - lll + - lll - misspell - nakedret - - scopelint - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - # - unused - - varcheck + - 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 text: "Function 'TestParsePortRange' is too long" + - path: pkg/api/networkservice + linters: + - gosec + text: "G115" 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= 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" )