name: Update supported languages
on:
  schedule:
    - cron: "0 0 */30 * *"

permissions:
  actions: read
  checks: read
  contents: read
  deployments: read
  issues: read
  discussions: read
  packages: read
  pages: read
  pull-requests: write
  repository-projects: read
  security-events: read
  statuses: read

jobs:
  updateLanguages:
    if: github.repository == 'anuraghazra/github-readme-stats'
    name: Update supported languages
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]

    steps:
      - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

      - name: Setup Node
        uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
        with:
          node-version: ${{ matrix.node-version }}
          cache: npm

      - name: Install dependencies
        run: npm ci
        env:
          CI: true

      - name: Run update-languages-json.js script
        run: npm run generate-langs-json

      - name: Create Pull Request if upstream language file is changed
        uses: peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54 # v4.2.4
        with:
          commit-message: "refactor: update languages JSON"
          branch: "update_langs/patch"
          delete-branch: true
          title: Update languages JSON
          body:
            "The
            [update-langs](https://github.com/anuraghazra/github-readme-stats/actions/workflows/update-langs.yaml)
            action found new/updated languages in the [upstream languages JSON
            file](https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml)."
          labels: "ci, lang-card"