name: Check README parser info

on:
  push:
    branches:
      - master

jobs:
  update-readme:
    name: Check README parser info
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Prepare
        env:
          NVIM_TAG: stable
        run: |
          sudo apt-get update
          sudo add-apt-repository universe
          wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim.appimage
          chmod u+x nvim.appimage
          mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
          ln -s $(pwd) ~/.local/share/nvim/site/pack/nvim-treesitter/start

      - name: Check README
        run: |
          git config user.email "actions@github"
          git config user.name "Github Actions"
          ./nvim.appimage --headless -c "luafile ./scripts/update-readme.lua" -c "q" || echo "Needs update"
          git add README.md
          git commit -m "Update README" || echo 'No commit necessary!'
          git clean -xf

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          commit-message: Update README
          title: Update README
          branch: update-readme-pr
          base: ${{ github.head_ref }}
