name: Check generated code state

on:
    push:
        branches:
            - "main"
    pull_request:

jobs:
    check-generated-code-state:
        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: Ensure there are no diffs
              run: |
                  git update-index -q --refresh
                  git diff
                  git diff-index --exit-code --quiet HEAD -- || {
                      echo '::error::Generated code is not up to date, run "make generate".';
                      exit 1;
                  }
