Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barkermn01 patch 2 #20

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 87 additions & 63 deletions .github/workflows/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,106 @@ ret=0
declare -A id_map

# Initialize the validation results file
echo -e "### Validtion Results" > validation_results.md
echo -e "### Validtion Results" >validation_results.md

for file in mods/**/*.xml; do
IFS='/'
read -ra parts <<< "$file"
name="${parts[1]}"
warnings=""
errors=""

# Lint the XML file
xmllint --noout "$file"
if [ $? -ne 0 ]; then
errors+=" - Invalid XML failed lint\n"
ret=1
fi

# Check Mod.LatestVersion.Link
latest_version_link=$(xmllint --xpath 'string(//Mod/LatestVersion/Link)' "$file" | sed 's|iroj://Url/https\$|https://|' | sed 's|iroj://Url/http\$|http://|')
curl --output /dev/null --silent --head --fail "$latest_version_link" -A "Mozilla/5.0"
if [ $? -ne 0 ]; then
errors+=" - Verify LatestVersion.Link failed: [link]($latest_version_link)\n"
ret=1
fi
IFS='/'
read -ra parts <<<"$file"
name="${parts[1]}"
warnings=""
errors=""

# Check Mod.LatestVersion.PreviewImage
preview_image=$(xmllint --xpath 'string(//Mod/LatestVersion/PreviewImage)' "$file")
if [ -n "$preview_image" ]; then
curl --head --fail -H "Accept: image/*" "$preview_image" -A "Mozilla/5.0" --silent | grep "content-type: blar/*"
# Lint the XML file
xmllint --noout "$file"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.PreviewImage failed: [preview image]($preview_image)\n"
errors+=" - Invalid XML failed lint\n"
ret=1
fi
fi

# Check Mod.Link
mod_link=$(xmllint --xpath 'string(//Mod/Link)' "$file")
if [ -n "$mod_link" ]; then
curl --output /dev/null --silent --head --fail "$mod_link" -A "Mozilla/5.0"
# Check Mod.LatestVersion.Link
latest_version_link=$(xmllint --xpath 'string(//Mod/LatestVersion/Link)' "$file")

# Parse the iros:// URI format
if [[ $latest_version_link =~ ^iroj://([a-zA-Z]+)/ ]]; then
protocol=${BASH_REMATCH[1]}
uri_path=${latest_version_link#iros://$protocol/}

case ${protocol,,} in # ${protocol,,} converts to lowercase
"url")
latest_version_link=${uri_path/\$/:\/\/}
;;
"gdrive")
latest_version_link="https://drive.google.com/file/d/${uri_path}"
;;
"mega")
latest_version_link="https://mega.co.nz/${uri_path}"
;;
*)
errors+=" - Unknown protocol in LatestVersion.Link: $protocol\n"
ret=1
continue
;;
esac
fi
# Now check the converted URL
curl --output /dev/null --silent --head --fail "$latest_version_link" -A "Mozilla/5.0"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.Link failed: [link]($mod_link)\n"
errors+=" - Verify LatestVersion.Link failed: [link]($latest_version_link)\n"
ret=1
fi
fi

# Check Mod.DonationLink
donation_link=$(xmllint --xpath 'string(//Mod/DonationLink)' "$file")
if [ -n "$donation_link" ]; then
curl --output /dev/null --silent --head --fail "$donation_link" -A "Mozilla/5.0"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.DonationLink failed: [donation link]($donation_link)\n"
# Check Mod.LatestVersion.PreviewImage
preview_image=$(xmllint --xpath 'string(//Mod/LatestVersion/PreviewImage)' "$file")
if [ -n "$preview_image" ]; then
curl --head --fail -H "Accept: image/*" "$preview_image" -A "Mozilla/5.0" --silent | grep "content-type: blar/*"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.PreviewImage failed: [preview image]($preview_image)\n"
fi
fi

# Check Mod.Link
mod_link=$(xmllint --xpath 'string(//Mod/Link)' "$file")
if [ -n "$mod_link" ]; then
curl --output /dev/null --silent --head --fail "$mod_link" -A "Mozilla/5.0"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.Link failed: [link]($mod_link)\n"
fi
fi
fi

# Check for unique ID
mod_id=$(xmllint --xpath 'string(//Mod/ID)' "$file")
if [ -n "${id_map[$mod_id]}" ]; then
errors+=" - Duplicate Mod ID found: $mod_id (conflicts with ${id_map[$mod_id]})\n"
ret=1
else
id_map[$mod_id]=$name
fi
# Check Mod.DonationLink
donation_link=$(xmllint --xpath 'string(//Mod/DonationLink)' "$file")
if [ -n "$donation_link" ]; then
curl --output /dev/null --silent --head --fail "$donation_link" -A "Mozilla/5.0"
if [ $? -ne 0 ]; then
warnings+=" - Verify Mod.DonationLink failed: [donation link]($donation_link)\n"
fi
fi

# Check for unique ID
mod_id=$(xmllint --xpath 'string(//Mod/ID)' "$file")
if [ -n "${id_map[$mod_id]}" ]; then
errors+=" - Duplicate Mod ID found: $mod_id (conflicts with ${id_map[$mod_id]})\n"
ret=1
else
id_map[$mod_id]=$name
fi

# Append results to the output file
if [ -n "$errors" ]; then
echo -e "#### Mod: $name 🔴\n" >> validation_results.md
elif [ -n "$warnings" ]; then
echo -e "#### Mod: $name 🟡\n" >> validation_results.md
else
echo -e "#### Mod: $name 🟢\n" >> validation_results.md
echo -e "No errors or warnings\n" >> validation_results.md
fi
# Append results to the output file
if [ -n "$errors" ]; then
echo -e "#### Mod: $name 🔴\n" >>validation_results.md
elif [ -n "$warnings" ]; then
echo -e "#### Mod: $name 🟡\n" >>validation_results.md
else
echo -e "#### Mod: $name 🟢\n" >>validation_results.md
echo -e "No errors or warnings\n" >>validation_results.md
fi

if [ -n "$errors" ]; then
echo -e "Errors:\n$errors\n" >> validation_results.md
fi
if [ -n "$warnings" ]; then
echo -e "Warnings:\n$warnings\n" >> validation_results.md
fi
if [ -n "$errors" ]; then
echo -e "Errors:\n$errors\n" >>validation_results.md
fi
if [ -n "$warnings" ]; then
echo -e "Warnings:\n$warnings\n" >>validation_results.md
fi
done

exit $ret
3 changes: 2 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Run Validation
run: .github/workflows/validate.sh
- name: Post warnings as PR comment
if: always()
if: always()
uses: actions/github-script@v6
with:
script: |
Expand All @@ -62,3 +62,4 @@ jobs:
issue_number: context.issue.number,
body: output
});

Loading