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.2.2

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

      - name: Link Checker
        uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1
        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@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
        with:
          path: .lycheecache
          key: ${{ steps.cache-restore.outputs.cache-primary-key }}
