|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Check documentation links |
| 6 | +description: Check authored or rendered documentation with shared nightly caches and bounded retries |
| 7 | + |
| 8 | +inputs: |
| 9 | + kind: |
| 10 | + description: "Input kind: authored or rendered" |
| 11 | + required: true |
| 12 | + refresh-cache: |
| 13 | + description: Check links afresh and publish a new cache baseline |
| 14 | + default: "false" |
| 15 | + failure-policy: |
| 16 | + description: "check allows up to 10 rate-limited URLs; cache-warm warns on all link failures" |
| 17 | + default: check |
| 18 | + |
| 19 | +# Callers provide Python 3.10+ on PATH; the helpers use only its standard library. |
| 20 | +runs: |
| 21 | + using: composite |
| 22 | + steps: |
| 23 | + - name: Prepare link-check inputs and cache policy |
| 24 | + id: inputs |
| 25 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 26 | + env: |
| 27 | + KIND: ${{ inputs.kind }} |
| 28 | + LYCHEE_VERSION: v0.24.2 # Must match the pinned rev in .pre-commit-config.yaml |
| 29 | + POLICY_HASH: ${{ hashFiles('lychee.toml', '.github/actions/check-doc-links/action.yml', 'ci/tools/prepare_lychee_inputs.py', 'ci/tools/retry_lychee.py') }} |
| 30 | + # The first pass and all retries use the same inputs and cache policy. |
| 31 | + LYCHEE_ARGS: >- |
| 32 | + --files-from "${{ github.workspace }}/lychee-${{ inputs.kind }}-files.txt" |
| 33 | + ${{ inputs.kind == 'rendered' && '--include-fragments=full' || '' }} |
| 34 | + --cache |
| 35 | + --max-cache-age 1d |
| 36 | + --max-concurrency 16 |
| 37 | + --host-concurrency 2 |
| 38 | + --host-request-interval 250ms |
| 39 | + --max-retries 3 |
| 40 | + --retry-wait-time 5 |
| 41 | + --timeout 30 |
| 42 | + --no-progress |
| 43 | + --config "${{ github.workspace }}/lychee.toml" |
| 44 | + run: | |
| 45 | + python "${GITHUB_WORKSPACE}/ci/tools/prepare_lychee_inputs.py" "${KIND}" \ |
| 46 | + --output "${GITHUB_WORKSPACE}/lychee-${KIND}-files.txt" |
| 47 | + # Keep authored checks separate from rendered checks, which also |
| 48 | + # validate fragments. Both callers must use the same cache paths. |
| 49 | + mkdir -p "${RUNNER_TEMP}/lychee-${KIND}" |
| 50 | + prefix="lychee-v1-${LYCHEE_VERSION}-${KIND}-${POLICY_HASH}-baseline-" |
| 51 | + echo "prefix=${prefix}" >> "${GITHUB_OUTPUT}" |
| 52 | + echo "key=${prefix}${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" >> "${GITHUB_OUTPUT}" |
| 53 | + echo "version=${LYCHEE_VERSION}" >> "${GITHUB_OUTPUT}" |
| 54 | + echo "args=${LYCHEE_ARGS}" >> "${GITHUB_OUTPUT}" |
| 55 | +
|
| 56 | + - name: Restore successful checks from the nightly baseline |
| 57 | + if: ${{ inputs.refresh-cache != 'true' }} |
| 58 | + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 59 | + with: |
| 60 | + path: ${{ runner.temp }}/lychee-${{ inputs.kind }}/.lycheecache |
| 61 | + key: ${{ steps.inputs.outputs.key }} |
| 62 | + restore-keys: ${{ steps.inputs.outputs.prefix }} |
| 63 | + |
| 64 | + - name: Check documentation links |
| 65 | + id: lychee |
| 66 | + uses: lycheeverse/lychee-action@6da1d14f3a43098a294b7696d93d938aa8d20fc0 # supports v0.24.x archive layout |
| 67 | + with: |
| 68 | + args: ${{ steps.inputs.outputs.args }} |
| 69 | + # The next step owns bounded retries and the final success gate. |
| 70 | + fail: false |
| 71 | + # The action's empty-report guard only understands Markdown. |
| 72 | + # Our helper validates the JSON report and rejects zero checked links. |
| 73 | + failIfEmpty: false |
| 74 | + format: json |
| 75 | + jobSummary: false |
| 76 | + lycheeVersion: ${{ steps.inputs.outputs.version }} |
| 77 | + workingDirectory: ${{ runner.temp }}/lychee-${{ inputs.kind }} |
| 78 | + output: ${{ github.workspace }}/lychee-${{ inputs.kind }}.json |
| 79 | + token: ${{ github.token }} |
| 80 | + |
| 81 | + - name: Retry transient link failures using cached successful checks |
| 82 | + if: ${{ steps.lychee.outcome == 'success' }} |
| 83 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 84 | + working-directory: ${{ runner.temp }}/lychee-${{ inputs.kind }} |
| 85 | + env: |
| 86 | + EXIT_CODE: ${{ steps.lychee.outputs.exit_code }} |
| 87 | + REPORT: ${{ github.workspace }}/lychee-${{ inputs.kind }}.json |
| 88 | + LYCHEE_ARGS: ${{ steps.inputs.outputs.args }} |
| 89 | + FAILURE_POLICY: ${{ inputs.failure-policy }} |
| 90 | + GITHUB_TOKEN: ${{ github.token }} |
| 91 | + run: | |
| 92 | + python "${GITHUB_WORKSPACE}/ci/tools/retry_lychee.py" \ |
| 93 | + --initial-exit-code "${EXIT_CODE}" --report "${REPORT}" \ |
| 94 | + --max-attempts 3 --policy "${FAILURE_POLICY}" |
| 95 | +
|
| 96 | + - name: Publish fresh successful checks |
| 97 | + # Manual branch tests publish isolated branch caches. Nightly callers |
| 98 | + # on the default branch publish the baseline that all PRs can restore. |
| 99 | + if: ${{ always() && inputs.refresh-cache == 'true' && steps.inputs.outputs.key != '' }} |
| 100 | + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 101 | + with: |
| 102 | + path: ${{ runner.temp }}/lychee-${{ inputs.kind }}/.lycheecache |
| 103 | + key: ${{ steps.inputs.outputs.key }} |
| 104 | + |
| 105 | + - name: Upload link-check report |
| 106 | + if: ${{ always() }} |
| 107 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 108 | + with: |
| 109 | + name: lychee-${{ inputs.kind }}-${{ github.run_id }}-${{ github.run_attempt }} |
| 110 | + path: | |
| 111 | + ${{ github.workspace }}/lychee-${{ inputs.kind }}*.json |
| 112 | + ${{ github.workspace }}/lychee-${{ inputs.kind }}*.md |
| 113 | + if-no-files-found: ignore |
| 114 | + retention-days: 7 |
0 commit comments