layotto
layotto copied to clipboard
让 CI 中的报错信息更直观
优化检查报错信息,让报错更明显些
复现步骤: 提交个会让 ut 报错的 pr,github 跑 CI 会报错,但报错信息如上图、不明显,看不出来是哪个ut出错了
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.