Skip to content

Commit

Permalink
Add verification scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Chen <[email protected]>

Add verify and update to Makefile

Signed-off-by: Yuan Chen <[email protected]>

Remove venv

Revert changes

Signed-off-by: Yuan Chen <[email protected]>

Add yamlfmt

Signed-off-by: Yuan Chen <[email protected]>

Remove golangci.yaml

Fix goling config file names
  • Loading branch information
yuanchen8911 committed May 10, 2024
1 parent f72e040 commit 9dff93a
Show file tree
Hide file tree
Showing 22 changed files with 817 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .yamlfmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
formatter:
type: basic
indentless_arrays: true
retain_line_breaks_single: true
14 changes: 14 additions & 0 deletions .yamllint.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# configuration file rules
# https://yamllint.readthedocs.io/en/stable/rules.html

extends: default

ignore-from-file: .gitignore

rules:
indentation: disable
document-start: disable
comments: disable
line-length: disable
truthy:
check-keys: false
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ IMAGE_REPO ?=docker.io/nvidia/knavigator
GIT_REF =$(shell git rev-parse --abbrev-ref HEAD)
IMAGE_TAG ?=$(GIT_REF)

## verify: Verify code
.PHONY: verify
verify:
@./hack/verify-all.sh

## update: Update all the generated
.PHONY: update
update:
@./hack/update-all.sh

.PHONY: build
build:
@for target in $(TARGETS); do \
Expand Down
1 change: 1 addition & 0 deletions hack/spelling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
importas
64 changes: 64 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

failed=()

if [[ "${UPDATE_GO_FORMAT:-true}" == "true" ]]; then
echo "[*] Update go format..."
"${ROOT_DIR}"/hack/update-go-format.sh || failed+=(go-format)
fi

if [[ "${UPDATE_GO_MOD:-true}" == "true" ]]; then
echo "[*] Update go mod..."
"${ROOT_DIR}"/hack/update-go-mod.sh || failed+=(go-mod)
fi

if [[ "${UPDATE_GO_LINT:-true}" == "true" ]]; then
echo "[*] Update go lint..."
"${ROOT_DIR}"/hack/update-go-lint.sh || failed+=(go-lint)
fi

if [[ "${UPDATE_ENDS_NEWLINE:-true}" == "true" ]]; then
echo "[*] Update ends newline..."
"${ROOT_DIR}"/hack/update-ends-newline.sh || failed+=(ends-newline)
fi

if [[ "${UPDATE_SHELL_FORMAT:-true}" == "true" ]]; then
echo "[*] Update shell format..."
"${ROOT_DIR}"/hack/update-shell-format.sh || failed+=(shell-format)
fi

if [[ "${UPDATE_YAML_FORMAT:-true}" == "true" ]]; then
echo "[*] Update yaml format..."
"${ROOT_DIR}"/hack/update-yaml-format.sh || failed+=(yaml-format)
fi

if [[ "${UPDATE_SPELLING:-true}" == "true" ]]; then
echo "[*] Update spelling..."
"${ROOT_DIR}"/hack/update-spelling.sh || failed+=(spelling)
fi

if [[ "${#failed[@]}" != 0 ]]; then
echo "Update failed for: ${failed[*]}"
exit 1
fi
42 changes: 42 additions & 0 deletions hack/update-ends-newline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function update_ends_newline() {
find . \( \
-iname "*.md" \
-o -iname "*.sh" \
-o -iname "*.go" \
-o -iname "*.tpl" \
-o -iname "*.yaml" \
-o -iname "*.yml" \
\) \
-not \( \
-path ./.git/\* \
-o -path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\) \
-exec sh -c '[ -n "$(tail -c 1 $1)" ] && echo >> $1' sh {} \;
}

cd "${ROOT_DIR}" && update_ends_newline
37 changes: 37 additions & 0 deletions hack/update-go-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function format() {
echo "Update go format"
mapfile -t findfiles < <(find . \( \
-iname "*.go" \
\) \
-not \( \
-path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\))
gofmt -s -w "${findfiles[@]}"
}

cd "${ROOT_DIR}" && format
26 changes: 26 additions & 0 deletions hack/update-go-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

COMMAND=(go run github.com/golangci/golangci-lint/cmd/[email protected])

cd "${ROOT_DIR}" && "${COMMAND[@]}" run -c "${ROOT_DIR}/.golangci.yml" --fix
24 changes: 24 additions & 0 deletions hack/update-go-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

cd "${ROOT_DIR}" && go mod tidy
37 changes: 37 additions & 0 deletions hack/update-shell-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function format() {
echo "Update shell format"
mapfile -t findfiles < <(find . \( \
-iname "*.sh" \
\) \
-not \( \
-path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\))
go run mvdan.cc/sh/v3/cmd/[email protected] -w -i=2 "${findfiles[@]}"
}

cd "${ROOT_DIR}" && format
47 changes: 47 additions & 0 deletions hack/update-spelling.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Copyright 2023 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

allowed_spelling_words="${ROOT_DIR}/hack/spelling.txt"

function update() {
local ignore
ignore="$(tr <"${allowed_spelling_words}" '\n' ',')"
mapfile -t files < <(find . \( \
-iname "*.md" \
-o -iname "*.sh" \
-o -iname "*.go" \
-o -iname "*.tpl" \
-o -iname "*.yaml" \
-o -iname "*.yml" \
\) \
-not \( \
-path ./.git/\* \
-o -path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
\))
go run github.com/client9/misspell/cmd/[email protected] \
-locale US -w -i "${ignore}" "${files[@]}"
}

cd "${ROOT_DIR}" && update
40 changes: 40 additions & 0 deletions hack/update-yaml-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Copyright 2024 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

DIR="$(dirname "${BASH_SOURCE[0]}")"

ROOT_DIR="$(realpath "${DIR}/..")"

function format() {
echo "Update yaml format"
mapfile -t findfiles < <(find . \( \
-iname "*.yaml" \
-o -iname "*.yml" \
\) \
-not \( \
-path ./vendor/\* \
-o -path ./demo/node_modules/\* \
-o -path ./site/themes/\* \
-o -path ./kustomize/crd/bases/\* \
-o -path ./kustomize/rbac/\* \
\))
go run github.com/google/yamlfmt/cmd/[email protected] -conf .yamlfmt.yaml "${findfiles[@]}"
}

cd "${ROOT_DIR}" && format
Loading

0 comments on commit 9dff93a

Please sign in to comment.