diff --git a/.github/helpers/check_urls.sh b/.github/helpers/check_urls.sh index 768a49b4..c27ff515 100755 --- a/.github/helpers/check_urls.sh +++ b/.github/helpers/check_urls.sh @@ -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" diff --git a/.github/workflows/check_links.yml b/.github/workflows/check_links.yml index c4cb8ba6..ba1800e0 100644 --- a/.github/workflows/check_links.yml +++ b/.github/workflows/check_links.yml @@ -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"