ci: parse LuaLS json output instead of the pretty output - #7877
Conversation
The step summary counted lines containing "Warning":
$(cat luals-check | grep 'Warning' | wc -l)
That gives 263 where LuaLS itself reports 238, because a single diagnostic can
span several lines. Use the totals LuaLS prints, and add files-with-problems
alongside them.
No delta is reported against the base, because the count is not deterministic:
237-240 across 8 runs on identical code, in both pretty and json output, with no
--threads flag to pin the analysis. Files-with-problems was stable at 142 in
every run, so that is the number worth watching, and the summary says as much.
Gating behaviour is untouched; only the summary lines change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two unrelated changes were sharing a branch: a new metric and a fix to an existing one. Split so they can be reviewed and reverted independently. The LuaLS summary fix now lives in #7877. luals-code-style here is byte identical to main again; this branch only adds annotation coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
I didn't know there is a JSON format available for output (it's not in the documentation on luals.github.io). |
Per review (@mbergen): --check_format=json plus jq, rather than stripping ANSI codes and pulling totals out of prose. This removes the reason for the previous commit. Counting lines containing "Warning" gave 263 against LuaLS's own 238, because one diagnostic can span several lines; counting array elements cannot go wrong that way, so the fix becomes moot rather than needing to be gotten right. The old pipeline also only surfaced annotations as a side effect: the ::error lines were piped into grep, so they reached the log only because grep echoes the lines it matches, and the exit status came from inverting that grep. Now annotations and the pass/fail decision are both explicit, and the summary gains a count of problems in changed files -- the number that actually gates. Three details that needed checking rather than assuming: - JSON line/character are 0-based where the pretty output and the annotations are 1-based, so both need +1. Verified against pretty for two files: 27:23 and 42:2 either way. - A clean run writes `[]`, not `{}`, so `[.[] | length] | add` yields null and the summary would say "null problems". Hence `// 0`. - Messages can contain newlines, which would break the ::error command, so they are flattened. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Done in 3f92ac7 — good call, it's a much better fit. It also removes the reason this PR existed. The original fix was to stop One thing worth knowing about the old pipeline while we're here: sed -n 's/.../::error file=,line=/p' | (! grep -E "$changed_files")The Three details that needed checking rather than assuming:
Verified in CI on a throwaway branch, both paths: a clean changed file passes with Also — you're right that it isn't on luals.github.io. It's only in |
Removing one echo left the sentence hanging mid-clause with no closing underscore, so the summary rendered a broken italic. Taking the other half out as well. The caveat itself still holds -- the count moved between 237 and 240 across 8 runs on identical code -- it just does not need to be restated on every run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
The
luals-code-stylestep scraped LuaLS's human-readable output — stripping ANSI codes, then pulling counts out of prose. Now it uses--check_format=jsonandjq.grep -c 'Warning'reported 263 where LuaLS itself said 238 (one diagnostic can span several lines).::errorlines were piped intogrep, so they only reached the log because grep echoes what it matches, and the exit status came from inverting that grep.Gating behaviour is unchanged: annotate and fail only for files the PR touches.
How it was tested
luals-code-styleskips unlesslua/wikis/**/*.luachanges, so both paths were verified on a throwaway branch (since deleted):In changed files: 0, job passesIn changed files: 1, job fails, and GitHub registered the annotation atFilterButtons/Config.lua:27— the exact line predicted locallyAlso checked locally: JSON line/character are 0-based where annotations are 1-based (verified both
27:23and42:2against the pretty output), a clean run writes[]rather than{}so the count needs// 0, and multi-line messages are flattened so they don't break the workflow command.