Update broken-links.yml #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check README for Broken Links | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| check-links: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| # Step 1: Checkout the repository code | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Step 2: Set up Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| # Step 3: Install the markdown-link-check tool globally | |
| - name: Install markdown-link-check | |
| run: npm install -g markdown-link-check | |
| # Step 4: Check README links and log the results | |
| - name: Check README links | |
| id: check-links | |
| run: | | |
| # Run markdown-link-check and store the results | |
| markdown-link-check --verbose README.md > link-check-results.txt || true | |
| # Output the results for debugging | |
| echo "::group::Link Check Results" | |
| cat link-check-results.txt | |
| echo "::endgroup::" | |
| # Step 5: Analyze and Annotate Results | |
| - name: Annotate Results | |
| run: | | |
| # Extract broken links, excluding any from ./Assets | |
| broken_links=$(grep -B 1 "✖" link-check-results.txt | grep -v "./Assets" || true) | |
| # Count total links and broken links | |
| total_links=$(grep -oE '.?' link-check-results.txt | wc -l) | |
| broken_count=$(echo "$broken_links" | grep -c "✖" || echo "0") | |
| excluded_assets=$(grep -c './Assets' link-check-results.txt || echo "0") | |
| # Display summary | |
| echo "Total links checked: $total_links" | |
| echo "Broken links found (excluding ./Assets): $broken_count" | |
| echo "Broken links excluded from ./Assets: $excluded_assets" | |
| # Check if there are broken links | |
| if [ -n "$broken_links" ]; then | |
| echo "::error title=Broken Links Found::The following links are broken (excluding ./Assets):" | |
| echo "$broken_links" | sed 's/%/%25/g; s/\n/%0A/g; s/\r/%0D/g' | |
| echo "Summary: $broken_count broken links found out of $total_links total links." | |
| exit 1 | |
| else | |
| echo "::notice title=All Links Valid::All links in the README are valid." | |
| echo "Summary: All $total_links links are valid." | |
| fi |