From f2d8f66ae3f79c86031bcd615903d56415fc47e0 Mon Sep 17 00:00:00 2001 From: alfred gedeon Date: Thu, 24 Sep 2020 12:35:22 -0700 Subject: [PATCH] Maintenance: Github workflow URL checker (#179) * Remove non needed spell checks * FreeRTOS Kernel Spelling Update (#170) * FreeRTOS Kernel Spelling Update * Added spell check to kernel repository. * Fixed small spelling errors in various kernel source files. * Added documentation for spellcheck. Note: Only kernel files are checked for spelling, and portable files are ignored. * Fix exit 0 * Remove spell * add echo * Call script from ci * Fix script location * Print pwd * Fix script * Fix script * Remove some lines from script * uncomment lines and fix exit * use bash instead of sh * Move url checker to the action directory * Separate spell and url checkers * Fix bad merge from master * Fix yml file error * Add another step to the url checker Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com> --- .github/actions/url_verifier.sh | 59 +++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 11 +++++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 .github/actions/url_verifier.sh diff --git a/.github/actions/url_verifier.sh b/.github/actions/url_verifier.sh new file mode 100755 index 000000000..4e9575aa3 --- /dev/null +++ b/.github/actions/url_verifier.sh @@ -0,0 +1,59 @@ +#!/bin/bash - + +PROJECT=$1 +echo "Verifying url links of: ${PROJECT}" +if [ ! -d "$PROJECT" ] +then + echo "Directory passed does not exist" + exit 2 +fi + +SCRIPT_RET=0 + +set -o nounset # Treat unset variables as an error + +declare -A dict + +function test { + while IFS= read -r LINE; do + FILE=$(echo $LINE | cut -f 1 -d ':') + URL=$(echo $LINE | grep -IoE '\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]') + + # remove trailing / if it exists curl diferenciate between links with + # and without / at the end + # URL=`echo "$URL" | sed 's,/$,,'` + dict+=(["$URL"]="$FILE ") + done < <(grep -e 'https\?://' ${PROJECT} -RIa --exclude='*.exe' --exclude-dir=.git | tr '*' ' ') + + for UNIQ_URL in ${!dict[@]} # loop urls + do + CURL_RES=$(curl -I ${UNIQ_URL} 2>/dev/null| head -n 1 | cut -f 2 -d ' ') + RES=$? + + if [ "${CURL_RES}" == '' -o "${CURL_RES}" != '200' ] + then + echo "URL is: ${UNIQ_URL}" + echo "File names: ${dict[$UNIQ_URL]}" + if [ "${CURL_RES}" == '' ] # curl returned an error + then + CURL_RES=$RES + SCRIPT_RET=1 + elif [ "${CURL_RES}" == '403' ] + then + SCRIPT_RET=1 + fi + echo Result is: "${CURL_RES}" + echo "=================================" + fi + done + + if [ "${SCRIPT_RET}" -eq 0 ] + then + exit 0 + else + exit 1 + fi +} + +test + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6b62a985..593c384f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,4 +34,13 @@ jobs: else exit 1 fi - + url-check: + runs-on: ubuntu-latest + steps: + - name: Clone This Repo + uses: actions/checkout@v2 + with: + path: ./kernel + - name: URL Checker + run: | + bash kernel/.github/actions/url_verifier.sh kernel