diff --git a/.bingo/Variables.mk b/.bingo/Variables.mk index f28bbfd2f..d35c8eaf5 100644 --- a/.bingo/Variables.mk +++ b/.bingo/Variables.mk @@ -47,17 +47,11 @@ $(FLAEX): $(BINGO_DIR)/flaex.mod @echo "(re)installing $(GOBIN)/flaex-v0.2.0" @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=flaex.mod -o=$(GOBIN)/flaex-v0.2.0 "github.com/owncloud/flaex" -GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.35.2 +GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.37.1 $(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. - @echo "(re)installing $(GOBIN)/golangci-lint-v1.35.2" - @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.35.2 "github.com/golangci/golangci-lint/cmd/golangci-lint" - -GOLINT := $(GOBIN)/golint-v0.0.0-20201208152925-83fdc39ff7b5 -$(GOLINT): $(BINGO_DIR)/golint.mod - @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. - @echo "(re)installing $(GOBIN)/golint-v0.0.0-20201208152925-83fdc39ff7b5" - @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golint.mod -o=$(GOBIN)/golint-v0.0.0-20201208152925-83fdc39ff7b5 "golang.org/x/lint/golint" + @echo "(re)installing $(GOBIN)/golangci-lint-v1.37.1" + @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.37.1 "github.com/golangci/golangci-lint/cmd/golangci-lint" GOVERAGE := $(GOBIN)/goverage-v0.0.0-20180129164344-eec3514a20b5 $(GOVERAGE): $(BINGO_DIR)/goverage.mod @@ -118,10 +112,3 @@ $(REFLEX): $(BINGO_DIR)/reflex.mod @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. @echo "(re)installing $(GOBIN)/reflex-v0.3.0" @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=reflex.mod -o=$(GOBIN)/reflex-v0.3.0 "github.com/cespare/reflex" - -STATICCHECK := $(GOBIN)/staticcheck-v0.1.2 -$(STATICCHECK): $(BINGO_DIR)/staticcheck.mod - @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. - @echo "(re)installing $(GOBIN)/staticcheck-v0.1.2" - @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=staticcheck.mod -o=$(GOBIN)/staticcheck-v0.1.2 "honnef.co/go/tools/cmd/staticcheck" - diff --git a/.bingo/golangci-lint.mod b/.bingo/golangci-lint.mod index d1511a951..d08b8c8c0 100644 --- a/.bingo/golangci-lint.mod +++ b/.bingo/golangci-lint.mod @@ -2,4 +2,4 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT go 1.15 -require github.com/golangci/golangci-lint v1.35.2 // cmd/golangci-lint +require github.com/golangci/golangci-lint v1.37.1 // cmd/golangci-lint diff --git a/.bingo/golint.mod b/.bingo/golint.mod deleted file mode 100644 index 32231fdb3..000000000 --- a/.bingo/golint.mod +++ /dev/null @@ -1,5 +0,0 @@ -module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT - -go 1.15 - -require golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // golint diff --git a/.bingo/staticcheck.mod b/.bingo/staticcheck.mod deleted file mode 100644 index 47bf89308..000000000 --- a/.bingo/staticcheck.mod +++ /dev/null @@ -1,5 +0,0 @@ -module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT - -go 1.15 - -require honnef.co/go/tools v0.1.2 // cmd/staticcheck diff --git a/.bingo/variables.env b/.bingo/variables.env index d5a5711b4..2be895c4a 100644 --- a/.bingo/variables.env +++ b/.bingo/variables.env @@ -18,9 +18,7 @@ FILEB0X="${GOBIN}/fileb0x-v1.1.4" FLAEX="${GOBIN}/flaex-v0.2.0" -GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.35.2" - -GOLINT="${GOBIN}/golint-v0.0.0-20201208152925-83fdc39ff7b5" +GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.37.1" GOVERAGE="${GOBIN}/goverage-v0.0.0-20180129164344-eec3514a20b5" @@ -41,6 +39,3 @@ PROTOC_GEN_MICROWEB="${GOBIN}/protoc-gen-microweb-v0.0.0-20210224131655-d9b1137a PROTOC_GEN_OPENAPIV2="${GOBIN}/protoc-gen-openapiv2-v2.2.0" REFLEX="${GOBIN}/reflex-v0.3.0" - -STATICCHECK="${GOBIN}/staticcheck-v0.1.2" - diff --git a/.drone.star b/.drone.star index 7d8264d51..38526dd75 100644 --- a/.drone.star +++ b/.drone.star @@ -240,10 +240,10 @@ def testOcisModules(ctx): for module in config['modules']: pipelines.append(testOcisModule(ctx, module)) - coverage_upload = uploadCoverage(ctx) - coverage_upload['depends_on'] = getPipelineNames(pipelines) + scan_result_upload = uploadScanResults(ctx) + scan_result_upload['depends_on'] = getPipelineNames(pipelines) - return pipelines + [coverage_upload] + return pipelines + [scan_result_upload] def testPipelines(ctx): pipelines = [ @@ -264,29 +264,13 @@ def testPipelines(ctx): def testOcisModule(ctx, module): steps = makeGenerate(module) + [ { - 'name': 'vet', + 'name': 'golangci-lint', 'image': 'webhippie/golang:1.15', 'pull': 'always', 'commands': [ - 'make -C %s vet' % (module), - ], - 'volumes': [stepVolumeGoWebhippie,], - }, - { - 'name': 'staticcheck', - 'image': 'webhippie/golang:1.15', - 'pull': 'always', - 'commands': [ - 'make -C %s staticcheck' % (module), - ], - 'volumes': [stepVolumeGoWebhippie,], - }, - { - 'name': 'lint', - 'image': 'webhippie/golang:1.15', - 'pull': 'always', - 'commands': [ - 'make -C %s lint' % (module), + 'mkdir -p cache/checkstyle', + 'make -C %s ci-golangci-lint' % (module), + 'mv %s/checkstyle.xml cache/checkstyle/%s_checkstyle.xml' % (module, module), ], 'volumes': [stepVolumeGoWebhippie,], }, @@ -295,8 +279,9 @@ def testOcisModule(ctx, module): 'image': 'webhippie/golang:1.15', 'pull': 'always', 'commands': [ + 'mkdir -p cache/coverage', 'make -C %s test' % (module), - 'mv %s/coverage.out %s_coverage.out' % (module, module), + 'mv %s/coverage.out cache/coverage/%s_coverage.out' % (module, module), ], 'volumes': [stepVolumeGoWebhippie,], }, @@ -308,8 +293,8 @@ def testOcisModule(ctx, module): 'from_secret': 'cache_s3_endpoint' }, 'bucket': 'cache', - 'source': '%s_coverage.out' % (module), - 'target': '%s/%s/coverage' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), + 'source': 'cache/**/*', + 'target': '%s/%s' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), 'path_style': True, 'access_key': { 'from_secret': 'cache_s3_access_key' @@ -364,7 +349,7 @@ def buildOcisBinaryForTesting(ctx): 'volumes': [pipelineVolumeGoWebhippie], } -def uploadCoverage(ctx): +def uploadScanResults(ctx): sonar_env = { 'SONAR_TOKEN': { 'from_secret': 'sonar_token', @@ -377,26 +362,39 @@ def uploadCoverage(ctx): 'SONAR_PULL_REQUEST_KEY': '%s' % (ctx.build.ref.replace("refs/pull/", "").split("/")[0]), }) + repo_slug = ctx.build.source_repo if ctx.build.source_repo else ctx.repo.slug + return { 'kind': 'pipeline', 'type': 'docker', - 'name': 'upload-coverage', + 'name': 'upload-scan-results', 'platform': { 'os': 'linux', 'arch': 'amd64', }, + 'clone': { + 'disable': True, # Sonarcloud does not apply issues on already merged branch + }, 'steps': [ + { + 'name': 'clone', + 'image': 'alpine/git', + 'commands': [ + 'git clone https://github.com/%s.git .' % (repo_slug), + 'git checkout $DRONE_COMMIT', + ], + }, { 'name': 'sync-from-cache', - 'image': 'minio/mc:RELEASE.2020-12-10T01-26-17Z', + 'image': 'minio/mc:RELEASE.2021-02-19T05-34-40Z', 'environment': { - 'MC_HOST_cache': { + 'MC_HOST_cachebucket': { 'from_secret': 'cache_s3_connection_url' } }, 'commands': [ - 'mkdir -p coverage', - 'mc mirror cache/cache/%s/%s/coverage coverage/' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), + 'mkdir -p cache', + 'mc mirror cachebucket/cache/%s/%s/cache cache/' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), ] }, { @@ -411,7 +409,7 @@ def uploadCoverage(ctx): }, { 'name': 'sonarcloud', - 'image': 'sonarsource/sonar-scanner-cli:latest', + 'image': 'sonarsource/sonar-scanner-cli', 'pull': 'always', 'environment': sonar_env, }, @@ -419,12 +417,12 @@ def uploadCoverage(ctx): 'name': 'purge-cache', 'image': 'minio/mc:RELEASE.2020-12-10T01-26-17Z', 'environment': { - 'MC_HOST_cache': { + 'MC_HOST_cachebucket': { 'from_secret': 'cache_s3_connection_url' } }, 'commands': [ - 'mc rm --recursive --force cache/cache/%s/%s/coverage' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), + 'mc rm --recursive --force cachebucket/cache/%s/%s/cache' % (ctx.repo.slug, ctx.build.commit + '-${DRONE_BUILD_NUMBER}'), ] }, ], diff --git a/.gitignore b/.gitignore index 40cf88772..21bda20ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ */coverage.out +*/checkstyle.xml ocis/config/identifier-registration.yaml */bin diff --git a/.make/go.mk b/.make/go.mk index 7b2cd8519..5aa7d0b94 100644 --- a/.make/go.mk +++ b/.make/go.mk @@ -68,17 +68,13 @@ go-mod-tidy: fmt: gofmt -s -w $(SOURCES) -.PHONY: vet -vet: - go vet $(PACKAGES) +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) + $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E golint -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) -.PHONY: staticcheck -staticcheck: $(STATICCHECK) - $(STATICCHECK) -tags '$(TAGS)' $(PACKAGES) - -.PHONY: lint -lint: $(GOLINT) - for PKG in $(PACKAGES); do $(GOLINT) -set_exit_status $$PKG || exit 1; done; +.PHONY: ci-golangci-lint +ci-golangci-lint: $(GOLANGCI_LINT) + $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E golint -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) --timeout 10m0s --issues-exit-code 0 --out-format checkstyle > checkstyle.xml .PHONY: test test: $(GOVERAGE) diff --git a/docs/Makefile b/docs/Makefile index fb099039b..b9d5f5e4f 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -23,7 +23,7 @@ docs-init: .PHONY: docs-serve docs-serve: docs-init docs-generate docs-copy ## serve docs with hugo @bash -c "trap 'trap - SIGINT SIGTERM ERR; $(MAKE) --no-print-directory docs-sync-stop; exit 0' SIGINT SIGTERM ERR; $(MAKE) --no-print-directory docs-sync-start && $(MAKE) --no-print-directory hugo-serve" - + .PHONY: test test: $(HUGO) @cd hugo && $(HUGO) diff --git a/idp/Makefile b/idp/Makefile index c79308fa4..2976dbaa4 100644 --- a/idp/Makefile +++ b/idp/Makefile @@ -35,13 +35,13 @@ assets: yarn-build \ assets/identifier/static: mkdir -p assets/identifier/static -LOGO_URL = https://raw.githubusercontent.com/owncloud/assets/main/logo.svg +LOGO_URL = https://raw.githubusercontent.com/owncloud/assets/main/logo.svg .PHONY: assets/identifier/static/logo.svg # force overwrite assets/identifier/static/logo.svg: curl -o assets/identifier/static/logo.svg ${LOGO_URL} -FAVICON_URL = https://raw.githubusercontent.com/owncloud/assets/main/favicon.ico +FAVICON_URL = https://raw.githubusercontent.com/owncloud/assets/main/favicon.ico .PHONY: assets/identifier/static/favicon.ico # force overwrite assets/identifier/static/favicon.ico: diff --git a/sonar-project.properties b/sonar-project.properties index 7866b049e..9993e7675 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -22,14 +22,18 @@ sonar.links.issue=https://github.com/owncloud/ocis/issues sonar.sources=. # Pull Requests -sonar.pullrequest.provider=GitHub +sonar.pullrequest.provider=github sonar.pullrequest.github.repository=owncloud/ocis sonar.pullrequest.base=${env.SONAR_PULL_REQUEST_BASE} sonar.pullrequest.branch=${env.SONAR_PULL_REQUEST_BRANCH} sonar.pullrequest.key=${env.SONAR_PULL_REQUEST_KEY} # Properties specific to language plugins: -sonar.go.coverage.reportPaths=coverage/*_coverage.out +sonar.go.coverage.reportPaths=cache/coverage/* +# golangci-lint does not support wildcard +# https://github.com/SonarSource/slang/blob/85b05160bc1b31c6072a35f8818da4376b107afa/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/GolangCILintReportSensor.java#L37 +# https://github.com/SonarSource/slang/blob/85b05160bc1b31c6072a35f8818da4376b107afa/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/AbstractReportSensor.java#L76-L90 +sonar.go.golangci-lint.reportPaths=cache/checkstyle/accounts_checkstyle.xml,cache/checkstyle/glauth_checkstyle.xml,cache/checkstyle/graph_checkstyle.xml,cache/checkstyle/graph-explorer_checkstyle.xml,cache/checkstyle/idp_checkstyle.xml,cache/checkstyle/ocis_checkstyle.xml,cache/checkstyle/ocis-pkg_checkstyle.xml,cache/checkstyle/ocs_checkstyle.xml,cache/checkstyle/onlyoffice_checkstyle.xml,cache/checkstyle/proxy_checkstyle.xml,cache/checkstyle/settings_checkstyle.xml,cache/checkstyle/storage_checkstyle.xml,cache/checkstyle/store_checkstyle.xml,cache/checkstyle/thumbnails_checkstyle.xml,cache/checkstyle/web_checkstyle.xml,cache/checkstyle/webdav_checkstyle.xml # Exclude files sonar.exclusions=**/third_party,docs/**,changelog/**,*/pkg/assets/embed.go,idp/assets/identifier/**,**/package.json,**/rollup.config.js,CHANGELOG.md,**/pkg/proto/**/*.pb.*,deployments/**,tests/**,vendor-bin/**,README.md diff --git a/thumbnails/pkg/thumbnail/storage/filesystem.go b/thumbnails/pkg/thumbnail/storage/filesystem.go index 844cdd3b7..96fb28485 100644 --- a/thumbnails/pkg/thumbnail/storage/filesystem.go +++ b/thumbnails/pkg/thumbnail/storage/filesystem.go @@ -1,6 +1,7 @@ package storage import ( + "crypto/md5" "crypto/sha256" "encoding/hex" "io/ioutil" @@ -112,6 +113,9 @@ func (s *FileSystem) storeImage(key string, img []byte) (string, error) { // /users/<3 characters>/<3 characters>/<48 characters>/ // This will balance the folders in setups with many users. func (s *FileSystem) userDir(username string) string { + mh := md5.New() + mh.Write([]byte("something")) + hash := sha256.New224() if _, err := hash.Write([]byte(username)); err != nil { s.logger.Fatal().Err(err).Msg("failed to create hash")