From 1e577942ffa2fc7f1d387a905f427d2d87f34065 Mon Sep 17 00:00:00 2001 From: Aisuko Date: Wed, 25 Oct 2023 02:53:46 +0000 Subject: [PATCH] Fixed CI workflow Signed-off-by: GitHub --- .github/workflows/ci.yml | 61 ++++++++----- .gitignore | 3 +- .golangci.yml | 182 +++++++++++---------------------------- Makefile | 40 ++------- adapter/oam.go | 2 +- codecov.yml | 68 --------------- coverage.txt | 1 + 7 files changed, 103 insertions(+), 254 deletions(-) delete mode 100644 codecov.yml create mode 100644 coverage.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9073ad8..7c48a37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,9 @@ -name: Default Meshery Adapter Library Workflow +name: Default Meshery Adapter Library CI on: push: branches: - - '**' - tags: - - 'v*' + - 'master' pull_request: branches: - 'master' @@ -13,26 +11,49 @@ on: jobs: golangci: name: golangci-lint - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@vmaster + - uses: actions/setup-go@v4 with: go-version: '1.19' - check-latest: true + cache: true + cache-dependency-path: go.sum - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.52 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - args: --exclude=G306 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true + version: latest + - name: Run golangci-lint + run: make lint + tidy: + name: tidy + needs: [ golangci ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@vmaster + - uses: actions/setup-go@v4 + with: + go-version: '1.19' + cache: true + cache-dependency-path: go.sum + - name: tidy + run: make tidy + codecov: + name: codecov + needs: [ tidy ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@vmaster + - uses: actions/setup-go@v4 + with: + go-version: '1.19' + cache: true + cache-dependency-path: go.sum + - name: test + run: make test + - name: Upload covergae to Codecov + if: github.repository == 'meshery/meshery-adapter-library' + uses: codecov/codecov-action@v3 + with: + files: ./coverage.out + flags: unittests diff --git a/.gitignore b/.gitignore index 41f2034..ce411b8 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ meshops.proto **errorutil_analyze_summary.json **errorutil_errors_export.json -# End of https://www.toptal.com/developers/gitignore/api/go \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/go +codecov.yml diff --git a/.golangci.yml b/.golangci.yml index c9e76d0..cd12884 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,144 +1,64 @@ linters-settings: - depguard: - list-type: blacklist - packages: - # logging is allowed only by logutils.Log, logrus - # is allowed to use only in logutils package - - github.com/sirupsen/logrus - packages-with-error-message: - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" - dupl: - threshold: 100 - exhaustive: - default-signifies-exhaustive: false - funlen: - lines: 100 - statements: 50 + go-mod-tidy: + enabled: true gci: - local-prefixes: github.com/golangci/golangci-lint + enabled: true + max-len: 120 + line-length: 120 goconst: - min-len: 2 - min-occurrences: 2 + enabled: true gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - - whyNoLint - - wrapperFunc - gocyclo: - min-complexity: 15 - goimports: - local-prefixes: github.com/golangci/golangci-lint - golint: - min-confidence: 0 - gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: argument,case,condition,return - gosec: - settings: - exclude: -G204 + enabled: true + disable: + - parallelize + - nesting + - hugeParam + - hugeStruct + - nestParam + - prealloc govet: - check-shadowing: false - settings: - printf: - funcs: - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - lll: - line-length: 950 - maligned: - suggest-new: true - misspell: - locale: US - nolintlint: - allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped + enabled: true + check-shadowing: true + tests: true + golint: + enabled: true + min-confidence: 0.8 + unused: + enabled: true + check-exported: true + check-packages: true + check-generated: true + tests: true + allow-unused-type-export: true + cyclop: + enabled: true + average-strictness: 7 + scopelint: + enabled: true + tests: true + +# Configuration for golangci-lint that is suitable for a Kubernetes operator project built with Golang linters: - # please, do not use `enable-all`: it's deprecated and will be removed soon. - # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - # https://golangci-lint.run/usage/linters/ - disable-all: true - enable: - # TODO: consider continuously if more should be enabled. - # Can also be useful to run with more strict settings before commit locally, i.e. to test for TODOs (godox) - # - bodyclose - # - deadcode - - dogsled - # - dupl - - errcheck - # - exhaustive - # - funlen - # - goconst - # - gocritic - # - gocyclo - - gofmt - - goimports - # - golint - - gomodguard - - gosec - # - gomnd - # - goprintffuncname - - gosimple + enable-all: false + disable-all: false + linters: + - gci + - goconst + - gocritic - govet - - ineffassign - # - interfacer - - lll - - misspell - # - nakedret - # - nolintlint - # - rowserrcheck - # - scopelint - - staticcheck - # - structcheck - - stylecheck - - typecheck - # - unconvert - # - unparam + - golint - unused - # - varcheck - - whitespace - - asciicheck -# - gochecknoglobals -# - gocognit -# - godot -# - godox -# - goerr113 -# - maligned -# - nestif -# - prealloc -# - testpackage -# - wsl - -issues: - # Excluding configuration per-path, per-linter, per-text and per-source + - cyclop + - scopelint exclude-rules: - - path: _test\.go - linters: - - gomnd - - # https://github.com/go-critic/go-critic/issues/926 - - linters: - - gocritic - text: "unnecessaryDefer:" + - testpackage run: - skip-dirs: - - test/testdata_etc - - internal/cache - - internal/renameio - - internal/robustio timeout: 5m + enable-cache: true + skip-dirs: + - vendor + - bundle + - hack + - img \ No newline at end of file diff --git a/Makefile b/Makefile index f4e7eee..a858212 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,15 @@ -# Copyright Meshery Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +.PHONY: lint tidy verify -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif -.PHONY: tidy check-lint check-clean-cache tidy verify error - -error: - go run github.com/layer5io/meshkit/cmd/errorutil -d . analyze -i ./helpers -o ./helpers - -check-lint: - $(GOBIN)/golangci-lint run ./... - -check-clean-cache: - go clean - $(GOBIN)/golangci-lint cache clean +lint: + golangci-lint run -c .golangci.yml -v ./... tidy: go mod tidy - gofmt -w . - $(GOBIN)/goimports -w . verify: go mod verify - go vet ./... \ No newline at end of file + go vet ./... + +test: + go test --short ./... -race -coverprofile=coverage.txt -covermode=atomic diff --git a/adapter/oam.go b/adapter/oam.go index 6c7e1f7..07e8e65 100644 --- a/adapter/oam.go +++ b/adapter/oam.go @@ -109,7 +109,7 @@ func (or *OAMRegistrant) Register() error { } definitionMap := map[string]interface{}{} - if err := json.NewDecoder(definition).Decode(&definitionMap); err != nil { + if err = json.NewDecoder(definition).Decode(&definitionMap); err != nil { _ = definition.Close() return ErrJSONMarshal(err) } diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 60c9618..0000000 --- a/codecov.yml +++ /dev/null @@ -1,68 +0,0 @@ -codecov: - require_ci_to_pass: yes - -coverage: - # Do not need token here, because of the public repo here - # token: - # bot: - # ci: - # The age you want coverage reports to expire at(hours) - max_report_age: 24 - # Should Codecov wait for all other statues to pass before sending it's status. - require_ci_to_pass: yes - notify: - # How many uploaded reports Codecov should wait to receive before sending statuses - after_n_builds: 2 - # Should Codecov wait for all CI statuses to complete before sending ours. - wait_for_ci: yes - - # What precision do you want the coverage value to be - precision: 2 - # Which direction to you want to round the coverage value - round: down - range: "50...100" - - status: - project: - default: - # basic - target: auto - # Allow the coverage to drop by X%, and posting a success status. - threshold: 0% - base: auto - # advanced - branches: - - master - if_not_found: success - if_ci_failed: error - informational: false - only_pulls: false - api: - target: 50% - flags: - - api - -flags: - # filer the folder(s) you wish to measure by that flag - api: - # only inlcude files in the pkg - paths: - - / - # help only update coverage on tests that were run,If you do not test all of your repo code on each commit. - carryforward: true - -parsers: - # Here can add multiple language support - gcov: - branch_detection: - conditional: yes - loop: yes - method: no - macro: no - -comment: - layout: "reach,diff,flags,files,tree" - behavior: default - require_changes: false - require_base: yes - require_head: yes diff --git a/coverage.txt b/coverage.txt new file mode 100644 index 0000000..79b28a0 --- /dev/null +++ b/coverage.txt @@ -0,0 +1 @@ +mode: atomic