From c205b4d74f749b4326e4020438a1c43c027d1be0 Mon Sep 17 00:00:00 2001 From: Ashley Davis Date: Tue, 10 May 2022 18:24:14 +0100 Subject: [PATCH 1/2] make verify-chart-version respect CTR in makefile this allows podman to be used instead of docker Signed-off-by: Ashley Davis --- hack/verify-chart-version.sh | 11 ++++++----- make/ci.mk | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hack/verify-chart-version.sh b/hack/verify-chart-version.sh index 5e30d0f1c..85b297719 100755 --- a/hack/verify-chart-version.sh +++ b/hack/verify-chart-version.sh @@ -18,13 +18,14 @@ set -o errexit set -o nounset set -o pipefail -if [ -z "${1:-}" ]; then +chart_tarball=${1:-} +DOCKER=${DOCKER:-docker} + +if [ -z "${chart_tarball}" ]; then echo "usage: $0 " exit 1 fi -chart_tarball=$1 - chart_dir="deploy/charts/cert-manager" echo "Linting chart '${chart_tarball}' using internal dir '${chart_dir}'" @@ -34,8 +35,8 @@ trap "rm -rf ${tmpdir}" EXIT tar -C "${tmpdir}" -xvf $chart_tarball -if ! docker run -v "${tmpdir}":/workspace --workdir /workspace \ - quay.io/helmpack/chart-testing:v3.5.0 \ +if ! ${DOCKER} run -v "${tmpdir}":/workspace --workdir /workspace \ + quay.io/helmpack/chart-testing:v3.5.1 \ ct lint \ --check-version-increment=false \ --validate-maintainers=false \ diff --git a/make/ci.mk b/make/ci.mk index 9eaf63e32..9c692e7b0 100644 --- a/make/ci.mk +++ b/make/ci.mk @@ -9,7 +9,7 @@ verify-imports: bin/tools/goimports .PHONY: verify-chart verify-chart: bin/cert-manager-$(RELEASE_VERSION).tgz - ./hack/verify-chart-version.sh $< + DOCKER=$(CTR) ./hack/verify-chart-version.sh $< .PHONY: verify-errexit verify-errexit: From 7a7a3951ed1c2b891bc4d51fa0ad2e13287b482b Mon Sep 17 00:00:00 2001 From: Ashley Davis Date: Tue, 10 May 2022 18:52:44 +0100 Subject: [PATCH 2/2] ignore bin directory in various verification scripts these scripts would choke in various ways on a vendored copy of go ignoring `bin` is the correct behaviour anyway, and should speed up running the scripts Signed-off-by: Ashley Davis --- hack/verify-errexit.sh | 2 +- hack/verify-goimports.sh | 9 +++++++-- hack/verify_boilerplate.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/hack/verify-errexit.sh b/hack/verify-errexit.sh index 15a1a4cdc..b3d523134 100755 --- a/hack/verify-errexit.sh +++ b/hack/verify-errexit.sh @@ -31,7 +31,7 @@ echo "+++ validating all scripts set '-o errexit'" >&2 if [ "$*" != "" ]; then args="$*" else - args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' ) + args=$(ls "$(pwd)" | grep -v 'bazel-' | grep -v 'external/' | grep -v 'bin' ) fi # Gather the list of files that appear to be shell scripts. diff --git a/hack/verify-goimports.sh b/hack/verify-goimports.sh index 22a43ee0b..f14ce016e 100755 --- a/hack/verify-goimports.sh +++ b/hack/verify-goimports.sh @@ -28,15 +28,20 @@ goimports=$(realpath "$1") # passing "-local" would be ideal, but it'll conflict with auto generated files ATM # and cause churn when we want to update those files #common_flags="-local github.com/cert-manager/cert-manager" + common_flags="" echo "+++ running goimports" >&2 -output=$($goimports $common_flags -l .) +# find all directories except bin which contain go files, and output them on a single line + +godirs=$(find . -not \( -path "./bin/*" -prune \) -name "*.go" | cut -d'/' -f2 | sort | uniq | tr '\n' ' ') + +output=$($goimports $common_flags -l $godirs) if [ ! -z "${output}" ]; then echo "${output}" echo "+++ goimports failed; the following command may fix:" >&2 - echo "+++ $goimports $common_flags -w ." &>2 + echo "+++ $goimports $common_flags -w $godirs" >&2 exit 1 fi diff --git a/hack/verify_boilerplate.py b/hack/verify_boilerplate.py index da902f981..dc822b6b6 100755 --- a/hack/verify_boilerplate.py +++ b/hack/verify_boilerplate.py @@ -121,7 +121,7 @@ def file_extension(filename): SKIPPED_DIRS = [ 'Godeps', 'third_party', '_gopath', '_output', 'external', '.git', 'vendor', '__init__.py', - 'node_modules', + 'node_modules', 'bin' ] # even when generated by bazel we will complain about some generated files @@ -135,7 +135,16 @@ IGNORE_HEADERS = [ def has_ignored_header(pathname): with open(pathname, 'r', encoding="utf-8") as myfile: - data = myfile.read() + try: + data = myfile.read() + except Exception as e: + # read() can fail if, e.g., the script tries to read a binary file; + # we could handle UnicodeDecodeError but if the script is recursing + # into a folder with binaries we probably want to know about it + # so print the name of the failed file and fail loudly + print("failed to read", pathname) + raise + for header in IGNORE_HEADERS: if header in data: return True