diff --git a/.github/workflows/link-check-cache.yml b/.github/workflows/link-check-cache.yml new file mode 100644 index 000000000..76f3e207b --- /dev/null +++ b/.github/workflows/link-check-cache.yml @@ -0,0 +1,39 @@ +# Cache link check results on each commit to main. + +name: Lychee Cache Update + +on: + push: + branches: [main] + +jobs: + lychee-cache-update: + name: Lychee Link Checking + runs-on: ubuntu-latest + + steps: + - name: Check out repo + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + + - name: Restore Lychee cache + id: restore-cache + uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 + with: + path: .lycheecache + key: cache-lychee-${{ github.event.before }} + restore-keys: cache-lychee- + + - name: Run Lychee + uses: lycheeverse/lychee-action@a8c4c7cb88f0c7386610c35eb25108e448569cb0 # v2.7.0 + with: + fail: false + format: markdown + jobSummary: true + args: > + -c lychee.toml --root-dir "$(pwd)" './**/*.mdx' + + - name: Update Lychee cache + uses: actions/cache/save@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 + with: + path: .lycheecache + key: cache-lychee-${{ github.event.after }} diff --git a/.github/workflows/link-check.yml b/.github/workflows/link-check.yml index 34c1bf37f..da5c518a0 100644 --- a/.github/workflows/link-check.yml +++ b/.github/workflows/link-check.yml @@ -1,7 +1,8 @@ +# Check links on changed MDX files in PRs. + name: Lychee Link Checking on: - # Run on PRs targeting main that change content files. pull_request: branches: [main] paths: ['**/*.mdx?'] @@ -24,8 +25,17 @@ jobs: files: | **.mdx + - name: Restore Lychee cache + uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 + if: steps.changed-mdx-files.outputs.any_changed == 'true' + with: + path: .lycheecache + key: cache-lychee-${{ github.event.pull_request.base.sha }} + restore-keys: cache-lychee- + - name: Run Lychee uses: lycheeverse/lychee-action@a8c4c7cb88f0c7386610c35eb25108e448569cb0 # v2.7.0 + if: steps.changed-mdx-files.outputs.any_changed == 'true' with: fail: false format: markdown @@ -37,5 +47,6 @@ jobs: - name: Comment on PR with link check results uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4 + if: steps.changed-mdx-files.outputs.any_changed == 'true' with: path: lychee/out.md diff --git a/lychee.toml b/lychee.toml index 561b596c4..2e482439b 100644 --- a/lychee.toml +++ b/lychee.toml @@ -11,9 +11,9 @@ include_verbatim = false # Don't check links inside code blocks exclude_all_private = true # Exclude link local, loopback, and private IPs. # Cache only successful results to avoid re-checking valid links. -# TODO: Update GitHub Action to use the cache cache = true cache_exclude_status = "300.." +max_cache_age = "7d" # Set a root dir so Lychee can resolve relative links to URIs, even though we # exclude relative links in the actual check.