name: Lint

on:
  workflow_call:
    inputs:
      dfhack_ref:
        type: string
      scripts_ref:
        type: string

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - name: Install Lua
      run: |
        sudo apt-get update
        sudo apt-get install lua5.3
    - name: Clone DFHack
      uses: actions/checkout@v3
      with:
        repository: ${{ inputs.dfhack_ref && github.repository || 'DFHack/dfhack' }}
        ref: ${{ inputs.dfhack_ref }}
    - name: Get scripts submodule ref
      if: '!inputs.scripts_ref'
      id: scriptssubmoduleref
      run: echo ref=$(git submodule | fgrep scripts | cut -c2-41) >> $GITHUB_OUTPUT
    - name: Clone scripts
      uses: actions/checkout@v3
      with:
        repository: ${{ inputs.scripts_ref && github.repository || 'DFHack/scripts' }}
        ref: ${{ inputs.scripts_ref || steps.scriptssubmoduleref.outputs.ref }}
        path: scripts
    - name: Check whitespace
      run: python ci/lint.py --git-only --github-actions
    - name: Check Authors.rst
      if: always()
      run: python ci/authors-rst.py
    - name: Check for missing documentation
      if: always()
      run: python ci/script-docs.py
    - name: Check Lua syntax
      if: always()
      run: python ci/script-syntax.py --ext=lua --cmd="luac5.3 -p" --github-actions