forked from os-autoinst/os-autoinst-distri-opensuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_deleted_renamed_referenced_files
executable file
·34 lines (33 loc) · 1.49 KB
/
test_deleted_renamed_referenced_files
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
32
33
34
#!/bin/bash -e
FILES="${@}"
success=1
for FILE in $FILES; do
if [ -f "$FILE" ]
then
# if file exists, it means it was renamed. Previous file name is retrieved by git log
FILE=$(git log --follow -p $FILE | grep 'rename from test' | awk '{print $3}' | head -n 1)
fi
if [ -n "$(echo $FILE | grep '\.pm$')" ]
then
# If the file is a module, file name appears in scheduling files (excluding part 'tests/' and file extension)
file_to_verify=$(echo $FILE | sed -E 's/^tests\/(.*)\.pm$/\1/g')
target_paths='schedule/ products/*/main.pm lib/main_common.pm'
elif [ -n "$(echo $FILE | grep '\.ya\?ml$')" ]
then
# If the file is test_data yaml file, the file name returned from git diff command
# is the same as in schedule or test_data files
file_to_verify="$FILE"
target_paths='schedule/ test_data/'
fi
# Using the -e script option will cause the following command to exit the script with failure in case the file_to_verify
# is not referenced anywhere. Using "|| :" to avoid this.
MATCHED_REFERENCE_FILES=$(grep --recursive --ignore-case --files-with-matches \
"${file_to_verify}\b" $target_paths | grep '\(\.ya\?ml$\|\.pm\)' || :)
if [[ -n $file_to_verify ]] && [[ -n $MATCHED_REFERENCE_FILES ]]
then
echo -e "\"$file_to_verify\" was removed or renamed, but it is still used in:\n$MATCHED_REFERENCE_FILES"
success=0
fi
done
[ $success = 1 ] && echo "SUCCESS" && exit 0
exit 1