Skip to content

Commit

Permalink
Use teststat in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Nov 7, 2023
1 parent c305c4f commit f494bf5
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF" >> $GITHUB_OUTPUT && cat failure-stats.txt >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
echo "report<<EOF" >> $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}"
Expand Down Expand Up @@ -115,14 +138,20 @@ jobs:
<details><summary>Coverage of changed lines</summary>
${{ steps.annotate.outputs.rep }}
</details>
<details><summary>Coverage diff with base branch</summary>
${{ steps.annotate.outputs.diff }}
</details>
<details><summary>Test stats: ${{ steps.test.outputs.failure-stats }}</summary>
${{ steps.test.outputs.report }}
</details>
- name: Store base coverage
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
Expand All @@ -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

0 comments on commit f494bf5

Please sign in to comment.