Microsoft Learn Link Monitor #1
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: Microsoft Learn Link Monitor | |
| on: | |
| workflow_dispatch: # Manual trigger only | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check-ms-learn: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Extract Microsoft Learn URLs | |
| run: | | |
| echo "Extracting all Microsoft Learn links..." | |
| grep -roh 'https://learn\.microsoft\.com[^)]*' docs/ | sort -u > ms-learn-urls.txt || true | |
| grep -roh 'https://docs\.microsoft\.com[^)]*' docs/ | sort -u >> ms-learn-urls.txt || true | |
| # Count total links | |
| LINK_COUNT=$(wc -l < ms-learn-urls.txt) | |
| echo "Found $LINK_COUNT unique Microsoft Learn links" | |
| echo "LINK_COUNT=$LINK_COUNT" >> $GITHUB_ENV | |
| - name: Check each URL | |
| run: | | |
| echo "# Microsoft Learn Link Status" > link-report.md | |
| echo "" >> link-report.md | |
| echo "**Total Links Checked:** $(wc -l < ms-learn-urls.txt)" >> link-report.md | |
| echo "" >> link-report.md | |
| BROKEN_COUNT=0 | |
| while read url; do | |
| # Clean URL (remove trailing characters) | |
| clean_url=$(echo "$url" | sed 's/[,;.)]*$//') | |
| status=$(curl -o /dev/null -s -w "%{http_code}" -L "$clean_url" || echo "000") | |
| if [ "$status" != "200" ]; then | |
| echo "## ❌ BROKEN: Status $status" >> link-report.md | |
| echo "\`$clean_url\`" >> link-report.md | |
| echo "" >> link-report.md | |
| BROKEN_COUNT=$((BROKEN_COUNT + 1)) | |
| fi | |
| done < ms-learn-urls.txt | |
| echo "BROKEN_COUNT=$BROKEN_COUNT" >> $GITHUB_ENV | |
| if [ $BROKEN_COUNT -eq 0 ]; then | |
| echo "## ✅ All Microsoft Learn links working!" >> link-report.md | |
| fi | |
| - name: Create issue if broken links found | |
| if: env.BROKEN_COUNT != '0' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const report = fs.readFileSync('link-report.md', 'utf8'); | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: '🔗 Microsoft Learn Links Need Update', | |
| body: `${report}\n\n---\n\n**Action Required:**\n1. Search for each broken URL in the \`docs/\` folder\n2. Find the updated URL on Microsoft Learn\n3. Update the markdown files\n4. Test the new links\n\n**Note:** Microsoft Learn URLs may have been redirected, moved, or retired.\n\n**Workflow Run:** ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| labels: ['maintenance', 'microsoft-learn', 'broken-links'] | |
| }) | |
| - name: Report success | |
| if: env.BROKEN_COUNT == '0' | |
| run: | | |
| echo "✅ SUCCESS: All ${{ env.LINK_COUNT }} Microsoft Learn links are working!" |