From ec0749195531124d5f2732a6e5aa818fa89cc62b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 16 Apr 2024 15:02:04 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Automate=20URL=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check-urls.yml | 88 +++++++++++++++++++ .../share/PlatformIO/scripts/signature.py | 3 +- 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check-urls.yml diff --git a/.github/workflows/check-urls.yml b/.github/workflows/check-urls.yml new file mode 100644 index 0000000000000..c23a5c808b1f0 --- /dev/null +++ b/.github/workflows/check-urls.yml @@ -0,0 +1,88 @@ +# +# check-urls.yml +# Check (most) distinct URLs in the project for reachability +# + +name: Check URLs + +on: + schedule: + - cron: '0 4 * * 2' # Tues 4:00 AM UTC + +jobs: + check_urls: + name: Check All URLs + if: github.repository == 'MarlinFirmware/Marlin' + + runs-on: ubuntu-latest + + permissions: + issues: write + pull-requests: 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 }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Exit with an error to notify fail on URL tests + run: | + 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 -v "Binary file" \ + | sed -E "s/\/https?:\/\//\//" \ + | 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/' \ + | 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= + case "$HEAD1" in + *" 301"*) EMSG="[Moved Permanently]" ;; + *" 302"*) EMSG="[Moved Temporarily]" ;; + *" 303"*) echo "[See Other]" ;; + *" 400"*) EMSG="[Invalid Request]" ;; + *" 403"*) EMSG="[Forbidden]" ;; + *" 404"*) EMSG="[Not Found]" ;; + *" 503"*) EMSG="[Unavailable]" ;; + *" 200"*) echo "[ OK ]" ;; + *) EMSG="[Other Err]" ;; + esac + [[ -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 --repo $GITHUB_REPOSITORY --body "${BODY}" + exit 1 + fi + + echo -e "\nURL Check Passed." + exit 0 diff --git a/buildroot/share/PlatformIO/scripts/signature.py b/buildroot/share/PlatformIO/scripts/signature.py index 820e6b7d653c6..8723969c00314 100755 --- a/buildroot/share/PlatformIO/scripts/signature.py +++ b/buildroot/share/PlatformIO/scripts/signature.py @@ -31,7 +31,6 @@ def enabled_defines(filepath): our crude scraping method and the actual compiler output. We end up with the actual configured state, better than what the config files say. You can then use the - a decent reflection of all enabled options that (probably) came from resulting config.ini to produce more exact configuration files. ''' outdict = {} @@ -188,7 +187,7 @@ def tryint(key): ini_fmt = '{0:40} = {1}' ext_fmt = '{0:40} {1}' - ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXPORT') + ignore = ('CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION', 'CONFIG_EXAMPLES_DIR', 'CONFIG_EXPORT') if extended_dump: # Extended export will dump config options by section