Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
hack: include more update and verify scripts
Browse files Browse the repository at this point in the history
update:
- deps: calls go mod tidy

verify:
- build: calls build for ./cmd
- deps: verifies if the current go.* files are valid
- gotest: calls go tests on _test files if present
- govet: calls go vet
- shellcheck: executes shellcheck on all .sh files
  • Loading branch information
neolit123 committed Jun 25, 2019
1 parent 64c3eaf commit 7feae07
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
REPO_PATH=$(get_root_path)

"${REPO_PATH}"/hack/update-deps.sh
"${REPO_PATH}"/hack/update-gofmt.sh
27 changes: 27 additions & 0 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -o nounset
set -o errexit
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

export GO111MODULE="on"
go mod tidy
88 changes: 88 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"

# set REPO_PATH
REPO_PATH=$(get_root_path)
cd "${REPO_PATH}"

# exit code, if a script fails we'll set this to 1
res=0

# run all verify scripts, optionally skipping any of them

if [[ "${VERIFY_WHITESPACE:-true}" == "true" ]]; then
echo "[*] Verifying whitespace..."
hack/verify-whitespace.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_SPELLING:-true}" == "true" ]]; then
echo "[*] Verifying spelling..."
hack/verify-spelling.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOFMT:-true}" == "true" ]]; then
echo "[*] Verifying gofmt..."
hack/verify-gofmt.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOLINT:-true}" == "true" ]]; then
echo "[*] Verifying golint..."
hack/verify-golint.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOVET:-true}" == "true" ]]; then
echo "[*] Verifying govet..."
hack/verify-govet.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_DEPS:-true}" == "true" ]]; then
echo "[*] Verifying deps..."
hack/verify-deps.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOTEST:-true}" == "true" ]]; then
echo "[*] Verifying gotest..."
hack/verify-gotest.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_BUILD:-true}" == "true" ]]; then
echo "[*] Verifying build..."
hack/verify-build.sh || res=1
cd "${REPO_PATH}"
fi

# exit based on verify scripts
if [[ "${res}" = 0 ]]; then
echo ""
echo "All verify checks passed, congrats!"
else
echo ""
echo "One or more verify checks failed! See output above..."
fi
exit "${res}"
26 changes: 26 additions & 0 deletions hack/verify-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"

# check if the code builds
cd_root_path
export GO111MODULE=on
go build ./cmd/...
50 changes: 50 additions & 0 deletions hack/verify-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

# cleanup on exit
cleanup() {
echo "Cleaning up..."
mv go.mod.old go.mod
mv go.sum.old go.sum
}
trap cleanup EXIT

echo "Verifying..."
# temporary copy the go mod and sum files
cp go.mod go.mod.old || exit
cp go.sum go.sum.old || exit

# run update-deps.sh
export GO111MODULE="on"
./hack/update-deps.sh

# compare the old and new files
DIFF0=$(diff -u go.mod go.mod.old)
DIFF1=$(diff -u go.sum go.sum.old)

if [[ -n "${DIFF0}" ]] || [[ -n "${DIFF1}" ]]; then
echo "${DIFF0}"
echo "${DIFF1}"
echo "Check failed. Please run ./hack/update-deps.sh"
exit 1
fi
31 changes: 31 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

# check for gofmt diffs
diff=$(git ls-files | grep "\.go" | grep -v "\/vendor" | xargs gofmt -s -d 2>&1)
if [[ -n "${diff}" ]]; then
echo "${diff}"
echo
echo "Check failed. Please run hack/update-gofmt.sh"
fi
27 changes: 27 additions & 0 deletions hack/verify-gotest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

# run go test
export GO111MODULE=on
go test ./...
28 changes: 28 additions & 0 deletions hack/verify-govet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# CI script to run go vet over our code
set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

# run go vet
export GO111MODULE=on
go vet ./...
54 changes: 54 additions & 0 deletions hack/verify-shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
ROOT_PATH=$(get_root_path)

# create a temporary directory
TMP_DIR=$(mktemp -d)

# cleanup on exit
cleanup() {
echo "Cleaning up..."
rm -rf "${TMP_DIR}"
}
trap cleanup EXIT

# install shellcheck (Linux-x64 only!)
cd "${TMP_DIR}" || exit
VERSION="shellcheck-v0.6.0"
DOWNLOAD_FILE="${VERSION}.linux.x86_64.tar.xz"
wget https://storage.googleapis.com/shellcheck/"${DOWNLOAD_FILE}"
tar xf "${DOWNLOAD_FILE}"
cd "${VERSION}" || exit

echo "Running shellcheck..."
cd "${ROOT_PATH}" || exit
OUT="${TMP_DIR}/out.log"
FILES=$(find . -name "*.sh")
while read -r file; do
"${TMP_DIR}/${VERSION}/shellcheck" "$file" >> "${OUT}" 2>&1
done <<< "$FILES"

if [[ -s "${OUT}" ]]; then
echo "Found errors:"
cat "${OUT}"
exit 1
fi

0 comments on commit 7feae07

Please sign in to comment.