mirror of https://github.com/knative/client.git
Fix shellcheck warnings in hack/build.sh script (#1860)
Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>
This commit is contained in:
parent
00f35299a1
commit
b59e60ba81
|
|
@ -14,6 +14,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
|
|
@ -37,19 +39,19 @@ run() {
|
||||||
export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
|
|
||||||
# Jump into project directory
|
# Jump into project directory
|
||||||
pushd $(basedir) >/dev/null 2>&1
|
pushd "$(basedir)" >/dev/null 2>&1
|
||||||
|
|
||||||
# Print help if requested
|
# Print help if requested
|
||||||
if $(has_flag --help -h); then
|
if has_flag --help -h; then
|
||||||
display_help
|
display_help "$@"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $(has_flag --watch -w); then
|
if has_flag --watch -w; then
|
||||||
# Build and test first
|
# Build and test first
|
||||||
go_build
|
go_build
|
||||||
|
|
||||||
if $(has_flag --test -t); then
|
if has_flag --test -t; then
|
||||||
go_test
|
go_test
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -58,29 +60,29 @@ run() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fast mode: Only compile and maybe run test
|
# Fast mode: Only compile and maybe run test
|
||||||
if $(has_flag --fast -f); then
|
if has_flag --fast -f; then
|
||||||
go_build
|
go_build
|
||||||
|
|
||||||
if $(has_flag --test -t); then
|
if has_flag --test -t; then
|
||||||
go_test
|
go_test
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run only tests
|
# Run only tests
|
||||||
if $(has_flag --test -t); then
|
if has_flag --test -t; then
|
||||||
go_test
|
go_test
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run only codegen
|
# Run only codegen
|
||||||
if $(has_flag --codegen -c); then
|
if has_flag --codegen -c; then
|
||||||
codegen
|
codegen
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cross compile only
|
# Cross compile only
|
||||||
if $(has_flag --all -x); then
|
if has_flag --all -x; then
|
||||||
cross_build || (echo "✋ Cross platform build failed" && exit 1)
|
cross_build || (echo "✋ Cross platform build failed" && exit 1)
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
@ -115,13 +117,13 @@ codegen() {
|
||||||
|
|
||||||
go_fmt() {
|
go_fmt() {
|
||||||
echo "🧹 ${S}Format"
|
echo "🧹 ${S}Format"
|
||||||
find $(echo "$source_dirs") -name "*.go" -print0 | xargs -0 gofmt -s -w
|
find "$(echo "$source_dirs")" -name "*.go" -print0 | xargs -0 gofmt -s -w
|
||||||
}
|
}
|
||||||
|
|
||||||
source_format() {
|
source_format() {
|
||||||
set +e
|
set +e
|
||||||
go_run "golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION}" -w $(echo "$source_dirs")
|
go_run "golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION}" -w "$(echo "$source_dirs")"
|
||||||
find $(echo "$source_dirs") -name "*.go" -print0 | xargs -0 gofmt -s -w
|
find "$(echo "$source_dirs")" -name "*.go" -print0 | xargs -0 gofmt -s -w
|
||||||
set -e
|
set -e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +138,7 @@ go_build() {
|
||||||
# Env var exported by hack/build-flags.sh
|
# Env var exported by hack/build-flags.sh
|
||||||
go build -mod=vendor -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
|
go build -mod=vendor -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
|
||||||
|
|
||||||
if $(file kn | grep -q -i "Windows"); then
|
if file kn | grep -q -i "Windows"; then
|
||||||
mv kn kn.exe
|
mv kn kn.exe
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +198,7 @@ check_license() {
|
||||||
|
|
||||||
update_deps() {
|
update_deps() {
|
||||||
echo "🚒 Update"
|
echo "🚒 Update"
|
||||||
$(basedir)/hack/update-deps.sh
|
"$(basedir)"/hack/update-deps.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_docs() {
|
generate_docs() {
|
||||||
|
|
@ -209,10 +211,10 @@ generate_docs() {
|
||||||
watch() {
|
watch() {
|
||||||
local command="./hack/build.sh --fast"
|
local command="./hack/build.sh --fast"
|
||||||
local fswatch_opts='-e "^\..*$" -o pkg cmd'
|
local fswatch_opts='-e "^\..*$" -o pkg cmd'
|
||||||
if $(has_flag --test -t); then
|
if has_flag --test -t; then
|
||||||
command="$command --test"
|
command="$command --test"
|
||||||
fi
|
fi
|
||||||
if $(has_flag --verbose); then
|
if has_flag --verbose; then
|
||||||
fswatch_opts="$fswatch_opts -v"
|
fswatch_opts="$fswatch_opts -v"
|
||||||
fi
|
fi
|
||||||
set +e
|
set +e
|
||||||
|
|
@ -228,7 +230,7 @@ watch() {
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "🔁 Watch"
|
echo "🔁 Watch"
|
||||||
fswatch $fswatch_opts | xargs -n1 -I{} sh -c "$command && echo 👌 OK"
|
fswatch "${fswatch_opts[@]}" | xargs -n1 -I{} sh -c "$command && echo 👌 OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dir where this script is located
|
# Dir where this script is located
|
||||||
|
|
@ -258,16 +260,15 @@ basedir() {
|
||||||
|
|
||||||
# Checks if a flag is present in the arguments.
|
# Checks if a flag is present in the arguments.
|
||||||
has_flag() {
|
has_flag() {
|
||||||
filters="$@"
|
filters=("$@")
|
||||||
for var in "${ARGS[@]}"; do
|
for var in "${ARGS[@]}"; do
|
||||||
for filter in $filters; do
|
for filter in "${filters[@]}"; do
|
||||||
if [ "$var" = "$filter" ]; then
|
if [ "$var" = "$filter" ]; then
|
||||||
echo 'true'
|
return 0
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
echo 'false'
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
cross_build() {
|
cross_build() {
|
||||||
|
|
@ -323,7 +324,7 @@ display_help() {
|
||||||
cat <<EOT
|
cat <<EOT
|
||||||
Knative client build script
|
Knative client build script
|
||||||
|
|
||||||
Usage: $(basename $BASH_SOURCE) [... options ...]
|
Usage: $(basename "${BASH_SOURCE[0]}") [... options ...]
|
||||||
|
|
||||||
with the following options:
|
with the following options:
|
||||||
|
|
||||||
|
|
@ -353,19 +354,19 @@ Examples:
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
if $(has_flag --debug); then
|
if has_flag --debug; then
|
||||||
export PS4='+($(basename ${BASH_SOURCE[0]}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
export PS4='+($(basename ${BASH_SOURCE[0]}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Shared funcs from hack repo
|
# Shared funcs from hack repo
|
||||||
source $(basedir)/vendor/knative.dev/hack/library.sh
|
source "$(basedir)"/vendor/knative.dev/hack/library.sh
|
||||||
|
|
||||||
# Shared funcs with CI
|
# Shared funcs with CI
|
||||||
while IFS= read -r -d '' file; do
|
while IFS= read -r -d '' file; do
|
||||||
source "${file}"
|
source "${file}"
|
||||||
done < <(find "$(basedir)/hack/build.sh.d" -name '*.sh' -print0)
|
done < <(find "$(basedir)/hack/build.sh.d" -name '*.sh' -print0)
|
||||||
source $(basedir)/hack/build-flags.sh
|
source "$(basedir)"/hack/build-flags.sh
|
||||||
|
|
||||||
# Fixe emoji labels for certain terminals
|
# Fixe emoji labels for certain terminals
|
||||||
apply_emoji_fixes
|
apply_emoji_fixes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue