layotto icon indicating copy to clipboard operation
layotto copied to clipboard

让 CI 中的报错信息更直观

Open GimmeCyy opened this issue 2 years ago • 1 comments

优化检查报错信息,让报错更明显些 b57d1f3e26c5490b4b44cd3d74d5a38

GimmeCyy avatar Jun 12 '22 06:06 GimmeCyy

复现步骤: 提交个会让 ut 报错的 pr,github 跑 CI 会报错,但报错信息如上图、不明显,看不出来是哪个ut出错了

seeflood avatar Jun 14 '22 08:06 seeflood

It seems still not solve, and nobody take this task. I have a simple but useful idea, and I implemented it.

In layotto github-ci process, main command about go-unit-test is run: make test, this command runs go.test in layotto/make/golang.mk. My idea is make commands in go.test output a temp record file, instead of stdout. When unit test finished, output the file content to stdout firstly, then output the failed info.

.PHONY: go.test
OUTPUT := /home/alilestera/foo.txt
go.unittest:
	@echo "===========> Run unit test in diagnostics" > $(OUTPUT) && \
	$(GO) test -count=1 -timeout=10m -short -v `go list ./diagnostics/...` >> $(OUTPUT) && \
	echo "===========> Run unit test in sdk/go-sdk" >> $(OUTPUT) && \
	cd sdk/go-sdk && $(GO) test -count=1 -timeout=10m -short -v `go list ./... | grep -v runtime` >> $(OUTPUT) && \
	echo "===========> Run unit test in components" >> $(OUTPUT) && \
	cd ../../components/ && $(GO) test -count=1 -timeout=10m -short -v `go list ./...` >> $(OUTPUT) && \
	echo "===========> Run unit test in pkg" >> $(OUTPUT) && \
	cd ../ && $(GO) test -count=1 -timeout=10m -short -v `go list ./pkg/...` >> $(OUTPUT) || true

go.test: go.unittest
	@cat $(OUTPUT)
#	if failed, exit 1 to stop process
	@if grep -q "FAIL" $(OUTPUT); then \
    		grep "FAIL" $(OUTPUT); \
    		rm -f $(OUTPUT); \
    		exit 1; \
	fi;
	@rm -f $(OUTPUT)

Use && connect every command make the workflow can fail fast if one of these get failed, and it runs to || true. Then the workflow runs to go.test. In go.test, if it really get failed, exit 1 let the make process output Error and stop ci.

alilestera avatar Jun 26 '23 13:06 alilestera