From f494bf57dc386a5c8258d626addd55e5745acf98 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 7 Nov 2023 23:47:51 +0100 Subject: [PATCH] Use teststat in CI --- .github/workflows/test-unit.yml | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 7ce70d7..cd593a2 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -77,8 +77,31 @@ jobs: - name: Test id: test + continue-on-error: true run: | - make test-unit + curl -sLO https://github.com/vearutop/teststat/releases/download/v0.1.22/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz + teststat_hash=$(git hash-object ./teststat) + [ "$teststat_hash" == "5f76f19f23958fdd71ba8bd2f066b3b4b87f5080" ] || (echo "::error::unexpected hash for teststat, possible tampering: $teststat_hash" && exit 1) + + # First run. + go test -short -coverprofile=unit.coverprofile -covermode=atomic -race -json ./... |& ./teststat -progress -store test-report0.jsonl -skip-report -failed-tests failed.txt -failed-builds errors.txt - + + # Retries. + for i in {1..3} + do + test ! -f failed.txt || (export FAILED=$(cat failed.txt) && rm failed.txt && echo "Retry $i: $FAILED" && go test -short -race -run $FAILED -json ./... |& ./teststat -progress -store test-report${i}.jsonl -skip-report -failed-tests failed.txt -) + done + + # Reporting. + REPORT=$(./teststat -failure-stats failure-stats.txt -markdown test-report*.jsonl) + echo "${REPORT}" + + test ! -f failed.txt || echo "Tests failed after retries: $(cat failed.txt)" 1>&2 + test ! -f failed.txt || (echo "failed=true" >> $GITHUB_OUTPUT) + test ! -f errors.txt || (echo "failed=true" >> $GITHUB_OUTPUT) + + echo "failure-stats<> $GITHUB_OUTPUT && cat failure-stats.txt >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT + echo "report<> $GITHUB_OUTPUT && echo "$REPORT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT go tool cover -func=./unit.coverprofile > unit.txt TOTAL=$(grep 'total:' unit.txt) echo "${TOTAL}" @@ -115,14 +138,20 @@ jobs:
Coverage of changed lines ${{ steps.annotate.outputs.rep }} - +
Coverage diff with base branch - + ${{ steps.annotate.outputs.diff }}
+ +
Test stats: ${{ steps.test.outputs.failure-stats }} + + ${{ steps.test.outputs.report }} + +
- name: Store base coverage if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} @@ -134,3 +163,9 @@ jobs: with: file: ./unit.coverprofile flags: unittests + + - name: Check test result + if: steps.test.outputs.failed == 'true' + run: | + echo "::error ::Test failed, see Test step for details" + exit 1 \ No newline at end of file