-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: run shellcheck and shfmt on shell scripts #353490
base: staging
Are you sure you want to change the base?
Conversation
Make sure that once files pass shellcheck linting, they will not be messed up again. Works similar to the check-nix-format workflow in that it allows a transition period for non-conforming files on the target branch.
Consistency is key.
Just to make sure we don’t have a formatting PR without any bikeshedding going on, I would be really happy if we could standardize on 2‐space indentation for our shell files, since our shell in Nix is usually 2‐space indented to match Nix indentation (anything else would look very strange with nested interpolation), and it shouldn’t be harder than necessary to move shell from Nix into separate files; I see no downsides to consistency there. I haven’t read the implementation here in great detail, but I am highly in favour of the principle. One thing I did notice on a quick skim is that Also, it’s nice to be able to run CI checks locally without relying on pushing to GitHub. It would be good if the logic could be implemented in a script in the |
No objection against 2 spaces from my side, for now I went with 4, because that's what Lines 38 to 40 in f946d35
I guess adding
I tried to leave all logic out of it - and it worked quite well. All settings are in config files. Similar to |
Yeah, I just figure if we’re doing a big reformatting commit that needs to go in
Yeah,
Fixing might be easy, but I think there’s still no easy command you can run locally to determine “will CI complain about my PR”, right? That’s what a script in |
Bash is a specific shell, just like Korn, Zsh, csh, etc. Using the "sh" extension for scripts which use a specific syntax is at best confusing, and at worst inviting bugs. Another (minor) advantage of using the "bash" extension is that we won't need |
I agree that standardizing on |
I'd say:
I think we should apply the no-extension-for-executables to all scripts (perl, python, ...) in maintainers, too. Everything that is executable, should "identify" via shebang anyway. |
I think some editors don’t work properly with shebangs and no file extensions, which is a factor we should probably consider. |
True. Especially with the more complex nix-shell shebang, which only references bash on the second line. Actually.. happens for me, too :). So.. all bash = |
That sounds good to me, although I can imagine edge cases where you would want a bona fide |
Ok, so maybe the check needs to be slightly more elaborate: "shebang must match file extension"? |
SGTM. But I’m also okay just mandating |
Wait, another pair of tools that we've all got to integrate into our workflows to continue contributing to nixpkgs? Fun. The weight of all this nonsense is making me too tired to want to continue. |
Shell is really error‐prone and problems caused by Bash foot‐guns in Nixpkgs code are not uncommon; especially for |
@@ -26,5 +26,8 @@ pkgs.mkShellNoCC { | |||
# Helper to review Nixpkgs PRs | |||
# See CONTRIBUTING.md | |||
nixpkgs-review | |||
# Linter and Formatter for shell scripts | |||
shellcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shellcheck-minimal
is the ShellCheck derivation writeShellApplication
uses, which is supposedly easier to bootstrap.
shellcheck | |
shellcheck-minimal |
The |
There have been various efforts for single files to keep them shellcheck'ed and nicely formatted. But none of that will persist without CI.
So let's do that. Here's a proposal to start discussion.
Assuming that the
shellcheck
part is less controversional than theshfmt
part, I added the latter as a second commit on top.CC @emilazy @ShamrockLee with whom this came up in discussions lately.
CC @NixOS/nix-formatting even though this is not about nix files, you might still have an opinion?
Note for how to look at the changed files:
stdenv/generic/setup.sh
are all howshfmt
works (except the very top lines about shellcheck).source=
" would look like.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.