Skip to content

Instantly share code, notes, and snippets.

@nolar
Created May 24, 2019 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolar/35c73e7a0caa37a30f0a37bdebb5d574 to your computer and use it in GitHub Desktop.
Save nolar/35c73e7a0caa37a30f0a37bdebb5d574 to your computer and use it in GitHub Desktop.
Ad-hoc script to replay code coverage over the whole git history (used in https://github.com/zalando-incubator/kopf/pull/72)
#!/bin/bash
set -eux
unset E2E # e2e covers everything, but this is not a fair coverage.
first=981e664e39955f38d9a279af24ee5be77c7e9a3e
last=b6e3ec407f46d8db0f1c5c15fce41359ac76ebf1 # or upstream/master
# Master-only commits (i.e. where "master" branch was on merges).
# These ones are fast, since it walks "first parent" way only
while read -r rev; do
git checkout master
git reset --hard "$rev"
rm -rf .coverage coverage.* htmlcov || true
pytest --cov=kopf/ --cov-report=term --cov-branch || true
codecov || true
done < <( git rev-list ${first}..${last} --reverse --first-parent )
# All the regular commits (those not failing) under their branch names!
# These ones are slow, since it is every commit, and e2e tests are slow'ish.
prev="${first}"
while read -r rev; do
subject=$( git log --pretty=format:%s -1 "$rev" )
if [[ "$subject" =~ "from "([^[:space:]]+) ]] ; then
branch=$(basename "${BASH_REMATCH[1]}")
while read -r subrev; do
git branch --force "$branch" "$subrev"
git checkout "$branch"
rm -rf .coverage coverage.* htmlcov || true
pytest --cov=kopf/ --cov-report=term --cov-branch || true
codecov || true
git checkout master
done < <( git rev-list ${prev}..${rev} --reverse )
git branch -D "$branch" || true
fi
prev="$rev"
done < <( git rev-list ${first}..${last} --reverse --first-parent )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment