-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-asciidoc-reuse.sh
executable file
·53 lines (42 loc) · 1.04 KB
/
check-asciidoc-reuse.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <directory_path>"
exit 1
else
FOLDER="$1"
fi
INCL_REGEX='^include::modules\/.*\.adoc'
INCLUDES=()
FILES=$(find "$FOLDER" -type f -name '*.adoc')
# Initialize an associative array to count occurrences
declare -A OCCURRENCES
for FILE in $FILES; do
while IFS= read -r line; do
if [[ $line =~ $INCL_REGEX ]]; then
INCLUDES+=("$line")
((OCCURRENCES["$line"]++))
fi
done < "$FILE"
done
# Print OCCURRENCES
# {
# for line in "${!OCCURRENCES[@]}"; do
# echo "$line: ${OCCURRENCES[$line]}"
# done
# } > OCCURRENCES
# Count the number of includes
TOTAL=${#INCLUDES[@]}
# Count the number of duplicates
DUPLICATES=0
for count in "${OCCURRENCES[@]}"; do
if (( count > 1 )); then
((DUPLICATES++))
fi
done
# Calculate the percentage reuse
if (( TOTAL > 0 )); then
percentage=$(echo "scale=2; ($DUPLICATES / $TOTAL) * 100" | bc)
else
percentage=0
fi
echo "$percentage% of asciidoc modules are reused in the repo 🎉"