From dd34adce883226da312e8154c7baa5cde6d7f762 Mon Sep 17 00:00:00 2001 From: Vasco Guita <33404234+vascoguita@users.noreply.github.com> Date: Tue, 22 Nov 2022 11:36:29 +0100 Subject: [PATCH] Migrate golangci-lint from Drone to GitHub Actions (#3466) Co-authored-by: Vasco Guita --- .drone.star | 12 -- .github/workflows/check-changelog.yml | 19 +-- .github/workflows/golangci-lint.yml | 29 +++++ .golangci.yaml | 113 ++++++++++++------ .../unreleased/enhancement-golangci-lint.md | 3 + go.mod | 3 +- go.sum | 2 - 7 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 changelog/unreleased/enhancement-golangci-lint.md diff --git a/.drone.star b/.drone.star index 85987da72f..adfcb9e557 100644 --- a/.drone.star +++ b/.drone.star @@ -7,15 +7,6 @@ def makeStep(target): ], } -def lintStep(): - return { - "name": "lint", - "image": "registry.cern.ch/docker.io/golangci/golangci-lint:v1.42.1", - "commands": [ - "golangci-lint run --timeout 3m0s", - ], - } - def cloneOc10TestReposStep(): return { "name": "clone-oC10-test-repos", @@ -134,7 +125,6 @@ def buildAndPublishDocker(): ], }, makeStep("ci"), - lintStep(), { "name": "publish-docker-reva-latest", "pull": "always", @@ -245,7 +235,6 @@ def buildOnly(): "dockerfile": "Dockerfile.revad", }, }, - lintStep(), ], } @@ -300,7 +289,6 @@ def release(): }, "steps": [ makeStep("ci"), - lintStep(), { "name": "create-dist", "image": "registry.cern.ch/docker.io/library/golang:1.19", diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml index ecbb967524..673f506a9b 100644 --- a/.github/workflows/check-changelog.yml +++ b/.github/workflows/check-changelog.yml @@ -23,23 +23,7 @@ jobs: uses: actions/setup-go@v3.3.0 with: go-version-file: go.mod - - name: Setup Golang caches - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Cache calens - id: cache-calens - uses: actions/cache@v3 - with: - path: $(go env GOPATH)/bin/calens - key: ${{ runner.os }}-calens - - name: clone calens - if: steps.cache-calens.outputs.cache-hit != 'true' + - name: Clone calens uses: actions/checkout@v3 with: repository: restic/calens @@ -47,7 +31,6 @@ jobs: fetch-depth: 0 ref: v0.2.0 - name: Install calens - if: steps.cache-calens.outputs.cache-hit != 'true' run: cd calens && go install - name: Check if changelog exists run: | diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000000..74c00cb221 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,29 @@ +name: golangci-lint +on: + pull_request: + paths-ignore: + - ".github/**" + - "Makefile" + - "tools/**" + - "docs/**" + - "tests/**" + - ".drone.star" + - ".drone.env" + - ".fossa.yml" + workflow_dispatch: + +jobs: + golangci: + name: lint + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v3.1.0 + - name: Setup Go environment + uses: actions/setup-go@v3.3.0 + with: + go-version-file: go.mod + - name: Install golangci-lint + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1 + - name: Run golangci-lint + run: $(go env GOPATH)/bin/golangci-lint run diff --git a/.golangci.yaml b/.golangci.yaml index 6c9559020e..62ba978671 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,37 +1,78 @@ -issues: - exclude-rules: - - path: internal/http/interceptors/log/log.go - text: "SA1019:" - linters: - - staticcheck - - path: pkg/utils/utils.go - text: "SA1019:" - linters: - - staticcheck - # Exclude scopelint for tests files because of https://github.com/kyoh86/scopelint/issues/4 - - path: _test\.go - linters: - - scopelint +run: + timeout: 20m + linters: - enable: - - maligned - - bodyclose - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - - depguard - - golint - - goimports - - unconvert - - scopelint - - misspell - - gocritic - - prealloc - #- gosec + enable-all: true + disable: + - exhaustive # TODO: consider enabling the 'exhaustive' linter to check the exhaustiveness of enum switch statements and map literals. + - wrapcheck # TODO: consider enabling the 'wrapcheck' linter to check that errors from external packages are wrapped during return to help identify the error source during debugging. + - cyclop # TODO: consider enabling the 'cyclop' linter to calculate the cyclomatic complexities of functions/packages. + - varnamelen # TODO: consider enabling the 'varnamelen' linter to check that the length of a variable's name matches its usage scope. + - goimports # TODO: consider enabling the 'goimports' linter to fix imports and format the code in the same style as gofmt. + - testpackage # TODO: consider enabling the 'testpackage' linter to make sure that separate _test packages are used. + - gosec # TODO: consider enabling the 'gosec' linter to inspect source code for security problems. + - tagliatelle # TODO: consider enabling the 'tagliatelle' linter to check the struct tags. + - stylecheck # TODO: consider enabling the 'stylecheck' linter to enforce style rules. + - gofmt # TODO: consider enabling the 'gofmt' linter to check whether code was gofmt-ed. + - usestdlibvars # TODO: consider enabling the 'usestdlibvars' linter to detect the possibility to use variables/constants from the Go standard library. + - thelper # TODO: consider enabling the 'thelper' linter to detect golang test helpers without t.Helper() call and check the consistency of test helpers. + - staticcheck # TODO: consider enabling the 'staticcheck' linter to find bugs and performance issues, offer simplifications, and enforce style rules. + - predeclared # TODO: consider enabling the 'predeclared' linter to find code that shadows one of Go's predeclared identifiers. + - paralleltest # TODO: consider enabling the 'paralleltest' linter to detect missing usage of t.Parallel() method in Go test. + - ireturn # TODO: consider enabling the 'ireturn' linter to accept interfaces and return concrete types. + - nosprintfhostport # TODO: consider enabling the 'nosprintfhostport' linter to check for misuse of Sprintf to construct a host with port in a URL. + - nonamedreturns # TODO: consider enabling the 'nonamedreturns' linter to reports all named returns. + - gomnd # TODO: consider enabling the 'gomnd' linter to detect magic numbers. + - noctx # TODO: consider enabling the 'noctx' linter to find sending http request without context.Context. + - nlreturn # TODO: consider enabling the 'nlreturn' linter to check for a new line before return and branch statements to increase code clarity. + - nilnil # TODO: consider enabling the 'nilnil' linter to check that there is no simultaneous return of nil error and an invalid value. + - nilerr # TODO: consider enabling the 'nilerr' linter to find the code that returns nil even if it checks that the error is not nil. + - interfacebloat # TODO: consider enabling the 'interfacebloat' linter to check the number of methods inside an interface. + - goerr113 # TODO: consider enabling the 'goerr113' linter to check the errors handling expressions. + - gochecknoglobals # TODO: consider enabling the 'gochecknoglobals' linter to check that no global variables exist. + - forcetypeassert # TODO: consider enabling the 'forcetypeassert' linter to find forced type assertions. + - exhaustruct # TODO: consider enabling the 'exhaustruct' linter to check if all structure fields are initialized. + - execinquery # TODO: consider enabling the 'execinquery' linter to check query strings. + - errorlint # TODO: consider enabling the 'errorlint' linter to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - errname # TODO: consider enabling the 'errname' linter to check that sentinel errors are prefixed with the Err and error types are suffixed with the Error. + - wsl # TODO: consider enabling the 'wsl' linter to force the use of empty lines. + - nestif # TODO: consider enabling the 'nestif' linter to report deeply nested if statements. + - errchkjson # TODO: consider enabling the 'errchkjson' linter to checks types passed to the json encoding functions. + - contextcheck # TODO: consider enabling the 'contextcheck' linter to check whether the function uses a non-inherited context. + - asasalint # TODO: consider enabling the 'asasalint' linter to check for pass []any as any in variadic func(...any). + - containedctx # TODO: consider enabling the 'containedctx' linter to detect struct contained context.Context field. + - whitespace # TODO: consider enabling the 'whitespace' linter to detect leading and trailing whitespaces. + - unparam # TODO: consider enabling the 'unparam' linter to report unused function parameters. + - revive # TODO: consider enabling the 'revive' linter to configure custom rules and define a strict preset for enhancing development & code review processes. + - nakedret # TODO: consider enabling the 'nakedret' linter to find naked returns in functions greater than a specified function length. + - dupword # TODO: consider enabling the 'dupword' linter to check for duplicate words in the source code. + - makezero # TODO: consider enabling the 'makezero' linter to find slice declarations with non-zero initial length. + - lll # TODO: consider enabling the 'lll' linter to report long lines. + - gomoddirectives # TODO: consider enabling the 'gomoddirectives' linter to manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. + - gofumpt # TODO: consider enabling the 'gofumpt' linter to check whether code was gofumpt-ed. + - godox # TODO: consider enabling the 'godox' linter to detect FIXME, TODO and other comment keywords. + - godot # TODO: consider enabling the 'godot' linter to if comments end in a period. + - gocritic # TODO: consider enabling the 'gocritic' linter to check for bugs, performance and style issues. + - goconst # TODO: consider enabling the 'goconst' linter to find repeated strings that could be replaced by a constant. + - gocognit # TODO: consider enabling the 'gocognit' linter to compute and check the cognitive complexity of functions. + - gochecknoinits # TODO: consider enabling the 'gochecknoinits' linter to check that no init functions are present in Go code. + - gci # TODO: consider enabling the 'gci' linter to control golang package import order and make it always deterministic. + - funlen # TODO: consider enabling the 'funlen' linter to detect long functions. + - maintidx # TODO: consider enabling the 'maintidx' linter to measure the maintainability index of each function. + - gocyclo # TODO: consider enabling the 'gocyclo' linter to compute and check the cyclomatic complexity of functions. + - forbidigo # TODO: consider enabling the 'forbidigo' linter to forbid identifiers. + - dupl # TODO: consider enabling the 'dupl' linter to detect code cloning. + - dogsled # TODO: consider enabling the 'dogsled' linter to check assignments with too many blank identifiers (e.g. x, , , _, := f()). + - golint # deprecated since v1.41.0 - replaced by 'revive'. + - ifshort # deprecated since v1.48.0 + - structcheck # deprecated since v1.49.0 - replaced by 'unused'. + - exhaustivestruct # deprecated since v1.46.0 - replaced by 'exhaustruct'. + - deadcode # deprecated since v1.49.0 - replaced by 'unused'. + - interfacer # deprecated since v1.38.0 + - nosnakecase # deprecated since v1.48.1 - replaced by 'revive'(var-naming). + - varcheck # deprecated since v1.49.0 - replaced by 'unused'. + - maligned # deprecated since v1.38.0 - replaced by 'govet' 'fieldalignment'. + - scopelint # deprecated since v1.39.0 - replaced by 'exportloopref'. + - rowserrcheck # disabled because of generics - https://github.com/golangci/golangci-lint/issues/2649. + - sqlclosecheck # disabled because of generics - https://github.com/golangci/golangci-lint/issues/2649. + - wastedassign # disabled because of generics - https://github.com/golangci/golangci-lint/issues/2649. \ No newline at end of file diff --git a/changelog/unreleased/enhancement-golangci-lint.md b/changelog/unreleased/enhancement-golangci-lint.md new file mode 100644 index 0000000000..8c0f74f3ad --- /dev/null +++ b/changelog/unreleased/enhancement-golangci-lint.md @@ -0,0 +1,3 @@ +Enhancement: Migrate golangci-lint from Drone to GitHub Actions + +https://github.com/cs3org/reva/pull/3466 \ No newline at end of file diff --git a/go.mod b/go.mod index c576dc2d61..b817985528 100644 --- a/go.mod +++ b/go.mod @@ -17,10 +17,10 @@ require ( github.com/coreos/go-oidc v2.2.1+incompatible github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e github.com/cs3org/go-cs3apis v0.0.0-20221004162747-f20ee4756d90 - github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 github.com/dgraph-io/ristretto v0.1.0 github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59 github.com/gdexlab/go-render v1.0.1 + github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9 github.com/go-chi/chi/v5 v5.0.7 github.com/go-ldap/ldap/v3 v3.4.3 github.com/go-sql-driver/mysql v1.6.0 @@ -86,7 +86,6 @@ require ( github.com/dustin/go-humanize v1.0.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9 // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect diff --git a/go.sum b/go.sum index 386e5f7220..299d7e7c60 100644 --- a/go.sum +++ b/go.sum @@ -225,8 +225,6 @@ github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJff github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20221004162747-f20ee4756d90 h1:zYg2UzwpChLgXktwt7MJEMv46GQPtluifRnynkSw80Y= github.com/cs3org/go-cs3apis v0.0.0-20221004162747-f20ee4756d90/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= -github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=