Skip to content

Commit

Permalink
Update link check to have ignore patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauch committed Oct 9, 2024
1 parent 0fdd8ed commit effcb5a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
42 changes: 41 additions & 1 deletion .github/helpers/check_urls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,54 @@

set -e

IGNORE_FILES=""
IGNORE_PATTERNS=""

while getopts ":f:d:p:" opt; do
case "${opt}" in
f)
IGNORE_FILES="${OPTARG}";;
d)
IGNORE_DIRS="${OPTARG}";;
p)
IGNORE_PATTERNS="${OPTARG}";;
\?)
echo "Invalid option -$OPTARG"
exit;;
esac
done

read -r -a ignore_files <<<"$IGNORE_FILES"
read -r -a ignore_dirs <<<"$IGNORE_DIRS"
read -r -a ignore_patterns <<<"$IGNORE_PATTERNS"

IGNORE_FILES_ARG=""
for item in "${!ignore_files[@]}"; do
IGNORE_FILES_ARG="$IGNORE_FILES_ARG--exclude=$item"
done
IGNORE_DIRS_ARG=""
for item in "${!ignore_dirs[@]}"; do
IGNORE_DIRS_ARG="$IGNORE_DIRS_ARG--exclude-dir=$item"
done

#Find URLs in code:
urls=$(grep -oP "(http|ftp|https):\/\/([a-zA-Z0-9_-]+(?:(?:\.[a-zA-Z0-9_-]+)+))([a-zA-Z0-9_.,@?^=%&:\/~+#-]*[a-zA-Z0-9_@?^=%&\/~+#-])?" "$@")
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)

fail_counter=0

FAILED_LINKS=()
for item in $urls; do
# echo $item
skip=0
for pattern in "${!ignore_patterns[@]}"; do
[[ "$item" =~ $pattern ]] && skip=1
done

if [[ $skip == 1 ]]; then
echo "SKIPPING $item"
continue
fi

filename=$(echo "$item" | cut -d':' -f1)
url=$(echo "$item" | cut -d':' -f2-)
echo -n "Checking $url from file $filename"
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/check_links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ jobs:
- uses: actions/checkout@v2
- name: Check URLs
run: |
.github/helpers/check_urls.sh -rI \
--exclude-dir=.git \
--exclude-dir=build/ \
--exclude=package.xml \
--exclude-dir=CMakeModules \
--exclude-dir=debian \
--exclude=ursim_docker.rst \
.github/helpers/check_urls.sh \
-d ".git build CMakeModules debian" \
-f "package.xml ursim_docker.rst" \
-p "vnc\.html"

0 comments on commit effcb5a

Please sign in to comment.