Skip to content
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

shellcheck/shfmt more files; run check-config in CI #3378

Merged
merged 7 commits into from
Apr 14, 2022

Conversation

kolyshkin
Copy link
Contributor

This almost fixes the TODO item for shellcheck.

Please review commit-by-commit; see individual commits for details.

@kolyshkin kolyshkin force-pushed the ci-verify-more branch 2 times, most recently from 7573e7e to 60581d8 Compare February 16, 2022 22:32
@kolyshkin kolyshkin changed the title shellcheck/shfmt more files; run check-config in CI shellcheck/shfmt more files; run check-config in CI; bump shfmt Feb 16, 2022
@kolyshkin kolyshkin changed the title shellcheck/shfmt more files; run check-config in CI; bump shfmt shellcheck/shfmt more files; run check-config in CI Feb 16, 2022
@kolyshkin
Copy link
Contributor Author

@tianon PTAL 🙏🏻

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully my suggestions on these PRs aren't making you regret asking me for my thoughts on them 😂 😇

Generally speaking, I try to avoid bash-isms unless they provide obvious value (or I know for certain the script will never want or need to become /bin/sh). This makes sure that when I do have to write /bin/sh (such as in Dockerfile RUN lines 😅), I'm not constantly getting the syntax wrong because my muscle memory is already mostly right. 😄

man/md2man-all.sh Outdated Show resolved Hide resolved
script/check-config.sh Outdated Show resolved Hide resolved
script/check-config.sh Outdated Show resolved Hide resolved
script/check-config.sh Outdated Show resolved Hide resolved
@@ -118,8 +120,7 @@ is_config() {
}

search_config() {
local target_dir="$1"
[[ "$target_dir" ]] || target_dir=("${possibleConfigs[@]}")
local target_dir=("${1:-${possibleConfigs[@]}}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if the quoting here would have the right effect, but it appears that it does!

$ arr=( 'foo bar' 'baz' ); foo() { local foo=("${1:-${arr[@]}}"); local bar; for bar in "${foo[@]}"; do echo "$bar"; done; }; foo bar; foo
bar
foo bar
baz

script/check-config.sh Outdated Show resolved Hide resolved
script/check-config.sh Outdated Show resolved Hide resolved
fi
fi
}

if [ "$kernelMajor" -lt 4 ] || [ "$kernelMajor" -eq 4 -a "$kernelMinor" -le 5 ]; then
if [ "$kernelMajor" -lt 4 ] || [[ "$kernelMajor" -eq 4 && "$kernelMinor" -le 5 ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ "$kernelMajor" -lt 4 ] || [[ "$kernelMajor" -eq 4 && "$kernelMinor" -le 5 ]]; then
if [ "$kernelMajor" -lt 4 ] || { [ "$kernelMajor" -eq 4 ] && [ "$kernelMinor" -le 5 ]; }; then

script/check-config.sh Outdated Show resolved Hide resolved
script/check-config.sh Outdated Show resolved Hide resolved
@kolyshkin
Copy link
Contributor Author

@tianon addressed all your comments; PTAL

@tianon
Copy link
Member

tianon commented Mar 9, 2022

Nice! I love how much cleaner your kernel_lt function makes those checks 😍

@kolyshkin
Copy link
Contributor Author

@thaJeztah @AkihiroSuda PTAL

@kolyshkin
Copy link
Contributor Author

@thaJeztah @AkihiroSuda PTAL (this was already blessed by @tianon)

thaJeztah
thaJeztah previously approved these changes Mar 21, 2022
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice!

@kolyshkin
Copy link
Contributor Author

kolyshkin commented Mar 23, 2022

Rebased (no changed, just a merge conflict in .cirrus.yml). PTAL @thaJeztah @AkihiroSuda 🙏🏻

thaJeztah
thaJeztah previously approved these changes Mar 23, 2022
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still LGTM

…and fix a single format issue found.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Allow wrap_bad and wrap_good to have an optional arguments.

2. Remove unneeded echos; this fixes the shellcheck warnings like

	In ./script/check-config.sh line 178:
			echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')"
                             ^-- SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.

3. Fix missing color argument in calls to wrap_color (when printing the
   hint about how to install apparmor).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Like this one:

	In ./script/check-config.sh line 215:
	if [ "$kernelMajor" -lt 5 ] || [ "$kernelMajor" -eq 5 -a "$kernelMinor" -le 1 ]; then
							      ^-- SC2166 (warning): Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
... and add this file to shellcheck target in Makefile.

These:

	In script/check-config.sh line 27:
	kernelMinor="${kernelVersion#$kernelMajor.}"
				     ^----------^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

	Did you mean:
	kernelMinor="${kernelVersion#"$kernelMajor".}"

	In script/check-config.sh line 103:
		source /etc/os-release 2>/dev/null || /bin/true
		       ^-------------^ SC1091 (info): Not following: /etc/os-release was not specified as input (see shellcheck -x).

	In script/check-config.sh line 267:
		NET_CLS_CGROUP $netprio
			       ^------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
One particularly bad one is ${codes[@]} which is fine in bash 4.4+,
but gives "codes[@]: unbound variable" with older bash versions,
such as with bash 4.2 used on CentOS 6. It's good that this is the only
array in the script that can potentially be empty.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This is done to make sure the script is working correctly in different
environments (distro and kernel versions). In addition, we can see in
test logs which kernel features are enabled.

Note that I didn't want to have a separate job for GHA CI, so I just
added this to the end of shellcheck one.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Now the only remaining file that needs shellcheck warnings to be fixed
is bash-completion. Note that in Makefile's TODO.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

Rebased; PTAL @AkihiroSuda

@kolyshkin
Copy link
Contributor Author

Do I still need to address anything in this PR? PTAL @thaJeztah @AkihiroSuda @opencontainers/runc-maintainers

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 727aa42 into opencontainers:main Apr 14, 2022
@kolyshkin kolyshkin deleted the ci-verify-more branch May 11, 2022 21:31
@kolyshkin kolyshkin mentioned this pull request Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants