name: Links

on:
  repository_dispatch:
  workflow_dispatch:
  schedule:
  # Everyday at 9:00 AM.
  - cron: "0 9 * * *"

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

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


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

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

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

    - name: Create Issue From File
      if: steps.lychee.outputs.exit_code != 0
      uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd # v5
      with:
        title: Link Checker Report
        content-filepath: ./lychee/out.md
        labels: report, bot-generated
