name: Validate existing links

on:
  push:
  repository_dispatch:
  workflow_dispatch:
  schedule:
    - cron: "00 18 * * *"

jobs:
  linkChecker:
    permissions:
      contents: write
      issues: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Link Checker
        id: lychee
        uses: lycheeverse/lychee-action@master
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
        with:
          args: --accept=200,429,403,502,503 --verbose --no-progress './**/*.md'
          fail: true

      - name: Create Issue From File
        if: always() && env.lychee_exit_code != 0 && github.event_name != 'pull_request'
        uses: peter-evans/create-issue-from-file@main
        with:
          title: Link Checker Report
          content-filepath: ./lychee/out.md
          labels: report, automated issue