diff --git a/.github/workflows/.markdown-link-check.json b/.github/workflows/.markdown-link-check.json new file mode 100644 index 000000000..f582e4aee --- /dev/null +++ b/.github/workflows/.markdown-link-check.json @@ -0,0 +1,8 @@ +{ + "ignorePatterns": [ + { + "pattern": "^#" + } + ] + } + \ No newline at end of file diff --git a/.github/workflows/docs_link_check.yaml b/.github/workflows/docs_link_check.yaml new file mode 100644 index 000000000..2aa93ef94 --- /dev/null +++ b/.github/workflows/docs_link_check.yaml @@ -0,0 +1,72 @@ +name: Link Checker for Sphinx Documentation +# Trigger the workflow on push to main branch or pull request to main branch +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, reopened, synchronize] + +jobs: + link-check: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout repository + uses: actions/checkout@v3 + + # Set up Python + - name: Set up Python 3.x + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + + # Install dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip #upgrading pip + pip install -r docs/requirements.txt #installing the required packages from repo docs/requirements.txt + echo "Dependencies installed." + + # Run Sphinx linkcheck to check for broken URLs + - name: Run Sphinx linkcheck + run: | + cd docs + 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 "===============================" + echo "Broken links found:" + echo "===============================" + cat broken_links.txt + fi + + + # Display 'Not Found for url' links if found + if [ -s not_found_links.txt ]; then + echo "===============================" + echo "Not Found for url:" + echo "===============================" + 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 + echo "!!!!!!!!!!!!!!!!!!!!!!!!" + echo "Broken links found." + echo "!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1 + + else + echo "#########################" + echo "No broken links found." + echo "#########################" + fi diff --git a/.github/workflows/markdown_files_link_check.yaml b/.github/workflows/markdown_files_link_check.yaml new file mode 100644 index 000000000..9f8205370 --- /dev/null +++ b/.github/workflows/markdown_files_link_check.yaml @@ -0,0 +1,48 @@ +name: Check Markdown Links + +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, reopened, synchronize] + +jobs: + markdown-link-check: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout repository + uses: actions/checkout@v3 + + # Set up Node.js (required for markdown-link-check) + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + # Install markdown-link-check + - name: Install markdown-link-check + run: | + npm install -g markdown-link-check + + - name: Verify config file exists + run: | + ls -la .github/workflows/.markdown-link-check.json + cat .github/workflows/.markdown-link-check.json + + # Check links in all Markdown files + - name: Check links in Markdown files + run: | + # Find all .md files and check their links + find . -name "*.md" | while read file; do + echo ------------------------------------- + if [ markdown-link-check "$file" -c .github/workflows/.markdown-link-check.json -q ]; then + echo "Checking $file" + echo "$file contains broken links" + else + echo "$file contains no broken links" + fi + echo ------------------------------------- + done \ No newline at end of file