From a20e33a93729b1e0a8e003f98979fed4e69f03ba Mon Sep 17 00:00:00 2001 From: Khushalsarode Date: Mon, 28 Oct 2024 00:16:13 +0530 Subject: [PATCH] flow to show only broken and not found links --- .github/workflows/docs_link_check.yaml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs_link_check.yaml b/.github/workflows/docs_link_check.yaml index d6094f44..b7f69de5 100644 --- a/.github/workflows/docs_link_check.yaml +++ b/.github/workflows/docs_link_check.yaml @@ -34,12 +34,29 @@ jobs: - name: Run Sphinx linkcheck run: | cd docs - sphinx-build -b linkcheck source _build/linkcheck || true # link from source docs to be checked - grep "Not Found for url" _build/linkcheck/output.txt > broken_links.txt #output of broken links to broken_links.txt from _builds/linkcheck/output.txt + sphinx-build -b linkcheck source _build/linkcheck > /dev/null 2>&1 || true # Suppress full output of the sphinx-build -b linkcheck source _build/linkcheck command and redirect the output to /dev/null + + # Extract broken links + grep "broken" _build/linkcheck/output.txt > broken_links.txt # Using Grep Extract broken links from the output.txt file and save them to broken_links.txt + grep "Not Found for url" _build/linkcheck/output.txt > not_found_links.txt # Using Grep Extract 'Not Found for url' links from the output.txt file and save them to not_found_links.txt + + # -s flag checks if the file is not empty + # Display broken links if found if [ -s broken_links.txt ]; then echo "Broken links found:" cat broken_links.txt + fi + + + # Display 'Not Found for url' links if found + if [ -s not_found_links.txt ]; then + echo "Not Found for url:" + cat not_found_links.txt + fi + + # Exit with error if any broken or not found links exist + if [ -s broken_links.txt ] || [ -s not_found_links.txt ]; then exit 1 else echo "No broken links found." - fi \ No newline at end of file + fi