DEI draft task page #515
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: Link Checker for Pull requests | |
| on: pull_request | |
| jobs: | |
| changedFiles: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| files: ${{ steps.changed-markdown-files.outputs.all_changed_files }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get changed markdown files | |
| id: changed-markdown-files | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| **/*.md | |
| matrix: true | |
| linkChecker: | |
| runs-on: ubuntu-latest | |
| needs: changedFiles | |
| if: ${{ needs.changedFiles.outputs.files != '' && toJSON(fromJSON(needs.changedFiles.outputs.files)) != '[]' }} | |
| strategy: | |
| matrix: | |
| file: ${{ fromJSON(needs.changedFiles.outputs.files) }} | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Download Lychee | |
| run: | | |
| wget https://github.com/lycheeverse/lychee/releases/download/lychee-v0.19.1/lychee-x86_64-unknown-linux-gnu.tar.gz | |
| tar xzf lychee-x86_64-unknown-linux-gnu.tar.gz | |
| - name: Check added lines in file for broken links | |
| run: | | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| HEAD_SHA="${{ github.event.pull_request.head.sha }}" | |
| echo "Checking links in changed lines of: ${{ matrix.file }}" | |
| # Extract raw added lines from diff | |
| DIFF=$(git diff -U0 "$BASE_SHA" "$HEAD_SHA" -- ${{ matrix.file }} | \ | |
| grep -v "+++" | grep "^+" | cut -c 2-) | |
| if [ -z "$DIFF" ]; then | |
| echo "No added lines at all. Skipping." | |
| exit 0 | |
| fi | |
| # Extract only actual URLs from added lines | |
| LINK_LINES=$(echo "$DIFF" | grep -Eo '(https?://[^ )\]}]+|www\.[^ )\]}]+)' || true) | |
| if [ -z "$LINK_LINES" ]; then | |
| echo "Added lines contain no URLs. Skipping link checking." | |
| exit 0 | |
| fi | |
| echo "Running Lychee on extracted links:" | |
| echo "$LINK_LINES" | |
| echo "$LINK_LINES" | \ | |
| ./lychee \ | |
| --fallback-extensions=md \ | |
| --exclude-all-private \ | |
| --exclude support.posit.co \ | |
| --exclude www.intel.com \ | |
| --exclude reddit.com \ | |
| --exclude jsfiddle.net \ | |
| --exclude 'file://' |