name: Autogenerate code

on:
    workflow_dispatch:
    schedule:
        - cron: "0 10 * * *"

jobs:
    autogenerate:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - uses: rhysd/action-setup-vim@v1
              with:
                  neovim: true
                  version: v0.10.1

            - name: make generate
              run: make generate

            - name: Create Pull Request
              id: cpr
              uses: peter-evans/create-pull-request@v4
              with:
                  token: ${{ secrets.PAT }}
                  author: "William Botman <william+bot@redwill.se>"
                  committer: "William Botman <william+bot@redwill.se>"
                  add-paths: lua/mason-lspconfig
                  commit-message: "chore: update generated code"
                  branch: chore/generate
                  branch-suffix: short-commit-hash
                  delete-branch: true
                  labels: automerge
                  title: "chore: update generated code"

            - name: Enable Pull Request Automerge
              if: steps.cpr.outputs.pull-request-operation == 'created'
              uses: peter-evans/enable-pull-request-automerge@v2
              with:
                  token: ${{ secrets.PAT }}
                  pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
                  merge-method: squash
