Skip to content

Commit effcb5a

Browse files
author
Felix Exner
committed
Update link check to have ignore patterns
1 parent 0fdd8ed commit effcb5a

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

.github/helpers/check_urls.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,54 @@
22

33
set -e
44

5+
IGNORE_FILES=""
6+
IGNORE_PATTERNS=""
7+
8+
while getopts ":f:d:p:" opt; do
9+
case "${opt}" in
10+
f)
11+
IGNORE_FILES="${OPTARG}";;
12+
d)
13+
IGNORE_DIRS="${OPTARG}";;
14+
p)
15+
IGNORE_PATTERNS="${OPTARG}";;
16+
\?)
17+
echo "Invalid option -$OPTARG"
18+
exit;;
19+
esac
20+
done
21+
22+
read -r -a ignore_files <<<"$IGNORE_FILES"
23+
read -r -a ignore_dirs <<<"$IGNORE_DIRS"
24+
read -r -a ignore_patterns <<<"$IGNORE_PATTERNS"
25+
26+
IGNORE_FILES_ARG=""
27+
for item in "${!ignore_files[@]}"; do
28+
IGNORE_FILES_ARG="$IGNORE_FILES_ARG--exclude=$item"
29+
done
30+
IGNORE_DIRS_ARG=""
31+
for item in "${!ignore_dirs[@]}"; do
32+
IGNORE_DIRS_ARG="$IGNORE_DIRS_ARG--exclude-dir=$item"
33+
done
34+
535
#Find URLs in code:
6-
urls=$(grep -oP "(http|ftp|https):\/\/([a-zA-Z0-9_-]+(?:(?:\.[a-zA-Z0-9_-]+)+))([a-zA-Z0-9_.,@?^=%&:\/~+#-]*[a-zA-Z0-9_@?^=%&\/~+#-])?" "$@")
36+
urls=$(grep -oP '(http|ftp|https):\/\/([a-zA-Z0-9_-]+(?:(?:\.[a-zA-Z0-9_-]+)+))([a-zA-Z0-9_.,@?^=%&:\/~+#-]*[a-zA-Z0-9_@?^=%&\/~+#-])?' -rI $IGNORE_FILES_ARG $IGNORE_DIRS_ARG)
737

838
fail_counter=0
939

1040
FAILED_LINKS=()
1141
for item in $urls; do
1242
# echo $item
43+
skip=0
44+
for pattern in "${!ignore_patterns[@]}"; do
45+
[[ "$item" =~ $pattern ]] && skip=1
46+
done
47+
48+
if [[ $skip == 1 ]]; then
49+
echo "SKIPPING $item"
50+
continue
51+
fi
52+
1353
filename=$(echo "$item" | cut -d':' -f1)
1454
url=$(echo "$item" | cut -d':' -f2-)
1555
echo -n "Checking $url from file $filename"

.github/workflows/check_links.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ jobs:
1313
- uses: actions/checkout@v2
1414
- name: Check URLs
1515
run: |
16-
.github/helpers/check_urls.sh -rI \
17-
--exclude-dir=.git \
18-
--exclude-dir=build/ \
19-
--exclude=package.xml \
20-
--exclude-dir=CMakeModules \
21-
--exclude-dir=debian \
22-
--exclude=ursim_docker.rst \
16+
.github/helpers/check_urls.sh \
17+
-d ".git build CMakeModules debian" \
18+
-f "package.xml ursim_docker.rst" \
19+
-p "vnc\.html"

0 commit comments

Comments
 (0)