mirror of
https://codeberg.org/dwl/dwl.git
synced 2025-10-27 10:14:14 +00:00
replacement functionality works
This commit is contained in:
parent
8735757c93
commit
4c84f36aaa
78
.github/workflows/testPatches.sh
vendored
78
.github/workflows/testPatches.sh
vendored
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user