Skip to content

Commit

Permalink
get coverage hsitory from git notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jul 15, 2024
1 parent 66beda5 commit 0f358f7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ jobs:
- name: ⛙ Merge coverage reports
run: |
coverage combine test-logs/*/.coverage
- name: ± Compute change in coverage
run: ./utils/coverage-log.sh
- name: 📃 Produce coverage reports
run: |
coverage html -d lenskit-coverage
Expand Down
1 change: 1 addition & 0 deletions lkdev/workflows/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def jobs_result(deps: list[str]) -> GHJob:
coverage combine test-logs/*/.coverage
"""),
},
{"name": "± Compute change in coverage", "run": "./utils/coverage-log.sh"},
{
"name": "📃 Produce coverage reports",
"run": script("""
Expand Down
40 changes: 40 additions & 0 deletions utils/coverage-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/zsh

git fetch --all || exit 2
coverage json || exit 2

if [[ -n $GITHUB_HEAD_REF ]]; then
# PR run — save difference to output
git log --pretty=ref $GITHUB_HEAD_REF | while read commit msg; do
prev_data="$(git notes --ref=coverage show $log)"
if [[ "$?" -eq 0 ]]; then
break
fi
done
if [[ -z "$prev_data" ]]; then
echo "no previous coverage found" >&2
exit 2
fi

prev_cov="$(echo "prev_data" |jq .totals.percent_covered)"
if [[ $? -ne 0 ]]; then
echo "jq failed" >&2
exit 2
fi
cur_cov="$(jq .totals.percent_covered coverage.json)"
if [[ $? -ne 0 ]]; then
echo "jq failed" >&2
exit 2
fi

cov_change=$(( $cur_cov - $prev_cov ))
echo "coverage change: $cov_change"
cat >>"$GITHUB_JOB_SUMMARY" <<EOM
Coverage change **$cov_change** (from $prev_cov to $cur_cov).
EOM
elif [[ $GITHUB_EVENT_NAME = push && -n $GITHUB_TOKEN ]]; then
jq '{meta: .meta, totals: .totals}' coverage.json >cov-summary.json || exit 2
git notes --ref=coverage add -F cov-summary.json HEAD || exit 2
git push origin refs/notes/coverage || exit 2
fi

0 comments on commit 0f358f7

Please sign in to comment.