From 4c84f36aaa7ce2dcf16ae1603d12e74334a68c24 Mon Sep 17 00:00:00 2001 From: wyatt-avilla Date: Sun, 22 Oct 2023 22:53:44 -0700 Subject: [PATCH] replacement functionality works --- .github/workflows/testPatches.sh | 78 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/.github/workflows/testPatches.sh b/.github/workflows/testPatches.sh index 34973e4..64026e4 100755 --- a/.github/workflows/testPatches.sh +++ b/.github/workflows/testPatches.sh @@ -1,49 +1,59 @@ #!/bin/bash -update_line() { - local line="$1" # line from opened file is passed in - local testResult="$2" # result from git diff - - echo "Processing line: $line with additional argument: $testResult" -} +# wiki directory was initially formatted via: sed -i '/https:\/\/github\.com\/[^/]\+\/[^/]\+\/compare\/[^/]\+\.patch/s/$/ [❔]/' dwlSrcDirectory="$1" wikiDirectory="$2" -patchRE="https://github\.com/[^/]+/[^/]+/compare/[^/]+\.patch" +patchLinkPattern="https://github\.com/[^/]+/[^/]+/compare/[^/]+\.patch" +emojiReplacePattern="\(\[[❔⚠️❌✅]\]\)" for file in "$wikiDirectory"/*.md; do - if [ -f "$file" ]; then - if ! grep -q "Download" "$file"; then - echo "no download heading found in $file, skipping..." + + bFileName=$(basename "$file") + if ! [ -f "$file" ] || + [ "$bFileName" == "Patches.md" ] || \ + [ "$bFileName" == "Screenshots.md" ] || \ + [ "$bFileName" == "Home.md" ] || \ + [ "$bFileName" == "_Sidebar.md" ]; then + echo "$file is invalid, skipping" + continue + fi + if ! grep -q "Download" "$file"; then + echo "no download heading found in $file, skipping..." + continue + fi + + tempFile="$file.tmp" + touch "$tempFile" + while IFS= read -r line || [ -n "$line" ]; do + if ! [[ $line =~ $patchLinkPattern ]]; then # not a download link + echo "$line" >> "$tempFile" continue fi - while IFS= read -r line - do - if [[ $line =~ $patchRE ]]; then - extractedURL=${BASH_REMATCH[0]} - response=$(curl -s -w "%{http_code}" -o - "$extractedURL") + extractedURL=${BASH_REMATCH[0]} + response=$(curl -s -w "%{http_code}" -o - "$extractedURL") - http_status_code="${response: -3}" - patchContent="${response:0:-3}" + http_status_code="${response: -3}" + patchContent="${response:0:-3}" - if [ "$http_status_code" -ne 200 ] || [ -z "$patchContent" ]; then - echo "⚠️ - $extractedURL" - update_line "$line" "inaccessible" - continue - fi + if [ "$http_status_code" -ne 200 ] || [ -z "$patchContent" ]; then + echo "[⚠️] -- $extractedURL" + echo "$line" | sed "s/$emojiReplacePattern/[⚠️]/1" >> "$tempFile" + continue + fi - git -C "$dwlSrcDirectory" apply --check <<< "$patchContent" > /dev/null 2>&1 - patchApplicationExitCode=$? + git -C "$dwlSrcDirectory" apply --check <<< "$patchContent" > /dev/null 2>&1 + patchApplicationExitCode=$? - if [ $patchApplicationExitCode -eq 0 ]; then - echo "✅ - $extractedURL" - update_line "$line" "pass" - else - echo "❌ - $extractedURL" - update_line "$line" "fail" - fi - fi - done < "$file" - fi + if [ $patchApplicationExitCode -eq 0 ]; then + echo "[✅] -- $extractedURL" + echo "$line" | sed "s/$emojiReplacePattern/[✅]/1" >> "$tempFile" + else + echo "[❌] -- $extractedURL" + echo "$line" | sed "s/$emojiReplacePattern/[❌]/1" >> "$tempFile" + fi + done < "$file" + + mv "$tempFile" "$file" done