Skip to content

👷 Local URL checking script #22

👷 Local URL checking script

👷 Local URL checking script #22

Workflow file for this run

#
# check-urls.yml
# Check (most) distinct URLs in the project for reachability
#
name: Check URLs
on:
pull_request:
branches:
- bugfix-2.1.x
jobs:
check_urls:
name: Check All URLs
if: github.repository == 'MarlinFirmware/Marlin'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Check out bugfix-2.1.x
uses: actions/checkout@v4
with:
ref: bugfix-2.1.x
- name: Check All URLs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Exit with an error to notify fail on URL tests
run: |
# Inline URL Check Script
UA="Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36"
UTMP=`mktemp`
grep -R -E "https?:\/\/[^ \"''\(\)\<\>]+" . 2>/dev/null \
| grep -vE "Binary file" \
| sed -E 's/.*\((https?:\/\/[^ ]+)\).*$/\1/' \
| sed -E 's/.*\[(https?:\/\/[^ ]+)\].*$/\1/' \
| sed -E 's/.*(https?:\/\/[^ \"''()<>]+).*/\1/' \
| grep -vE "(127\.0\.0\.1|localhost|myserver|doc\.qt\.io|docs\.google\.com|raw\.githubusercontent\.com|\$)" \
| sed -E 's/]$//' | sed -E "s/'$//" | sed -E "s/[#.',]+$//" \
| sed -E 's/youtu\.be\/(.+)/www.youtube.com\/watch?v=\1/' \
| grep -vE "[}]$" \
| sort -u -R \
>"$UTMP"
ISERR=
declare -a BADURLS
while IFS= read -r URL
do
echo -n "Checking ${URL} ... "
HEAD=$(curl -s -I -A "${UA}" --request GET "${URL}" 2>/dev/null) ; HERR=$?
if [[ $HERR > 0 ]]; then
# Error 92 may be domain blocking curl / wget
[[ $HERR == 92 ]] || { ISERR=1 ; BADURLS+=($URL) ; }
echo "[FAIL ($HERR)]"
else
HEAD1=$(echo $HEAD | head -n1)
EMSG=
if [[ $HEAD1 == *" 301"* ]]; then
EMSG="[Moved Permanently]"
elif [[ $HEAD1 == *" 302"* ]]; then
EMSG="[Moved Temporarily]"
elif [[ $HEAD1 == *" 303"* ]]; then
echo "[See Other]"
elif [[ $HEAD1 == *" 400"* ]]; then
EMSG="[Invalid Request]"
elif [[ $HEAD1 == *" 403"* ]]; then
EMSG="[Forbidden]"
elif [[ $HEAD1 == *" 404"* ]]; then
EMSG="[Not Found]"
elif [[ $HEAD1 == *" 503"* ]]; then
EMSG="[Unavailable]"
elif [[ ! $HEAD1 == *" 200"* ]]; then
EMSG="[Error]"
else
echo "[ OK ]"
fi
[[ -n $EMSG ]] && { ISERR=1 ; BADURLS+=($URL) ; echo $EMSG ; }
fi
done <"$UTMP"
if [[ -n $ISERR ]]; then
# Join bad URLs into a bulleted markdown list
printf -v BADSTR -- "- %s\n" "${BADURLS[@]}"
BODY=$(echo -e "URL Checker reports one or more URLs could not be reached:\n${BADSTR}")
echo -e "\n$BODY"
gh issue comment 26975 --body "${BODY}"
exit 1
fi
exit 0