name: Validate links on push + PR

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  workflow_dispatch:

permissions:
  contents: read

jobs:
  lychee:
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6.0.2

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

      - name: Validate links
        uses: lycheeverse/lychee-action@v2.8.0
        with:
          # Check all files, ignore ok/redir/blocked/rate-limited, exclude commonly down domains
          args: >-
            . --no-progress --include-mail
            --include-fragments --index-files README.md,docs/README.md --exclude "#readme"
            --accept 200..299,300..399,403,429
            --cache --max-cache-age 3d
            --exclude api\.star-history\.com --exclude ghostbrowser\.com
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

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