name: Housekeeping

on:
  schedule:
    - cron: "0 0 * * *"
  workflow_dispatch:
    inputs:
      issueLimit:
        description: Max. number of issues to create
        required: true
        default: "5"

jobs:
  find_closed_references:
    if: github.repository_owner == 'libretime'
    name: Find closed references

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: "16"

      - uses: ory/closed-reference-notifier@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          issueLimit: ${{ github.event.inputs.issueLimit || '5' }}
          ignore: .git,/docs/releases/*,CHANGELOG.md

  find_broken_links:
    if: github.repository_owner == 'libretime'
    name: Find broken links

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/cache@v3
        with:
          path: .lycheecache
          key: housekeeping-find-broken-links-${{ github.sha }}
          restore-keys: housekeeping-find-broken-links-

      - name: Check Links
        id: lychee
        uses: lycheeverse/lychee-action@v1.5.4
        with:
          args: >-
            '**/*.md'
            --require-https
            --exclude-all-private
            --exclude-mail
            --exclude 'example\.(com|org)'
            --exclude '\$server_name\$request_uri'
            --exclude '%7Bvars.version%7D'
            --exclude 'https://dir.xiph.org/cgi-bin/yp-cgi'
            --exclude 'https://radio.indymedia.org/cgi-bin/yp-cgi'
            --exclude 'https://www.ascap.com'
            --exclude 'github\.com/libretime/libretime/(issues|pulls)'
            --cache
            --max-cache-age 2d
          fail: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
