| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# This fixes package name="." in coverage.xml or another coverage filename |
| 4 |
# as the only optional argument: ./fix_pkg_name.sh other-name.xml |
| 5 |
# We default to grepping pkg name from (python) setup.cfg |
| 6 |
# otherwise you should set the REAL_NAME environment override, eg: |
| 7 |
# |
| 8 |
# REAL_NAME="re2" ./fix_pkg_name.sh |
| 9 |
# |
| 10 |
# or export it first in your shell env. |
| 11 |
|
| 12 |
set -euo pipefail |
| 13 |
|
| 14 |
failures=0 |
| 15 |
trap 'failures=$((failures+1))' ERR |
| 16 |
|
| 17 |
COV_FILE=${1:-coverage.xml} |
| 18 |
REAL_NAME=${REAL_NAME:-""} |
| 19 |
VERBOSE="false" # set to "true" for extra output |
| 20 |
|
| 21 |
NAME_CHECK=$(grep -o 'name="."' "${COV_FILE}" || true) |
| 22 |
|
| 23 |
[[ -z "$NAME_CHECK" ]] && echo "Nothing to fix ..." && exit 0 |
| 24 |
[[ -n $REAL_NAME ]] || REAL_NAME=$(grep ^name pyproject.toml | cut -d'"' -f2) |
| 25 |
[[ -n $REAL_NAME ]] && sed -i -e "s|name=\".\"|name=\"${REAL_NAME}\"|" $COV_FILE |
| 26 |
[[ -n $REAL_NAME ]] && echo "Replaced \".\" with ${REAL_NAME} in ${COV_FILE} ..." |
| 27 |
|
| 28 |
if ((failures != 0)); then |
| 29 |
echo "Something went wrong !!!" |
| 30 |
exit 1 |
| 31 |
fi |