Upgrade go version to 1.18 (#5045)

* Upgrade go version to 1.18

* fix go 1.18 compatibility

* update gofmt

* ignore golangci-lint staticcheck

* update gofmt
This commit is contained in:
hongming
2022-07-18 10:42:48 +08:00
committed by GitHub
parent e529703c49
commit 521cb40c21
872 changed files with 109434 additions and 111219 deletions

View File

@@ -13,8 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Update the Godeps/LICENSES document.
# Generates a table of Godep dependencies and their license.
# Update the LICENSES directory.
# Generates a table of Go dependencies and their licenses.
#
# Usage:
# $0 [--create-missing] [/path/to/licenses]
@@ -24,12 +24,15 @@
# additionally created files into the vendor auto-generated tree.
#
# Run every time a license file is added/modified within /vendor to
# update /Godeps/LICENSES
# update /LICENSES
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
export LANG=C
export LC_ALL=C
@@ -100,7 +103,6 @@ process_content () {
IFS=" " read -r -a local_files <<< "$(
for dir_root in ${package} ${package_root}; do
[[ -d ${DEPS_DIR}/${dir_root} ]] || continue
# One (set) of these is fine
find "${DEPS_DIR}/${dir_root}" \
-xdev -follow -maxdepth ${find_maxdepth} \
@@ -130,8 +132,6 @@ process_content () {
#############################################################################
# MAIN
#############################################################################
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
# use modules, and use module info rather than the vendor dir for computing dependencies
export GO111MODULE=on
@@ -155,70 +155,101 @@ fi
LICENSE_ROOT="${LICENSE_ROOT:-${KUBE_ROOT}}"
cd "${LICENSE_ROOT}"
VENDOR_LICENSE_FILE="Godeps/LICENSES"
TMP_LICENSE_FILE="/tmp/Godeps.LICENSES.$$"
kube::util::ensure-temp-dir
# Save the genreated LICENSE file for each package temporarily
TMP_LICENSE_FILE="${KUBE_TEMP}/LICENSES.$$"
# The directory to save all the LICENSE files
LICENSES_DIR="${LICENSES_DIR:-${LICENSE_ROOT}/LICENSES}"
mkdir -p "${LICENSES_DIR}"
# The tmp directory to save all the LICENSE files, will move to LICENSES_DIR
TMP_LICENSES_DIR="${KUBE_TEMP}/LICENSES.DIR.$$"
mkdir -p "${TMP_LICENSES_DIR}"
DEPS_DIR="vendor"
declare -Ag CONTENT
# Put the K8S LICENSE on top
(
echo "================================================================================"
echo "= Kubernetes licensed under: ="
echo
cat "${LICENSE_ROOT}/LICENSE"
echo
echo "= LICENSE $(kube::util::md5 "${LICENSE_ROOT}/LICENSE")"
echo "================================================================================"
) > ${TMP_LICENSE_FILE}
# Put the KubeSphere LICENSE on top
if [ -f "${LICENSE_ROOT}/LICENSE" ]; then
(
echo "================================================================================"
echo "= KubeSphere licensed under: ="
echo
cat "${LICENSE_ROOT}/LICENSE"
echo
echo "= LICENSE $(kube::util::md5 "${LICENSE_ROOT}/LICENSE")"
echo "================================================================================"
) > "${TMP_LICENSE_FILE}"
mv "${TMP_LICENSE_FILE}" "${TMP_LICENSES_DIR}/LICENSE"
fi
# Capture all module dependencies
modules=$(go list -m -json all | jq -r .Path | sort -f)
# Loop through every vendored package
for PACKAGE in $(go list -m -json all | jq -r .Path | sort -f); do
for PACKAGE in ${modules}; do
if [[ -e "staging/src/${PACKAGE}" ]]; then
echo "$PACKAGE is a staging package, skipping" > /dev/stderr
echo "${PACKAGE} is a staging package, skipping" >&2
continue
fi
if [[ ! -e "${DEPS_DIR}/${PACKAGE}" ]]; then
echo "$PACKAGE doesn't exist in vendor, skipping" > /dev/stderr
echo "${PACKAGE} doesn't exist in ${DEPS_DIR}, skipping" >&2
continue
fi
# if there are no files vendored under this package...
if [[ -z "$(find "${DEPS_DIR}/${PACKAGE}" -mindepth 1 -maxdepth 1 -type f)" ]]; then
# and we have the same number of submodules as subdirectories...
if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -gt 0 ]]; then
echo "Only submodules of ${PACKAGE} are vendored, skipping" >&2
continue
fi
fi
echo "${PACKAGE}"
process_content "${PACKAGE}" LICENSE
process_content "${PACKAGE}" COPYRIGHT
process_content "${PACKAGE}" COPYING
# display content
echo
echo "================================================================================"
echo "= ${DEPS_DIR}/${PACKAGE} licensed under: ="
echo
# copy content and throw error message
{
echo "= ${DEPS_DIR}/${PACKAGE} licensed under: ="
echo
file=""
if [[ -n "${CONTENT[${PACKAGE}-LICENSE]-}" ]]; then
file=""
if [[ -n "${CONTENT[${PACKAGE}-LICENSE]-}" ]]; then
file="${CONTENT[${PACKAGE}-LICENSE]-}"
elif [[ -n "${CONTENT[${PACKAGE}-COPYRIGHT]-}" ]]; then
elif [[ -n "${CONTENT[${PACKAGE}-COPYRIGHT]-}" ]]; then
file="${CONTENT[${PACKAGE}-COPYRIGHT]-}"
elif [[ -n "${CONTENT[${PACKAGE}-COPYING]-}" ]]; then
elif [[ -n "${CONTENT[${PACKAGE}-COPYING]-}" ]]; then
file="${CONTENT[${PACKAGE}-COPYING]-}"
fi
if [[ -z "${file}" ]]; then
cat > /dev/stderr << __EOF__
fi
if [[ -z "${file}" ]]; then
cat >&2 << __EOF__
No license could be found for ${PACKAGE} - aborting.
Options:
1. Check if the upstream repository has a newer version with LICENSE, COPYRIGHT and/or
COPYING files.
2. Contact the author of the package to ensure there is a LICENSE, COPYRIGHT and/or
COPYING file present.
3. Do not use this package in Kubernetes.
3. Do not use this package in KubeSphere.
__EOF__
exit 9
fi
cat "${file}"
fi
echo
echo "= ${file} $(kube::util::md5 "${file}")"
echo "================================================================================"
echo
done >> ${TMP_LICENSE_FILE}
cat "${file}"
echo
echo "= ${file} $(kube::util::md5 "${file}")"
} >> "${TMP_LICENSE_FILE}"
cat ${TMP_LICENSE_FILE} > ${VENDOR_LICENSE_FILE}
dest_dir="${TMP_LICENSES_DIR}/vendor/${PACKAGE}"
mkdir -p "${dest_dir}"
mv "${TMP_LICENSE_FILE}" "${dest_dir}/LICENSE"
done
# Leave things like OWNERS alone.
rm -f "${LICENSES_DIR}/LICENSE"
rm -rf "${LICENSES_DIR}/vendor"
mv "${TMP_LICENSES_DIR}"/* "${LICENSES_DIR}"

View File

@@ -6,6 +6,9 @@ set -o errexit
set -o nounset
set -o pipefail
# Go tools really don't like it if you have a symlink in `pwd`.
cd "$(pwd -P)"
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
@@ -29,6 +32,15 @@ TMP_DIR="${TMP_DIR:-$(mktemp -d /tmp/update-vendor.XXXX)}"
LOG_FILE="${LOG_FILE:-${TMP_DIR}/update-vendor.log}"
kube::log::status "logfile at ${LOG_FILE}"
function finish {
ret=$?
if [[ ${ret} != 0 ]]; then
echo "An error has occurred. Please see more details in ${LOG_FILE}"
fi
exit ${ret}
}
trap finish EXIT
if [ -z "${BASH_XTRACEFD:-}" ]; then
exec 19> "${LOG_FILE}"
export BASH_XTRACEFD="19"
@@ -51,29 +63,60 @@ function ensure_require_replace_directives_for_all_dependencies() {
# Capture local require/replace directives before running any go commands that can modify the go.mod file
local require_json="${local_tmp_dir}/require.json"
local replace_json="${local_tmp_dir}/replace.json"
go mod edit -json | jq -r ".Require // [] | sort | .[] | select(${require_filter})" > "${require_json}"
go mod edit -json | jq -r ".Replace // [] | sort | .[] | select(${replace_filter})" > "${replace_json}"
go mod edit -json \
| jq -r ".Require // [] | sort | .[] | select(${require_filter})" \
> "${require_json}"
go mod edit -json \
| jq -r ".Replace // [] | sort | .[] | select(${replace_filter})" \
> "${replace_json}"
# 1a. Ensure replace directives have an explicit require directive
jq -r '"-require \(.Old.Path)@\(.New.Version)"' < "${replace_json}" | xargs -L 100 go mod edit -fmt
jq -r '"-require \(.Old.Path)@\(.New.Version)"' < "${replace_json}" \
| xargs -L 100 go mod edit -fmt
# 1b. Ensure require directives have a corresponding replace directive pinning a version
jq -r '"-replace \(.Path)=\(.Path)@\(.Version)"' < "${require_json}" | xargs -L 100 go mod edit -fmt
jq -r '"-replace \(.Old.Path)=\(.New.Path)@\(.New.Version)"' < "${replace_json}" | xargs -L 100 go mod edit -fmt
jq -r '"-replace \(.Path)=\(.Path)@\(.Version)"' < "${require_json}" \
| xargs -L 100 go mod edit -fmt
jq -r '"-replace \(.Old.Path)=\(.New.Path)@\(.New.Version)"' < "${replace_json}" \
| xargs -L 100 go mod edit -fmt
# 2. Propagate root replace/require directives into staging modules, in case we are downgrading, so they don't bump the root required version back up
for repo in $(kube::util::list_staging_repos); do
pushd "staging/src/kubesphere.io/${repo}" >/dev/null 2>&1
jq -r '"-require \(.Path)@\(.Version)"' < "${require_json}" \
| xargs -L 100 go mod edit -fmt
jq -r '"-replace \(.Path)=\(.Path)@\(.Version)"' < "${require_json}" \
| xargs -L 100 go mod edit -fmt
jq -r '"-replace \(.Old.Path)=\(.New.Path)@\(.New.Version)"' < "${replace_json}" \
| xargs -L 100 go mod edit -fmt
popd >/dev/null 2>&1
done
# 3. Add explicit require directives for indirect dependencies
go list -m -json all | jq -r 'select(.Main != true) | select(.Indirect == true) | "-require \(.Path)@\(.Version)"' | xargs -L 100 go mod edit -fmt
go list -m -json all \
| jq -r 'select(.Main != true) | select(.Indirect == true) | "-require \(.Path)@\(.Version)"' \
| xargs -L 100 go mod edit -fmt
# 4. Add explicit replace directives pinning dependencies that aren't pinned yet
go list -m -json all | jq -r 'select(.Main != true) | select(.Replace == null) | "-replace \(.Path)=\(.Path)@\(.Version)"' | xargs -L 100 go mod edit -fmt
go list -m -json all \
| jq -r 'select(.Main != true) | select(.Replace == null) | "-replace \(.Path)=\(.Path)@\(.Version)"' \
| xargs -L 100 go mod edit -fmt
}
function group_replace_directives() {
function group_directives() {
local local_tmp_dir
local_tmp_dir=$(mktemp -d "${TMP_DIR}/group_replace.XXXX")
local go_mod_require_direct="${local_tmp_dir}/go.mod.require_direct.tmp"
local go_mod_require_indirect="${local_tmp_dir}/go.mod.require_indirect.tmp"
local go_mod_replace="${local_tmp_dir}/go.mod.replace.tmp"
local go_mod_noreplace="${local_tmp_dir}/go.mod.noreplace.tmp"
local go_mod_other="${local_tmp_dir}/go.mod.other.tmp"
# separate replace and non-replace directives
awk "
# print lines between 'require (' ... ')' lines
/^require [(]/ { inrequire=1; next }
inrequire && /^[)]/ { inrequire=0; next }
inrequire && /\/\/ indirect/ { print > \"${go_mod_require_indirect}\"; next }
inrequire { print > \"${go_mod_require_direct}\"; next }
# print lines between 'replace (' ... ')' lines
/^replace [(]/ { inreplace=1; next }
inreplace && /^[)]/ { inreplace=0; next }
@@ -82,11 +125,21 @@ function group_replace_directives() {
# print ungrouped replace directives with the replace directive trimmed
/^replace [^(]/ { sub(/^replace /,\"\"); print > \"${go_mod_replace}\"; next }
# otherwise print to the noreplace file
{ print > \"${go_mod_noreplace}\" }
# print ungrouped require directives with the require directive trimmed
/^require [^(].*\/\/ indirect/ { sub(/^require /,\"\"); print > \"${go_mod_require_indirect}\"; next }
/^require [^(]/ { sub(/^require /,\"\"); print > \"${go_mod_require_direct}\"; next }
# otherwise print to the other file
{ print > \"${go_mod_other}\" }
" < go.mod
{
cat "${go_mod_noreplace}";
cat "${go_mod_other}";
echo "require (";
cat "${go_mod_require_direct}";
echo ")";
echo "require (";
cat "${go_mod_require_indirect}";
echo ")";
echo "replace (";
cat "${go_mod_replace}";
echo ")";
@@ -122,6 +175,7 @@ function add_generated_comments() {
# Phase 1: ensure go.mod files for staging modules and main module
for repo in $(kube::util::list_staging_repos); do
pushd "staging/src/kubesphere.io/${repo}" >/dev/null 2>&1
if [[ ! -f go.mod ]]; then
@@ -139,15 +193,25 @@ if [[ ! -f go.mod ]]; then
rm -f Godeps/Godeps.json # remove after initializing
fi
# Phase 2: ensure staging repo require/replace directives
kube::log::status "go.mod: update references"
kube::log::status "go.mod: update staging references"
# Prune
go mod edit -json | jq -r '.Require[]? | select(.Version == "v0.0.0") | "-droprequire \(.Path)"' | xargs -L 100 go mod edit -fmt
go mod edit -json | jq -r '.Replace[]? | select(.New.Path | startswith("./staging/")) | "-dropreplace \(.Old.Path)"' | xargs -L 100 go mod edit -fmt
go mod edit -json \
| jq -r '.Require[]? | select(.Version == "v0.0.0") | "-droprequire \(.Path)"' \
| xargs -L 100 go mod edit -fmt
go mod edit -json \
| jq -r '.Replace[]? | select(.New.Path | startswith("./staging/")) | "-dropreplace \(.Old.Path)"' \
| xargs -L 100 go mod edit -fmt
# Readd
kube::util::list_staging_repos | xargs -n 1 -I {} echo "-require kubesphere.io/{}@v0.0.0" | xargs -L 100 go mod edit -fmt
kube::util::list_staging_repos | xargs -n 1 -I {} echo "-replace kubesphere.io/{}=./staging/src/kubesphere.io/{}" | xargs -L 100 go mod edit -fmt
kube::util::list_staging_repos \
| while read -r X; do echo "-require kubesphere.io/${X}@v0.0.0"; done \
| xargs -L 100 go mod edit -fmt
kube::util::list_staging_repos \
| while read -r X; do echo "-replace kubesphere.io/${X}=./staging/src/kubesphere.io/${X}"; done \
| xargs -L 100 go mod edit -fmt
# Phase 3: capture required (minimum) versions from all modules, and replaced (pinned) versions from the root module
@@ -157,41 +221,160 @@ ensure_require_replace_directives_for_all_dependencies
go mod tidy >>"${LOG_FILE}" 2>&1
# pin expanded versions
ensure_require_replace_directives_for_all_dependencies
# group replace directives
group_replace_directives
# group require/replace directives
group_directives
# Phase 4: copy root go.mod to staging dirs and rewrite
kube::log::status "go.mod: propagate to staging modules"
for repo in $(kube::util::list_staging_repos); do
pushd "staging/src/kubesphere.io/${repo}" >/dev/null 2>&1
echo "=== propagating to ${repo}" >> "${LOG_FILE}"
# copy root go.mod, changing module name
sed "s#module kubesphere.io/kubesphere#module kubesphere.io/${repo}#" \
< "${KUBE_ROOT}/go.mod" \
> "${KUBE_ROOT}/staging/src/kubesphere.io/${repo}/go.mod"
# remove `require` directives for staging components (will get re-added as needed by `go list`)
kube::util::list_staging_repos \
| while read -r X; do echo "-droprequire kubesphere.io/${X}"; done \
| xargs -L 100 go mod edit
# rewrite `replace` directives for staging components to point to peer directories
kube::util::list_staging_repos \
| while read -r X; do echo "-replace kubesphere.io/${X}=../${X}"; done \
| xargs -L 100 go mod edit
popd >/dev/null 2>&1
done
# Phase 5: sort and tidy staging components
kube::log::status "go.mod: sorting staging modules"
# tidy staging repos in reverse dependency order.
# the content of dependencies' go.mod files affects what `go mod tidy` chooses to record in a go.mod file.
tidy_unordered="${TMP_DIR}/tidy_unordered.txt"
kube::util::list_staging_repos \
| xargs -I {} echo "kubesphere.io/{}" > "${tidy_unordered}"
rm -f "${TMP_DIR}/tidy_deps.txt"
# SC2094 checks that you do not read and write to the same file in a pipeline.
# We do read from ${tidy_unordered} in the pipeline and mention it within the
# pipeline (but only ready it again) so we disable the lint to assure shellcheck
# that :this-is-fine:
# shellcheck disable=SC2094
while IFS= read -r repo; do
# record existence of the repo to ensure modules with no peer relationships still get included in the order
echo "${repo} ${repo}" >> "${TMP_DIR}/tidy_deps.txt"
pushd "${KUBE_ROOT}/staging/src/${repo}" >/dev/null 2>&1
# save the original go.mod, since go list doesn't just add missing entries, it also removes specific required versions from it
tmp_go_mod="${TMP_DIR}/tidy_${repo/\//_}_go.mod.original"
tmp_go_deps="${TMP_DIR}/tidy_${repo/\//_}_deps.txt"
cp go.mod "${tmp_go_mod}"
{
echo "=== sorting ${repo}"
# 'go list' calculates direct imports and updates go.mod so that go list -m lists our module dependencies
echo "=== computing imports for ${repo}"
go list all
echo "=== computing tools imports for ${repo}"
go list -tags=tools all
} >> "${LOG_FILE}" 2>&1
# capture module dependencies
go list -m -f '{{if not .Main}}{{.Path}}{{end}}' all > "${tmp_go_deps}"
# restore the original go.mod file
cp "${tmp_go_mod}" go.mod
# list all module dependencies
for dep in $(join "${tidy_unordered}" "${tmp_go_deps}"); do
# record the relationship (put dep first, because we want to sort leaves first)
echo "${dep} ${repo}" >> "${TMP_DIR}/tidy_deps.txt"
# switch the required version to an explicit v0.0.0 (rather than an unknown v0.0.0-00010101000000-000000000000)
go mod edit -require "${dep}@v0.0.0"
done
popd >/dev/null 2>&1
done < "${tidy_unordered}"
kube::log::status "go.mod: tidying"
for repo in $(tsort "${TMP_DIR}/tidy_deps.txt"); do
pushd "${KUBE_ROOT}/staging/src/${repo}" >/dev/null 2>&1
echo "=== tidying ${repo}" >> "${LOG_FILE}"
# prune replace directives that pin to the naturally selected version.
# do this before tidying, since tidy removes unused modules that
# don't provide any relevant packages, which forgets which version of the
# unused transitive dependency we had a require directive for,
# and prevents pruning the matching replace directive after tidying.
go list -m -json all |
jq -r 'select(.Replace != null) |
select(.Path == .Replace.Path) |
select(.Version == .Replace.Version) |
"-dropreplace \(.Replace.Path)"' |
xargs -L 100 go mod edit -fmt
go mod tidy -v >>"${LOG_FILE}" 2>&1
# disallow transitive dependencies on kubesphere.io/kubesphere
loopback_deps=()
kube::util::read-array loopback_deps < <(go list all 2>/dev/null | grep kubesphere.io/kubernetes/ || true)
if [[ -n ${loopback_deps[*]:+"${loopback_deps[*]}"} ]]; then
kube::log::error "Disallowed ${repo} -> kubesphere.io/kubesphere dependencies exist via the following imports:
$(go mod why "${loopback_deps[@]}")"
exit 1
fi
# prune unused pinned replace directives
comm -23 \
<(go mod edit -json | jq -r '.Replace[] | .Old.Path' | sort) \
<(go list -m -json all | jq -r .Path | sort) |
while read -r X; do echo "-dropreplace=${X}"; done |
xargs -L 100 go mod edit -fmt
# prune replace directives that pin to the naturally selected version
go list -m -json all |
jq -r 'select(.Replace != null) |
select(.Path == .Replace.Path) |
select(.Version == .Replace.Version) |
"-dropreplace \(.Replace.Path)"' |
xargs -L 100 go mod edit -fmt
# group require/replace directives
group_directives
popd >/dev/null 2>&1
done
echo "=== tidying root" >> "${LOG_FILE}"
go mod tidy >>"${LOG_FILE}" 2>&1
# disallow transitive dependencies on kubesphere.io/kubesphere
loopback_deps=()
kube::util::read-array loopback_deps < <(go mod graph | grep ' kubesphere.io/kubesphere' || true)
if [[ -n ${loopback_deps[*]:+"${loopback_deps[*]}"} ]]; then
kube::log::error "Disallowed transitive kubesphere.io/kubesphere dependencies exist via the following imports:"
kube::log::error "${loopback_deps[@]}"
exit 1
fi
# Phase 6: add generated comments to go.mod files
kube::log::status "go.mod: adding generated comments"
add_generated_comments "
// This is a generated file. Do not edit directly.
// Ensure you've carefully read
// https://git.k8s.io/community/contributors/devel/sig-architecture/vendor.md
// Run hack/pin-dependency.sh to change pinned dependency versions.
// Run hack/update-vendor.sh to update go.mod files and the vendor directory.
"
for repo in $(kube::util::list_staging_repos); do
pushd "staging/src/kubesphere.io/${repo}" >/dev/null 2>&1
add_generated_comments "// This is a generated file. Do not edit directly."
popd >/dev/null 2>&1
done
# Phase 7: rebuild vendor directory
kube::log::status "vendor: running 'go mod vendor'"
go mod vendor >>"${LOG_FILE}" 2>&1
# sort recorded packages for a given vendored dependency in modules.txt.
# `go mod vendor` outputs in imported order, which means slight go changes (or different platforms) can result in a differently ordered modules.txt.
# scan | prefix comment lines with the module name | sort field 1 | strip leading text on comment lines
# 1. prefix '#' lines with the module name and capture the module name
# 2. prefix '##' with the most recently captured module name
# 3. output other lines as-is
# sort lines
# strip anything before '#'
awk '{
if($1=="#") { current_module=$2; print $2 " " $0; }
else if($1=="##") { print current_module " " $0; }
else { print }
}' < vendor/modules.txt | sort -k1,1 -s | sed 's/[^#]*#/#/' > "${TMP_DIR}/modules.txt.tmp"
# create a symlink in vendor directory pointing to the staging components.
# This lets other packages and tools use the local staging components as if they were vendored.
for repo in $(kube::util::list_staging_repos); do
@@ -199,5 +382,14 @@ for repo in $(kube::util::list_staging_repos); do
ln -s "../../staging/src/kubesphere.io/${repo}" "${KUBE_ROOT}/vendor/kubesphere.io/${repo}"
done
#kube::log::status "vendor: updating LICENSES file"
#hack/update-vendor-licenses.sh >>"${LOG_FILE}" 2>&1
kube::log::status "vendor: updating vendor/LICENSES"
hack/update-vendor-licenses.sh >>"${LOG_FILE}" 2>&1
kube::log::status "vendor: creating OWNERS file"
rm -f "vendor/OWNERS"
cat <<__EOF__ > "vendor/OWNERS"
# See the OWNERS docs at https://github.com/kubesphere/kubesphere/blob/master/OWNERS
__EOF__
kube::log::status "NOTE: don't forget to handle vendor/* files that were added or removed"

View File

@@ -69,7 +69,7 @@ done < <(find . -name "*.sh" \
-path ./_\* -o \
-path ./.git\* -o \
-path ./vendor\* -o \
-path ./hack/install_kubebuilder.sh -o \
-path ./LICENSES\* -o \
\( -path ./third_party\* -a -not -path ./third_party/forked\* \) \
\))
@@ -103,16 +103,18 @@ SHELLCHECK_OPTIONS=(
)
# tell the user which we've selected and lint all scripts
# The shellcheck errors are printed to stdout by default, hence they need to be redirected
# to stderr in order to be well parsed for Junit representation by juLog function
res=0
if ${HAVE_SHELLCHECK}; then
echo "Using host shellcheck ${SHELLCHECK_VERSION} binary."
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" || res=$?
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
else
echo "Using shellcheck ${SHELLCHECK_VERSION} docker image."
"${DOCKER}" run \
--rm -v "${KUBE_ROOT}:${KUBE_ROOT}" -w "${KUBE_ROOT}" \
"${SHELLCHECK_IMAGE}" \
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" || res=$?
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
fi
# print a message based on the result
@@ -133,4 +135,4 @@ else
fi
# preserve the result
exit $res
exit $res