Last active
May 4, 2017 21:24
-
-
Save stronk7/58a81cd59e0fe19251a6 to your computer and use it in GitHub Desktop.
Basic script to detect (by commit) uses of deleted lang strings within behat .feature files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Find uses in .feature files corresponding to deleted strings for a given commit. | |
# Far from ideal for multiline strings, but does its work for 1 line ones. | |
# Usage: within a git repo: check_lang_string_uses.sh <commit>. Look for ERROR @ output. | |
commit=${1:-HEAD} | |
count=0 | |
retcode=0 | |
pushd "$(git rev-parse --show-toplevel)" > /dev/null | |
echo "Checking commit ${commit}" | |
while read -r line; do | |
if [[ ${line} =~ ^-\$string\[.*=\ *\'(.*)\'\; ]]; then | |
((count++)) | |
search=${BASH_REMATCH[1]} | |
# normalize placeholders | |
search=$(echo "${search}" | sed 's/{[^}]*}/.*/g') | |
# normalize backslashes | |
search=$(echo "${search}" | sed 's/\\//g') | |
# get rid of tags | |
search=$(echo "${search}" | sed 's/<[^>]*>//g') | |
while read -r error; do | |
echo "ERROR: Commit removes '${search}' still used in '${error}'" | |
retcode=1 | |
done < <(find . -name "*.feature" | xargs grep "${search}") | |
fi | |
done < <(git show ${commit}) | |
popd > /dev/null | |
echo "${count} strings processed" | |
if [[ ${retcode} = 0 ]]; then | |
echo "Seems ok" | |
fi | |
exit ${retcode} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment