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