Add a CI linter test for static code checks #2877
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run Tests | |
| on: | |
| push: | |
| branches: [ dev ] | |
| pull_request: | |
| branches: [ dev ] | |
| workflow_dispatch: | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/musholic/lastepochplanner-tests:latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Download LuaLS Addons | |
| run: | | |
| git clone --depth 1 https://github.com/LuaLS/LLS-Addons.git .lls-addons | |
| cd .lls-addons | |
| git submodule update --init --depth 1 addons/busted | |
| git submodule update --init --depth 1 addons/luassert | |
| git submodule update --init --depth 1 addons/luafilesystem | |
| - name: Patch .luarc.json for CI + clean up | |
| run: | | |
| sed -i 's|${addons}|.lls-addons/addons|g' .luarc.json | |
| # Delete the Lua 5.3 specific file so it doesn't break LuaJIT parsing | |
| rm -f runtime/lua/sha1/lua53_ops.lua | |
| # Delete the ModCache which slows down type checking | |
| rm -f src/Data/ModCache.lua | |
| - name: Type Check Code Base | |
| run: lua-language-server --check . --check_format=json --logpath=. | |
| - name: Annotate GitHub PR from check.json | |
| if: always() | |
| run: | | |
| LOG_FILE="check.json" | |
| if [ -f "$LOG_FILE" ]; then | |
| cat $LOG_FILE | jq -r --arg ws "$GITHUB_WORKSPACE" ' | |
| to_entries[] | | |
| # 1. Strip "file://..." prefix and convert to relative path | |
| (.key | sub("file://"; "") | ltrimstr($ws) | ltrimstr("/")) as $file | | |
| # 2. Iterate over issues | |
| .value[] | | |
| # 3. Map LSP severity (1:Error, 2:Warning) to GH format | |
| (if .severity == 1 then "error" else "warning" end) as $sev | | |
| # 4. Convert 0-indexed LSP (line 55, char 0) to 1-indexed GH (line 56, col 1) | |
| # GitHub requires line and col. Optional: endLine, endColumn | |
| "::\($sev) file=\($file),line=\(.range.start.line + 1),col=\(.range.start.character + 1),endLine=\(.range.end.line + 1),endColumn=\(.range.end.character + 1)::\($file): \(.message) (code: \(.code))" | |
| ' | |
| else | |
| echo "::warning::check.json not found, skipping annotations." | |
| fi | |
| run_tests: | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/musholic/lastepochplanner-tests:latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Run tests | |
| run: busted --lua=luajit | |
| - name: Report coverage | |
| continue-on-error: true # May fail on server errors (of coveralls.io) | |
| run: cd src; luacov-coveralls --repo-token=${{ secrets.github_token }} -e TestData -e Data -e runtime | |
| check_modcache: | |
| runs-on: ubuntu-latest | |
| container: ghcr.io/musholic/lastepochplanner-tests:latest | |
| steps: | |
| - name: Install git dependency | |
| run: apk add git | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Regenerate ModCache | |
| env: | |
| LUA_PATH: ../runtime/lua/?.lua;../runtime/lua/?/init.lua | |
| REGENERATE_MOD_CACHE: 1 | |
| run: cd src; luajit HeadlessWrapper.lua | |
| - run: git config --global --add safe.directory $(pwd) | |
| - name: Check if the generated ModCache is different | |
| run: git diff --exit-code src/Data/ModCache.lua |