diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..df8015c3 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,160 @@ +--- +name: ci +on: pull_request +jobs: + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + - name: Install yamllint + run: pip install --user yamllint + - name: Run yamllint + run: ~/.local/bin/yamllint -c .yamllint.yml --strict . + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: shellcheck + uses: fkautz/shell-linter@v1.0.1 + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + build-win: + name: build-win + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + build-osx: + name: build-osx + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + env: + GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.28.1 + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Pull golangci-lint docker container + run: docker pull ${GOLANGCI_LINT_CONTAINER} + - name: Run golangci-lint + run: docker run --rm -v $(pwd):/app -w /app ${GOLANGCI_LINT_CONTAINER} golangci-lint run + + excludeFmtErrorf: + name: exclude fmt.Errorf + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Exclude fmt.Errorf + run: | + if grep -r --include=*.go --exclude=*.pb.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 + 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\/[a-zA-z\/]*\).*;\1;g' | sort -u);do + if [ "${i}" != "github.com/networkservicemesh/sdk" ] && [ "${i}" != "github.com/networkservicemesh/api" ]; then + echo Dependency on "${i}" is forbidden + exit 1 + fi + done + 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.13.4 + - 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 ) + gogenerate: + name: Check generated files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: arduino/setup-protoc@master + with: + version: '3.8.0' + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + - name: Install proto-gen-go + run: go get -u github.com/golang/protobuf/protoc-gen-go@v1.3.3 + - name: Install proto-gen-go + run: go get github.com/searKing/golang/tools/cmd/go-syncmap + - 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" && false ) + git diff -- '*.gen.go' || ( echo "Rerun go generate ./... locally and resubmit" && false ) + 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 + captureRunEnv: + name: Capture CI Run Env + runs-on: ubuntu-latest + steps: + - run: printenv + automerge: + name: automerge + runs-on: ubuntu-latest + needs: + - build + if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' + steps: + - name: Check out the code + uses: actions/checkout@v2 + - name: Fetch master + run: | + git remote -v + git fetch --depth=1 origin master + - name: Only allow go.mod and go.sum changes + run: | + find . -type f ! -name 'go.mod' ! -name 'go.sum' -exec git diff --exit-code origin/master -- {} + + - name: Automerge nsmbot PR + uses: ridedott/merge-me-action@master + with: + GITHUB_LOGIN: nsmbot + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-for-updates.yaml b/.github/workflows/pr-for-updates.yaml new file mode 100644 index 00000000..f7fddc30 --- /dev/null +++ b/.github/workflows/pr-for-updates.yaml @@ -0,0 +1,17 @@ +--- +name: Pull Request on update/* Branch Push +on: + push: + branches: + - update/* +jobs: + auto-pull-request: + name: Pull Request on update/* Branch Push + runs-on: ubuntu-latest + steps: + - name: pull-request-action + uses: vsoch/pull-request-action@master + env: + GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + BRANCH_PREFIX: "update/" + PULL_REQUEST_BRANCH: "master" diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..897c838b --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +# Test binary, built with `go test -c` +*.test +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.idea/ +junit/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..915ccefa --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,171 @@ +--- +run: + # concurrency: 6 + timeout: 2m + issues-exit-code: 1 + tests: true +linters-settings: + goheader: + template-path: ".license/template.txt" + values: + const: + year: 2020 + regexp: + year-range: ((\d\d\d\d-{{year}})|({{year}})) + company: .* + copyright-holder: Copyright \(c\) {{year-range}} {{company}}\n\n + copyright-holders: ({{copyright-holder}})+ + errcheck: + check-type-assertions: false + check-blank: false + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/sirupsen/logrus.FieldLogger).Infof + - (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/sdk + gocyclo: + min-complexity: 15 + maligned: + suggest-new: true + dupl: + threshold: 150 + funlen: + Lines: 100 + Statements: 50 + 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: + check-exported: false + nakedret: + max-func-lines: 30 + prealloc: + simple: true + range-loops: true + 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 + - 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 + - goheader + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + # - lll + - misspell + - nakedret + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + # - unused + - varcheck + - whitespace +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..94de7f5a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module sdk-k8s + +go 1.14