name: lua_lint

# Lint on lua changes on builtin or if workflow changed
on:
  push:
    paths:
      - 'builtin/**.lua'
      - 'games/devtest/**.lua'
      - '.github/workflows/**.yml'
  pull_request:
    paths:
      - 'builtin/**.lua'
      - 'games/devtest/**.lua'
      - '.github/workflows/**.yml'

jobs:
  # Note that the integration tests are also run in build.yml, but only when C++ code is changed.
  integration_tests:
    name: "Compile and run multiplayer tests"
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@v4
    - name: Install deps
      run: |
        source ./util/ci/common.sh
        install_linux_deps clang gdb libluajit-5.1-dev

    - name: Build
      run: |
        ./util/ci/build.sh
      env:
        CC: clang
        CXX: clang++
        CMAKE_FLAGS: "-DENABLE_GETTEXT=0 -DBUILD_SERVER=0 -DBUILD_UNITTESTS=0"

    - name: Integration test + devtest
      run: |
        ./util/test_multiplayer.sh

  luacheck:
    name: "Builtin Luacheck and Unit Tests"
    runs-on: ubuntu-20.04

    steps:

    - uses: actions/checkout@v4
    - uses: leafo/gh-actions-lua@v10
      with:
        luaVersion: "5.1.5"
    - uses: leafo/gh-actions-luarocks@v4.3.0

    - name: Install LuaJIT
      run: |
        cd $HOME
        git clone https://github.com/LuaJIT/LuaJIT/
        cd LuaJIT
        make -j$(nproc)

    - name: Install luarocks tools
      run: |
        luarocks install --local luacheck
        luarocks install --local busted

    - name: Run checks (builtin)
      run: |
        $HOME/.luarocks/bin/luacheck builtin
        $HOME/.luarocks/bin/busted builtin
        $HOME/.luarocks/bin/busted builtin --lua=$HOME/LuaJIT/src/luajit

    - name: Run checks (devtest)
      run: |
        $HOME/.luarocks/bin/luacheck --config=games/devtest/.luacheckrc games/devtest
