From 983f01388de3ac34faa0433737ae41ef5f98c4fd Mon Sep 17 00:00:00 2001 From: denis-tingajkin Date: Thu, 12 Mar 2020 20:37:16 +0700 Subject: [PATCH] add initial CI --- .github/workflows/ci.yaml | 151 ++++++++++++++++++++++++++++++++++++ .gitignore | 3 + .go-header.yaml | 16 ++++ .golangci.yaml | 159 ++++++++++++++++++++++++++++++++++++++ .yamllint.yml | 13 ++++ code-of-conduct.md | 3 + staticcheck.conf | 10 +++ 7 files changed, 355 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .go-header.yaml create mode 100644 .golangci.yaml create mode 100644 .yamllint.yml create mode 100644 code-of-conduct.md create mode 100644 staticcheck.conf diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5c59768 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,151 @@ +--- +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@v1 + - 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@v1 + - name: shellcheck + uses: azohra/shell-linter@v0.2.0 + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Install gotestsum + run: go get gotest.tools/gotestsum@v0.4.0 + - name: Run tests + run: | + eval $(go env) + mkdir -p ~/junit/ + ${GOPATH}/bin/gotestsum --junitfile ~/junit/unit-tests.xml -- -race -short $(go list ./...) + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + env: + GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.23.2 + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - 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@v1 + - 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 + + restrictNSMDeps: + name: Restrict dependencies on github.com/networkservicemesh/* + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - 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/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@v1 + - 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 ) + license: + name: license header check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Install go-header + run: 'go get github.com/denis-tingajkin/go-header@v0.2.2' + - name: Run go-header + run: | + eval $(go env) + ${GOPATH}/bin/go-header + excludereplace: + name: Exclude Replace in go.mod + runs-on: ubuntu-latest + steps: + - name: Check out the code + uses: actions/checkout@v1 + - 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 + - test + if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' + steps: + - name: Check out the code + uses: actions/checkout@v1 + - 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/.gitignore b/.gitignore index 66fd13c..be19042 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +.idea/ +junit/ diff --git a/.go-header.yaml b/.go-header.yaml new file mode 100644 index 0000000..aaccf20 --- /dev/null +++ b/.go-header.yaml @@ -0,0 +1,16 @@ +--- +year: 2020 +goroutine-count: 6 +scope: + policy: "diff" + master-branch: "origin/master" +rules: + - template-path: ".license/template.txt" + paths: + - ".*[.]go$" + exclude-paths: + - ".*[.]pb" +custom-patterns: + - name: NSM COPYRIGHT HOLDERS + pattern: "Copyright (c) {YEAR} {COPYRIGHT HOLDER}" + separator: "\n//\n// " diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..14ab3a4 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,159 @@ +--- +run: + # concurrency: 6 + timeout: 1m + issues-exit-code: 1 + tests: true +linters-settings: + 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 + 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 + - 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 + - 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 + exclude-rules: diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..42111a1 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,13 @@ +--- +extends: default + +yaml-files: + - '*.yaml' + - '*.yml' + +rules: + truthy: disable + # 80 chars should be enough, but don't fail if a line is longer + line-length: disable + comments-indentation: + ignore: .circleci/config.yml diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 0000000..a64950c --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,3 @@ +# Code of Conduct + +We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 0000000..6b78d47 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,10 @@ +checks = ["all", "-ST1000", "-ST1016"] +initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", + "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", + "IP", "JSON", "NS", "NSM", "QPS", "RAM", "RPC", "SLA", + "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", + "UDP", "UI", "GID", "UID", "UUID", "URI", + "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", + "XSS"] +dot_import_whitelist = [] +http_status_code_whitelist = ["200", "400", "404", "500"]