Skip to content

Commit 1e5d0e1

Browse files
authored
Merge pull request #356 from sapcc/fix-coverage-report-action
fix coverage-report-action
2 parents 38f0bbf + 0827c6a commit 1e5d0e1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ run-shellcheck: FORCE install-shellcheck
107107

108108
build/cover.out: FORCE | build
109109
@printf "\e[1;36m>> Running tests\e[0m\n"
110-
@env $(GO_TESTENV) go test -shuffle=on -p 1 -coverprofile=$@ $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=go-makefile-maker -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)
110+
@env $(GO_TESTENV) go test -shuffle=on -p 1 -coverprofile=build/coverprofile.out $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=go-makefile-maker -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)
111+
@awk < build/coverprofile.out '$$1 != "mode:" { is_filename[$$1] = true; counts1[$$1]+=$$2; counts2[$$1]+=$$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | $(SED) '1s/^/mode: count\n/' > $@
111112

112113
build/cover.html: build/cover.out
113114
@printf "\e[1;36m>> go tool cover > build/cover.html\e[0m\n"

internal/makefile/makefile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ endif
377377
},
378378
}
379379

380-
testRunner := "go test -shuffle=on -p 1 -coverprofile=$@"
380+
// NOTE: Ginkgo will always write the coverage profile as "coverprofile.out", so we will choose the same path for non-Ginkgo tests, too.
381+
// The actual final path is build/cover.out, which will be filled by a post-processing step below.
382+
testRunner := "go test -shuffle=on -p 1 -coverprofile=build/coverprofile.out"
381383
if sr.UseGinkgo {
382384
testRunner = "go run github.com/onsi/ginkgo/v2/ginkgo run --randomize-all -output-dir=build"
383385
}
@@ -389,9 +391,8 @@ endif
389391
} else {
390392
testRule.recipe = append(testRule.recipe, `@env $(GO_TESTENV) `+goTest)
391393
}
392-
if sr.UseGinkgo {
393-
testRule.recipe = append(testRule.recipe, `@mv build/coverprofile.out build/cover.out`)
394-
}
394+
// workaround for <https://github.com/fgrosse/go-coverage-report/issues/61>: merge block coverage manually
395+
testRule.recipe = append(testRule.recipe, `@awk < build/coverprofile.out '$$1 != "mode:" { is_filename[$$1] = true; counts1[$$1]+=$$2; counts2[$$1]+=$$3 } END { for (filename in is_filename) { printf "%s %d %d\n", filename, counts1[filename], counts2[filename]; } }' | sort | $(SED) '1s/^/mode: count\n/' > $@`)
395396

396397
test.addRule(testRule)
397398

0 commit comments

Comments
 (0)