verify zz_generated_range_data.go is up to date

This commit is contained in:
Benjamin Elder 2022-04-20 16:29:10 -07:00
parent 98996f191f
commit 7f2fec0579
4 changed files with 60 additions and 8 deletions

View File

@ -102,6 +102,9 @@ gofmt:
# run linters, ensure generated code, etc.
verify:
hack/make-rules/verify.sh
# verify generated files, subset of verify
verify-generated:
hack/make-rules/verify-generated.sh
# code linters
lint:
hack/make-rules/lint.sh
@ -109,4 +112,4 @@ lint:
shellcheck:
hack/make-rules/shellcheck.sh
#################################################################################
.PHONY: all archeio build unit integration clean update gofmt verify lint shellcheck
.PHONY: all archeio build unit integration clean update gofmt verify verify-generated lint shellcheck

View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright 2022 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.
# script to verify generated files
set -o errexit -o nounset -o pipefail
# cd to the repo root and setup go
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd -P)"
cd "${REPO_ROOT}"
source hack/tools/setup-go.sh
tmpdir=$(mktemp -d)
trap 'rm -rf ${tmpdir?}' EXIT
# generate and compare
OUT_FILE="${tmpdir}"/zz_generated_range_data.go
export OUT_FILE
./pkg/net/cidrs/aws/internal/ranges2go/run.sh
if ! diff "${OUT_FILE}" ./pkg/net/cidrs/aws/zz_generated_range_data.go; then
>&2 echo ""
>&2 echo "generated file is out of date, please run 'go generate ./...' to regenerate"
exit 1
fi

View File

@ -26,24 +26,30 @@ res=0
# run all verify scripts, optionally skipping any of them
if [[ "${VERIFY_LINT:-true}" == "true" ]]; then
echo "verifying lints ..."
>&2 echo "verifying lints ..."
hack/make-rules/lint.sh || res=1
cd "${REPO_ROOT}"
fi
if [[ "${VERIFY_SHELLCHECK:-true}" == "true" ]]; then
echo "verifying shellcheck ..."
>&2 echo "verifying shellcheck ..."
hack/make-rules/shellcheck.sh || res=1
cd "${REPO_ROOT}"
fi
if [[ "${VERIFY_GENERATED:-true}" == "true" ]]; then
>&2 echo "Verifying generated ..."
hack/make-rules/verify-generated.sh || res=1
cd "${REPO_ROOT}"
fi
# exit based on verify scripts
if [[ "${res}" = 0 ]]; then
echo ""
echo "All verify checks passed, congrats!"
>&2 echo ""
>&2 echo "All verify checks passed, congrats!"
else
echo ""
echo "One or more verify checks failed! See output above..."
>&2 echo ""
>&2 echo "One or more verify checks failed! See output above..."
fi
exit "${res}"

View File

@ -21,6 +21,12 @@ package main
import "os"
func main() {
// overridable for make verify
outputPath := os.Getenv("OUT_FILE")
if outputPath == "" {
outputPath = "./zz_generated_range_data.go"
}
// parse raw AWS IP range data
parsed, err := parseIPRangesJSON([]byte(ipRangesRaw))
if err != nil {
panic(err)
@ -30,7 +36,7 @@ func main() {
panic(err)
}
// emit file
f, err := os.Create("./zz_generated_range_data.go")
f, err := os.Create(outputPath)
if err != nil {
panic(err)
}