name: 'Issue and PR Maintenance'

on:
  schedule:
    - cron: '0 0 * * *'   # runs at midnight UTC
  workflow_dispatch:

permissions:
  actions: write
  issues: write
  pull-requests: write

jobs:
  lock-inactive:
    name: Lock Inactive Issues
    runs-on: ubuntu-24.04
    steps:
      - uses: klaasnicolaas/action-inactivity-lock@v1.1.3
        id: lock
        with:
          days-inactive-issues: 14
          lock-reason-issues: ""
          # Action can not skip PRs, set it to 100 years to cover it.
          days-inactive-prs: 36524
          lock-reason-prs: ""

  close-stale:
    name: Close Stale Issues
    runs-on: ubuntu-24.04
    steps:
      - name: Close Stale Issues
        uses: actions/stale@v10
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

          # Messaging
          stale-issue-message: >
            👋 This issue has been automatically marked as stale due to inactivity.
            If this issue is still relevant, please comment to keep it open.
            Without activity, it will be closed in 7 days.

          close-issue-message: >
            🔒 This issue has been automatically closed due to prolonged inactivity.
            Feel free to open a new issue if you have further questions or concerns.

          # Timing
          days-before-issue-stale: 14
          days-before-issue-close: 7
          # Action can not skip PRs, set it to 100 years to cover it.
          days-before-pr-stale: 36524

          # Max issues to process before early exit. Next run resumes from cache. GH API limit: 5000.
          operations-per-run: 1500

          # Labels
          stale-issue-label: 'stale'
          remove-stale-when-updated: true
          any-of-labels: 'awaiting-requester'
          exempt-issue-labels: 'enhancement' 

          # Exemptions
          exempt-assignees: true

          exempt-milestones: true
