name: Links (Fail Fast)

on:
  push:
    branches:
      - main
  pull_request:

# Declare default permissions as read only.
permissions: read-all

jobs:
  check-links:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

      - name: Restore lychee cache
        uses: actions/cache/restore@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
        id: cache-restore
        with:
          path: .lycheecache
          key: cache-lychee-${{ github.sha }}
          restore-keys: cache-lychee-

      - name: Link Checker
        uses: lycheeverse/lychee-action@f613c4a64e50d792e0b31ec34bbcbba12263c6a6 # v2.3.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          fail: true
          args: --max-concurrency 5 --cache --max-cache-age 1d --cache-exclude-status 300..=599 .

      - name: Save lychee cache
        if: always()
        uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
        with:
          path: .lycheecache
          key: ${{ steps.cache-restore.outputs.cache-primary-key }}
