name: Cleanup cspell.json

on:
  workflow_dispatch:
  schedule:
    # “At 00:00 on day-of-month 1 in July.” https://crontab.guru/#0_0_1_7_*
    - cron: "0 0 1 7 *"

permissions:
  pull-requests: write
  contents: write

jobs:
  run:
    name: Cleanup cspell.json
    if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

      - name: Setup Node.js
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          cache: "yarn"

      - name: Install Dependencies
        run: yarn install --immutable

      - name: Run script
        run: node scripts/clean-cspell.js

      - name: Set current date env
        run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"

      - uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          commit-message: Cleanup cspell.json (${{ env.CURRENT_DATE }})
          branch: automated-cleanup-cspell-${{ env.CURRENT_DATE }}
          branch-suffix: timestamp
          title: Cleanup cspell.json (${{ env.CURRENT_DATE }})
