Skip to content

Commit

Permalink
Adding verify-codegen script
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jul 4, 2024
1 parent efe1245 commit 298a73d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
21 changes: 14 additions & 7 deletions library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,22 @@ function calcRetcode() {
echo "$rc"
}

# Print error message.
# Parameters: $* - error message to be displayed
function error() {
gum_style \
--foreground '#D00' \
--padding '1 3' \
--border double \
--border-foreground '#D00' \
"ERROR: $*"
}

# Print error message and call exit(n) where n calculated from the error message.
# Parameters: $1..$n - error message to be displayed
# Globals: abort_retcode will change the default retcode to be returned
function abort() {
gum_style \
--foreground '#D00' \
--padding '1 3' \
--border double \
--border-foreground '#D00' \
"ERROR: $*"
error "$*"
readonly abort_retcode="${abort_retcode:-$(calcRetcode "$*")}"
exit "$abort_retcode"
}
Expand All @@ -169,7 +175,8 @@ function make_banner() {

# Simple header for logging purposes.
function header() {
local upper="$(echo "$*" | tr a-z A-Z)"
local upper
upper="$(echo "$*" | tr '[:lower:]' '[:upper:]')"
gum_style \
--padding '1 3' \
--border double \
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"knative.dev/hack/test/e2e/apis/hack"
"knative.dev/hack/test/codegen/testdata/apis/hack"
)

// SchemeGroupVersion is group version used to register these objects
Expand Down
4 changes: 2 additions & 2 deletions test/hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ relative_rootdir="$(realpath -s --relative-to="$PWD" "$rootdir")"
source "$(go run "${relative_rootdir}/cmd/script" codegen-library.sh)"

generate-groups deepcopy \
knative.dev/hack/test/e2e/apis/hack/v1alpha1/generated \
knative.dev/hack/test/e2e/apis \
knative.dev/hack/test/codegen/testdata/apis/hack/v1alpha1 \
knative.dev/hack/test/codegen/testdata/apis \
hack:v1alpha1 \
"$@"
31 changes: 31 additions & 0 deletions test/hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Copyright 2024 The Knative 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 -Eeuo pipefail

rootdir="$(realpath "$(dirname "${BASH_SOURCE[0]:-$0}")/../..")"
cd "${rootdir}"

# shellcheck disable=SC1090
source "$(go run ./cmd/script library.sh)"

./test/hack/update-codegen.sh

if ! git diff --exit-code; then
abort "codegen is out of date, please run test/hack/update-codegen.sh, and commit the changes."
fi

header "Codegen is up to date"
2 changes: 1 addition & 1 deletion test/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function post_build_tests() {
local failed=0
for script in *.sh; do
subheader "Checking integrity of ${script}"
bash -c "source ${script}" || { failed=1; echo "--- FAIL: ${script}"; }
bash -c "source ${script}" || { failed=1; error "${script}"; }
done
return ${failed}
}
Expand Down

0 comments on commit 298a73d

Please sign in to comment.