From 5c72d915eeeb8d357a286f85faad9b93f389d8f8 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 28 Dec 2020 11:57:46 +0100 Subject: [PATCH 1/4] fix sonarcloud run for master, remove unneeded configs, rework makefile --- .drone.star | 21 +++++++++------- Makefile | 16 ++++++++++++- accounts/Makefile | 5 ++++ accounts/sonar-project.properties | 37 ----------------------------- glauth/Makefile | 5 ++++ konnectd/Makefile | 5 ++++ ocis-pkg/Makefile | 5 ++++ ocis/Makefile | 7 +++++- ocs/Makefile | 5 ++++ onlyoffice/Makefile | 5 ++++ proxy/Makefile | 5 ++++ settings/Makefile | 5 ++++ storage/Makefile | 5 ++++ store/Makefile | 5 ++++ thumbnails/Makefile | 5 ++++ thumbnails/sonar-project.properties | 35 --------------------------- web/Makefile | 5 ++++ webdav/Makefile | 5 ++++ 18 files changed, 99 insertions(+), 82 deletions(-) delete mode 100644 accounts/sonar-project.properties delete mode 100644 thumbnails/sonar-project.properties diff --git a/.drone.star b/.drone.star index 8191004fc2..6ea279acbf 100644 --- a/.drone.star +++ b/.drone.star @@ -368,6 +368,18 @@ def buildOcisBinaryForTesting(ctx): } def uploadCoverage(ctx): + sonar_env = { + 'SONAR_TOKEN': { + 'from_secret': 'sonar_token', + }, + } + if True or ctx.build.event == 'pull_request': + sonar_env.update({ + 'SONAR_PULL_REQUEST_BASE': '%s' % (ctx.build.target), + 'SONAR_PULL_REQUEST_BRANCH': '%s' % (ctx.build.source), + 'SONAR_PULL_REQUEST_KEY': '%s' % (ctx.build.ref.replace("refs/pull/", "").split("/")[0]), + }) + return { 'kind': 'pipeline', 'type': 'docker', @@ -404,14 +416,7 @@ def uploadCoverage(ctx): 'name': 'sonarcloud', 'image': 'sonarsource/sonar-scanner-cli', 'pull': 'always', - 'environment': { - 'SONAR_TOKEN': { - 'from_secret': 'sonar_token', - }, - 'SONAR_PULL_REQUEST_BASE': '%s' % ('master' if ctx.build.event == 'pull_request' else None), - 'SONAR_PULL_REQUEST_BRANCH': '%s' % (ctx.build.source if ctx.build.event == 'pull_request' else None), - 'SONAR_PULL_REQUEST_KEY': '%s' % (ctx.build.ref.replace("refs/pull/", "").split("/")[0] if ctx.build.event == 'pull_request' else None), - }, + 'environment': sonar_env, }, { 'name': 'purge-cache', diff --git a/Makefile b/Makefile index 9bef74b87c..25720e89e3 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,9 @@ OCIS_MODULES = \ glauth \ konnectd \ ocis \ - ocs \ ocis-pkg \ + ocs \ + onlyoffice \ proxy \ settings \ storage \ @@ -83,3 +84,16 @@ go-mod-tidy: @for mod in $(OCIS_MODULES); do \ $(MAKE) --no-print-directory -C $$mod go-mod-tidy; \ done + +.PHONY: test +test: + @for mod in $(OCIS_MODULES); do \ + $(MAKE) --no-print-directory -C $$mod test; \ + done + +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @for mod in $(OCIS_MODULES); do \ + echo -n "% coverage $$mod: "; $(MAKE) --no-print-directory -C $$mod go-coverage; \ + done diff --git a/accounts/Makefile b/accounts/Makefile index 7199e3d9b9..f806106dfb 100644 --- a/accounts/Makefile +++ b/accounts/Makefile @@ -96,6 +96,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/accounts/sonar-project.properties b/accounts/sonar-project.properties deleted file mode 100644 index ab347e8d63..0000000000 --- a/accounts/sonar-project.properties +++ /dev/null @@ -1,37 +0,0 @@ - -sonar.projectKey=owncloud_ocis-accounts -sonar.organization=owncloud-1 -sonar.projectName=ocis-accounts -sonar.projectVersion=1.0 -sonar.host.url=https://sonarcloud.io - -# ===================================================== -# Meta-data for the project -# ===================================================== - -sonar.links.homepage=https://github.com/owncloud/ocis-accounts -sonar.links.ci=https://cloud.drone.io/owncloud/ocis-accounts/ -sonar.links.scm=https://github.com/owncloud/ocis-accounts -sonar.links.issue=https://github.com/owncloud/ocis/accounts/issues - - -# ===================================================== -# Properties that will be shared amongst all modules -# ===================================================== - -# SQ standard properties -sonar.sources=. - -# Pull Requests -sonar.pullrequest.provider=GitHub -sonar.pullrequest.github.repository=owncloud/ocis-accounts -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.out - -# Exclude protobuf files -sonar.exclusions=pkg/proto/**, changelog/**, docs/**, package.json, rollup.config.js, changelog.md diff --git a/glauth/Makefile b/glauth/Makefile index 3920939c19..332711da01 100644 --- a/glauth/Makefile +++ b/glauth/Makefile @@ -91,6 +91,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/konnectd/Makefile b/konnectd/Makefile index b98c698d7d..5350363685 100644 --- a/konnectd/Makefile +++ b/konnectd/Makefile @@ -113,6 +113,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/ocis-pkg/Makefile b/ocis-pkg/Makefile index c399cefbb5..6a00a59f08 100644 --- a/ocis-pkg/Makefile +++ b/ocis-pkg/Makefile @@ -69,6 +69,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: build build: $(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./... diff --git a/ocis/Makefile b/ocis/Makefile index 77129659f4..e64ae29c64 100644 --- a/ocis/Makefile +++ b/ocis/Makefile @@ -95,9 +95,14 @@ changelog: ## generate changelog go run github.com/restic/calens -i ../changelog -t ../changelog/CHANGELOG.tmpl >| ../CHANGELOG.md .PHONY: test -test: ## run tests +test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) ## install go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/ocs/Makefile b/ocs/Makefile index a4a8cc6615..01ffc68230 100644 --- a/ocs/Makefile +++ b/ocs/Makefile @@ -92,6 +92,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/onlyoffice/Makefile b/onlyoffice/Makefile index f73eef2cce..1ae16b93f1 100644 --- a/onlyoffice/Makefile +++ b/onlyoffice/Makefile @@ -93,6 +93,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/proxy/Makefile b/proxy/Makefile index 59be234642..26f2cd2ba9 100644 --- a/proxy/Makefile +++ b/proxy/Makefile @@ -92,6 +92,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/settings/Makefile b/settings/Makefile index 63390b3a25..21b83e0587 100644 --- a/settings/Makefile +++ b/settings/Makefile @@ -95,6 +95,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/storage/Makefile b/storage/Makefile index c879e49296..eb5e2a08f4 100644 --- a/storage/Makefile +++ b/storage/Makefile @@ -93,6 +93,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/store/Makefile b/store/Makefile index dedc4ab67b..e7c3bc867d 100644 --- a/store/Makefile +++ b/store/Makefile @@ -92,6 +92,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/thumbnails/Makefile b/thumbnails/Makefile index 16a5e88e64..5c511015da 100644 --- a/thumbnails/Makefile +++ b/thumbnails/Makefile @@ -93,6 +93,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/thumbnails/sonar-project.properties b/thumbnails/sonar-project.properties deleted file mode 100644 index 299aef553d..0000000000 --- a/thumbnails/sonar-project.properties +++ /dev/null @@ -1,35 +0,0 @@ - -sonar.projectKey=owncloud_ocis-thumbnails -sonar.organization=owncloud-1 -sonar.projectName=ocis-thumbnails -sonar.projectVersion=1.0 -sonar.host.url=https://sonarcloud.io - -# ===================================================== -# Meta-data for the project -# ===================================================== - -sonar.links.homepage=https://github.com/owncloud/ocis-thumbnails -sonar.links.ci=https://cloud.drone.io/owncloud/ocis-thumbnails/ -sonar.links.scm=https://github.com/owncloud/ocis-thumbnails -sonar.links.issue=https://github.com/owncloud/ocis/thumbnails/issues - -# ===================================================== -# Properties that will be shared amongst all modules -# ===================================================== - -# SQ standard properties -sonar.sources=. - -# Pull Requests -sonar.pullrequest.provider=GitHub -sonar.pullrequest.github.repository=owncloud/ocis-thumbnails -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.out - -# Exclude protobuf files -sonar.exclusions=pkg/proto/**, changelog/**, docs/**, package.json, rollup.config.js, changelog.md diff --git a/web/Makefile b/web/Makefile index 41b6d054a5..83dc4d3672 100644 --- a/web/Makefile +++ b/web/Makefile @@ -92,6 +92,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) diff --git a/webdav/Makefile b/webdav/Makefile index b45e33afa9..0a7c637fe2 100644 --- a/webdav/Makefile +++ b/webdav/Makefile @@ -91,6 +91,11 @@ changelog: test: go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES) +.PHONY: go-coverage +go-coverage: + @if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi; + @go tool cover -func coverage.out | tail -1 | grep -Eo "[0-9]+\.[0-9]+" + .PHONY: install install: $(SOURCES) go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME) From e58b47e456b22800e2b2d7181f0cca42e49a4ac5 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 29 Dec 2020 15:28:35 +0100 Subject: [PATCH 2/4] ignore protobuf generated files and go test files --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 093549e311..ce8187868c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -33,4 +33,4 @@ sonar.go.coverage.reportPaths=coverage/*_coverage.out # Exclude files sonar.exclusions=changelog/**,*/pkg/assets/embed.go,konnectd/assets/identifier/**,**/package.json,**/rollup.config.js,CHANGELOG.md -sonar.coverage.exclusions=docs/**,**/third_party,**/pkg/proto/** +sonar.coverage.exclusions=docs/**,**/third_party,**/pkg/proto/*.pb.*,**/*_test.go From d87d1f4e82820a6a8b836e3a17e970e2dc38c8c3 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 30 Dec 2020 07:21:17 +0100 Subject: [PATCH 3/4] fix always true condition --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 6ea279acbf..236a1730ea 100644 --- a/.drone.star +++ b/.drone.star @@ -373,7 +373,7 @@ def uploadCoverage(ctx): 'from_secret': 'sonar_token', }, } - if True or ctx.build.event == 'pull_request': + if ctx.build.event == 'pull': sonar_env.update({ 'SONAR_PULL_REQUEST_BASE': '%s' % (ctx.build.target), 'SONAR_PULL_REQUEST_BRANCH': '%s' % (ctx.build.source), From 40537027580cbb162e0f75ea3266171db4c6119b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 30 Dec 2020 07:53:25 +0100 Subject: [PATCH 4/4] change pull to pull_request --- .drone.star | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.star b/.drone.star index 236a1730ea..2b4bba6cfd 100644 --- a/.drone.star +++ b/.drone.star @@ -199,9 +199,9 @@ def main(ctx): ] elif \ - (ctx.build.event == "pull" and '[docs-only]' in ctx.build.title) \ + (ctx.build.event == "pull_request" and '[docs-only]' in ctx.build.title) \ or \ - (ctx.build.event != "pull" and '[docs-only]' in (ctx.build.title + ctx.build.message)): + (ctx.build.event != "pull_request" and '[docs-only]' in (ctx.build.title + ctx.build.message)): # [docs-only] is not taken from PR messages, but from commit messages pipelines = [docs(ctx)] @@ -373,7 +373,7 @@ def uploadCoverage(ctx): 'from_secret': 'sonar_token', }, } - if ctx.build.event == 'pull': + if ctx.build.event == "pull_request": sonar_env.update({ 'SONAR_PULL_REQUEST_BASE': '%s' % (ctx.build.target), 'SONAR_PULL_REQUEST_BRANCH': '%s' % (ctx.build.source),