Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
86a7a08a
Commit
86a7a08a
authored
Jan 12, 2019
by
Benjamin Elder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use host shellcheck binary when possible
parent
d1e53119
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
28 deletions
+56
-28
verify-shellcheck.sh
hack/verify-shellcheck.sh
+56
-28
No files found.
hack/verify-shellcheck.sh
View file @
86a7a08a
...
@@ -21,13 +21,19 @@ set -o pipefail
...
@@ -21,13 +21,19 @@ set -o pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
/..
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
# required version for this script, if not installed on the host we will
# use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE
SHELLCHECK_VERSION
=
"0.6.0"
# upstream shellcheck latest stable image as of January 10th, 2019
# upstream shellcheck latest stable image as of January 10th, 2019
SHELLCHECK_IMAGE
=
"koalaman/shellcheck-alpine:v0.6.0@sha256:7d4d712a2686da99d37580b4e2f45eb658b74e4b01caf67c1099adc294b96b52"
SHELLCHECK_IMAGE
=
"koalaman/shellcheck-alpine:v0.6.0@sha256:7d4d712a2686da99d37580b4e2f45eb658b74e4b01caf67c1099adc294b96b52"
# fixed name for the shellcheck docker container so we can reliably clean it up
SHELLCHECK_CONTAINER
=
"k8s-shellcheck"
SHELLCHECK_CONTAINER
=
"k8s-shellcheck"
# disabled lints
# disabled lints
disabled
=(
disabled
=(
# this lint dissalows non-constant source, which we use extensively
# this lint disallows non-constant source, which we use extensively without
# any known bugs
1090
1090
# this lint prefers command -v to which, they are not the same
# this lint prefers command -v to which, they are not the same
2230
2230
...
@@ -41,6 +47,22 @@ join_by() {
...
@@ -41,6 +47,22 @@ join_by() {
SHELLCHECK_DISABLED
=
"
$(
join_by ,
"
${
disabled
[@]
}
"
)
"
SHELLCHECK_DISABLED
=
"
$(
join_by ,
"
${
disabled
[@]
}
"
)
"
readonly
SHELLCHECK_DISABLED
readonly
SHELLCHECK_DISABLED
# creates the shellcheck container for later use
create_container
()
{
# TODO(bentheelder): this is a performance hack, we create the container with
# a sleep MAX_INT32 so that it is effectively paused.
# We then repeatedly exec to it to run each shellcheck, and later rm it when
# we're done.
# This is incredibly much faster than creating a container for each shellcheck
# call ...
docker run
--name
"
${
SHELLCHECK_CONTAINER
}
"
-d
--rm
-v
"
${
KUBE_ROOT
}
:
${
KUBE_ROOT
}
"
-w
"
${
KUBE_ROOT
}
"
--entrypoint
=
"sleep"
"
${
SHELLCHECK_IMAGE
}
"
2147483647
}
# removes the shellcheck container
remove_container
()
{
docker
rm
-f
"
${
SHELLCHECK_CONTAINER
}
"
&> /dev/null
||
true
}
# ensure we're linting the k8s source tree
cd
"
${
KUBE_ROOT
}
"
cd
"
${
KUBE_ROOT
}
"
# find all shell scripts excluding ./_*, ./.git/*, ./vendor*,
# find all shell scripts excluding ./_*, ./.git/*, ./vendor*,
...
@@ -88,32 +110,33 @@ array_contains () {
...
@@ -88,32 +110,33 @@ array_contains () {
return
$in
return
$in
}
}
# creates the shellcheck container for later user
# detect if the host machine has the required shellcheck version installed
create_container
()
{
# if so, we will use that instead.
# TODO(bentheelder): this is a performance hack, we create the container with
HAVE_SHELLCHECK
=
false
# a sleep MAX_INT32 so that it is effectively paused.
if
which shellcheck &>/dev/null
;
then
# We then repeatedly exec to it to run each shellcheck, and later rm it when
detected_version
=
"
$(
shellcheck
--version
|
grep
'version: .*'
)
"
# we're done.
if
[[
"
${
detected_version
}
"
=
"version:
${
SHELLCHECK_VERSION
}
"
]]
;
then
# This is incredibly much faster than creating a container for each shellcheck
HAVE_SHELLCHECK
=
true
# call ...
fi
docker run
--name
"
${
SHELLCHECK_CONTAINER
}
"
-d
--rm
-v
"
${
KUBE_ROOT
}
:
${
KUBE_ROOT
}
"
-w
"
${
KUBE_ROOT
}
"
--entrypoint
=
"sleep"
"
${
SHELLCHECK_IMAGE
}
"
2147483647
fi
}
# removes the shellcheck container
remove_container
()
{
docker
rm
-f
"
${
SHELLCHECK_CONTAINER
}
"
&> /dev/null
||
true
}
# remove any previous container, ensure we will attempt to cleanup on exit,
# tell the user which we've selected and possibly set up the container
# and create the container
if
${
HAVE_SHELLCHECK
}
;
then
remove_container
echo
"Using host shellcheck
${
SHELLCHECK_VERSION
}
binary."
trap
remove_container EXIT
else
if
!
output
=
"
$(
create_container 2>&1
)
"
;
then
echo
"Using shellcheck
${
SHELLCHECK_VERSION
}
docker image."
{
# remove any previous container, ensure we will attempt to cleanup on exit,
echo
"Failed to create shellcheck container with output: "
# and create the container
echo
""
remove_container
echo
"
${
output
}
"
kube::util::trap_add
'remove_container'
EXIT
}
>
&2
if
!
output
=
"
$(
create_container 2>&1
)
"
;
then
exit
1
{
echo
"Failed to create shellcheck container with output: "
echo
""
echo
"
${
output
}
"
}
>
&2
exit
1
fi
fi
fi
# lint each script, tracking failures
# lint each script, tracking failures
...
@@ -121,7 +144,12 @@ errors=()
...
@@ -121,7 +144,12 @@ errors=()
not_failing
=()
not_failing
=()
for
f
in
"
${
all_shell_scripts
[@]
}
"
;
do
for
f
in
"
${
all_shell_scripts
[@]
}
"
;
do
set
+o errexit
set
+o errexit
failedLint
=
$(
docker
exec
-t
"
${
SHELLCHECK_CONTAINER
}
"
shellcheck
--exclude
=
"
${
SHELLCHECK_DISABLED
}
"
"
${
f
}
"
)
if
${
HAVE_SHELLCHECK
}
;
then
failedLint
=
$(
shellcheck
--exclude
=
"
${
SHELLCHECK_DISABLED
}
"
"
${
f
}
"
)
else
failedLint
=
$(
docker
exec
-t
${
SHELLCHECK_CONTAINER
}
\
shellcheck
--exclude
=
"
${
SHELLCHECK_DISABLED
}
"
"
${
f
}
"
)
fi
set
-o
errexit
set
-o
errexit
array_contains
"
${
f
}
"
"
${
failing_files
[@]
}
"
&&
in_failing
=
$?
||
in_failing
=
$?
array_contains
"
${
f
}
"
"
${
failing_files
[@]
}
"
&&
in_failing
=
$?
||
in_failing
=
$?
if
[[
-n
"
${
failedLint
}
"
]]
&&
[[
"
${
in_failing
}
"
-ne
"0"
]]
;
then
if
[[
-n
"
${
failedLint
}
"
]]
&&
[[
"
${
in_failing
}
"
-ne
"0"
]]
;
then
...
@@ -134,7 +162,7 @@ done
...
@@ -134,7 +162,7 @@ done
# Check to be sure all the packages that should pass lint are.
# Check to be sure all the packages that should pass lint are.
if
[
${#
errors
[@]
}
-eq
0
]
;
then
if
[
${#
errors
[@]
}
-eq
0
]
;
then
echo
'Congratulations!
All shell files have been linted
.'
echo
'Congratulations!
All shell files are passing lint (excluding those in hack/.shellcheck_failures)
.'
else
else
{
{
echo
"Errors from shellcheck:"
echo
"Errors from shellcheck:"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment