stylua-action
stylua-action copied to clipboard
Action fails to produce any feedback
Now that my favorite coding style is achievable via stylua v2.0.0, I'm working on setting up linting in CI for some projects. I have this a whirl, and it seems to run but I know there is a formatting issue in the code base and the CI output makes it look like all is perfect.
Enabling debug output I can confirm it is running 2.0.0. Copy and pasting the full arguments from the debug output into my local repo does return a falsey exit status and 3 lines of diff. But in CI it just succedes.
Here is the output of a debug run.
Any clues?
Interesting, enabling verbose mode shows that everything is getting ignored -https://github.com/JohnnyMorganz/sile/actions/runs/11898276424/job/33154411083#step:3:152:
debug: ignoring ./packages/autodoc/init.lua: Ignore(IgnoreMatch(Override(Glob(UnmatchedIgnore))))
I wonder why that behaviour is different, because I can also repro the check failure on my own machine
Replacing the single quotes with double quotes worked: https://github.com/JohnnyMorganz/sile/actions/runs/11898498015/job/33155128506
stylua --verbose --check --respect-ignores -g *.lua -g *.lua.in -g *.rockspec.in .busted .luacov .luacheckrc build-aux/config.ld .
TIL, maybe some sort of shell expansion? or we aren't passing through the args correctly in stylua-action? Would help if verbose log would show the parsed opts, i'll add that in
Interesting observation, thanks for looking into it.
I suspect this is GH trying to be too smart. So in any local or sane shell, these args must be quoted the way I have them. Otherwise the shell is going to see the * and expand the glob itself and pass the results instead of passing the glob pattern. The globbing it does is also not going to be the same as stylua would do internally because it is only going to match 1 directory deep, not at every file recursively.
GH Actions might be taking this YAML line and quoting it by work, effectively parsing it "-g" "'*.lua'"* and so forth. That would end up passing the single quotes as part of the glob pattern. The solution is probably do do something to the YAML to quote the whole line instead of each word. I'll look into that, but it is probably worth documenting in the action usage once we figure it out.
Huh, yes. I just realised in the command that I pasted above (which I copied from the GH actions log line), the quotes are missing. But indeed in the YAML I wrote it with double quotes:
args: --verbose --check --respect-ignores -g "*.lua" -g "*.lua.in" -g "*.rockspec.in" .busted .luacov .luacheckrc build-aux/config.ld .
So it seems likely to be the parsing the single quotes as you are saying.
Also added for the next release https://github.com/JohnnyMorganz/StyLua/commit/27721985d05dc5058f795885f90e5348333c9dbe to log the resolved outputs in verbose mode
I tried a variety of quoting and line escape methods and it looks like " quotes are the only reasonably sane way that works. I suspect this is because double quotes are the only ones with meaning in YAML (and JSON) that GH is parsing this to internally and hence escaping. It is also wrapping everything by word in quotes when it passes it to the shell, so that's the only way to not get nested quoting.
I suspect no quotes would work because of the way GH is adding escaping, but that rubs me wrong because it would be bogus in an actual shell. Using double quotes works both on a local shell and in GH Actions (for different reasons) so that's what I'd advise the documentation to recommend.