|
9 | 9 |
|
10 | 10 | steps: |
11 | 11 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6 |
12 | | - - name: lychee Link Checker |
13 | | - id: lychee |
| 12 | + |
| 13 | + # Blocking: fail the build only on genuinely broken links (4xx/5xx, |
| 14 | + # DNS failures, timeouts). Redirects are accepted here so a moved link |
| 15 | + # does not break CI on its own -- the pass below surfaces those. |
| 16 | + - name: Check for broken links |
| 17 | + id: lychee-broken |
14 | 18 | uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2.9.0 |
15 | 19 | with: |
16 | | - args: --accept=200,403,429 --max-retries=3 --retry-wait-time=10 "**/*.html" "**/*.md" "**/*.txt" "**/*.json" --exclude "https://opensearch-domain.region.com/" --exclude "https://github.com/\[your*" --exclude "https://localhost:9200" --exclude "https://codecov.io/gh/opensearch-project/opensearch-go/branch/main/graph/badge.svg" |
| 20 | + args: --accept=200,206,301,302,307,308,403,429 --max-retries=3 --retry-wait-time=10 "**/*.html" "**/*.md" "**/*.txt" "**/*.json" --exclude "https://opensearch-domain.region.com/" --exclude "https://github.com/\[your*" --exclude "https://localhost:9200" --exclude "https://codecov.io/gh/opensearch-project/opensearch-go/branch/main/graph/badge.svg" |
| 21 | + fail: true |
| 22 | + jobSummary: true |
| 23 | + env: |
| 24 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 25 | + |
| 26 | + # Non-blocking: surface permanent redirects (301/308) so their links can |
| 27 | + # be updated to point at the final destination. --max-redirects=0 makes |
| 28 | + # lychee report the redirect status instead of following it; 302/307 stay |
| 29 | + # accepted because temporary redirects are not a signal to rewrite a link. |
| 30 | + # LICENSE.txt/NOTICE.txt are excluded here: their URLs are canonical |
| 31 | + # license text and standard attribution wording, not links to rewrite. |
| 32 | + # fail:false + if:always() so this always reports without breaking CI. |
| 33 | + - name: Check for permanently-redirecting links |
| 34 | + id: lychee-redirects |
| 35 | + if: always() |
| 36 | + uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2.9.0 |
| 37 | + with: |
| 38 | + args: --accept=200,206,302,307,403,429 --max-redirects=0 --max-retries=3 --retry-wait-time=10 --exclude-path LICENSE.txt --exclude-path NOTICE.txt "**/*.html" "**/*.md" "**/*.txt" "**/*.json" --exclude "https://opensearch-domain.region.com/" --exclude "https://github.com/\[your*" --exclude "https://localhost:9200" --exclude "https://codecov.io/gh/opensearch-project/opensearch-go/branch/main/graph/badge.svg" |
| 39 | + fail: false |
| 40 | + jobSummary: true |
| 41 | + output: lychee/redirects.md |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 44 | + |
| 45 | + # Turn each redirect the pass above found into a PR annotation, so a moved |
| 46 | + # link shows up inline on the PR (Files changed + checks summary) instead |
| 47 | + # of only in the run's job summary. Never fails the build. |
| 48 | + - name: Annotate redirecting links |
| 49 | + if: always() |
| 50 | + run: | |
| 51 | + report="lychee/redirects.md" |
| 52 | + [ -f "$report" ] || { echo "no redirect report found; nothing to annotate"; exit 0; } |
| 53 | + awk ' |
| 54 | + /^### Errors in / { file=$0; sub(/^### Errors in /, "", file); next } |
| 55 | + /^\* \[30[0-9]\]/ { |
| 56 | + url=$0; sub(/^[^<]*</, "", url); sub(/>.*/, "", url) |
| 57 | + code=$0; sub(/^\* \[/, "", code); sub(/\].*/, "", code) |
| 58 | + line=""; col=""; tmp=$0 |
| 59 | + if (sub(/^.*\(at /, "", tmp) && match(tmp, /^[0-9]+:[0-9]+/)) { |
| 60 | + pos=substr(tmp, 1, RLENGTH); split(pos, a, ":"); line=a[1]; col=a[2] |
| 61 | + } |
| 62 | + printf "::warning file=%s,line=%s,col=%s,title=Redirecting link::%s redirects (%s) -- update to its final destination\n", file, line, col, url, code |
| 63 | + } |
| 64 | + ' "$report" |
17 | 65 | env: |
18 | 66 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
19 | | - - name: Fail if there were link errors |
20 | | - run: exit ${{ steps.lychee.outputs.exit_code }} |
|
0 commit comments