Skip to content

Commit

Permalink
Updated error handling for missing files and no response hyperlinks
Browse files Browse the repository at this point in the history
 Signed-off-by: Charan-Sharan <[email protected]>
  • Loading branch information
Charan-Sharan committed Jun 24, 2024
1 parent e035112 commit 1aba5c6
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/test-hyperlinks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ on:
# - '**.rst'
# - '**.xml'
workflow_dispatch:
inputs:
full-scan:
description: 'Scan all files'
required: false
type: boolean
default: false

jobs:
main:
Expand All @@ -32,6 +26,7 @@ jobs:

- name: List Docs
run: |
# if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
if [[ true ]]; then
find $PWD -name '*.xml' -type f > xmlFilesList.txt
find $PWD -name '*.md' -type f > mdFilesList.txt
Expand All @@ -48,6 +43,11 @@ jobs:
IFS=$'\n'
for file in $( cat xmlFilesList.txt )
do
if [[ ! -f $file ]]; then
echo -e "$file -\u001b[31m file missing"
echo $file >> missingFiles.txt
continue
fi
grep -onHE -e "<ulink" -e 'url="http[^\"\]+' -e "</ulink>" ${file} | sed 's/url="//' > links.tmp
flag=0
for line in $( cat links.tmp )
Expand All @@ -69,6 +69,11 @@ jobs:
done
for file in $( cat mdFilesList.txt )
do
if [[ ! -f $file ]]; then
echo -e "$file -\u001b[31m file missing"
echo $file >> missingFiles.txt
continue
fi
grep -onHE -e "\]\([^\)]+" -e "\`\`\`[^\`]*" -e "http://[^\ \;\"\'\<\>\]\[\,\`\)]+" -e "https://[^\ \;\"\'\<\>\]\[\,\`\)]+" ${file} | sed 's/](//' > links.tmp
flag=0
for line in $( cat links.tmp )
Expand All @@ -86,6 +91,11 @@ jobs:
for file in $( cat rstFilesList.txt )
do
if [[ ! -f $file ]]; then
echo -e "$file -\u001b[31m file missing"
echo $file >> missingFiles.txt
continue
fi
grep -onHE -e ".. _[^\]+" -e "http://[^\ \;\"\'\<\>\,\`\)]+" -e "https://[^\ \;\"\'\<\>\,\`\)]+" ${file} | sed 's/.. _[^\:]*: //' >> links_list.txt
done
Expand Down Expand Up @@ -122,6 +132,9 @@ jobs:
if [[ $status_code -eq 404 ]]; then
echo -e "${link} - \033[0;31m404 Error\033[0m"
echo "${line}" >> error-report.log
elif [[ ! -n $status_code ]]; then
echo -e "${link} - \033[0;31mNo Response\033[0m"
echo "${line}(No Response)" >> error-report.log
else
echo "${link} - ${status_code}"
fi
Expand Down Expand Up @@ -155,7 +168,7 @@ jobs:
fi
done
- name: report Error links
- name: Report Error links
run: |
Number_of_404_links=$( cat error-report.log | wc -l )
echo -e "\u001b[32mNo. of files scanned : $( cat *FilesList.txt | wc -l )"
Expand Down Expand Up @@ -185,7 +198,15 @@ jobs:
echo -e "\t Line $rawLine" | sed 's/:/ : /' >> error-reportTmp.log
done
done
cat error-reportTmp.log > error-report.log
if [[ $(cat missingFiles.txt | wc -w ) -eq 0 ]]; then
echo -e "Broken links: \n" > error-report.log
cat error-reportTmp.log >> error-report.log
else
echo -e "Missing Files: \n" > error-report.log
cat missingFiles.txt >> error-report.log
echo -e "Broken links: \n" >> error-report.log
cat error-reportTmp.log >> error-report.log
fi
- name: Upload logs
uses: actions/upload-artifact@v4
Expand Down

0 comments on commit 1aba5c6

Please sign in to comment.