hack/module.sh learns codegen_verify

This commit is contained in:
aram price 2020-08-14 17:34:21 -07:00 committed by Andrew Keesler
parent a456daa0b2
commit 7fa8f7797a
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
2 changed files with 32 additions and 2 deletions

View File

@ -68,8 +68,33 @@ function codegen::generate_for_module() {
}
function codegen::generate() {
local mod_basename_for_version
mod_basename_for_version="${K8S_PKG_VERSION}/$(basename "${MOD_DIR}")"
codegen::ensure_module_in_gopath
codegen::generate_for_module "${K8S_PKG_VERSION}/$(basename "${MOD_DIR}")"
codegen::generate_for_module "${mod_basename_for_version}"
}
function codegen::verify() {
local have_stash=''
if [[ "$(git status --porcelain 2>/dev/null | wc -l | tr -d ' ')" -ne "0" ]]; then
git stash --all >/dev/null 2>&1 && have_stash=1
fi
codegen::generate
if [[ "$(git status --porcelain 2>/dev/null | wc -l | tr -d ' ')" -eq "0" ]]; then
echo "Generated code in ${MOD_DIR} up to date."
else
echo "Generated code in ${MOD_DIR} is out of date."
echo "Please run hack/module.sh codegen"
git diff "${ROOT}"
git checkout "${ROOT}"
fi
if [[ -n "${have_stash}" ]]; then
git stash pop >/dev/null 2>&1
fi
}
function codegen::usage() {

View File

@ -37,6 +37,10 @@ function codegen_cmd() {
echo "${ROOT}/hack/codegen.sh codegen::generate"
}
function codegen_verify_cmd() {
echo "${ROOT}/hack/codegen.sh codegen::verify"
}
# The race detector is slow, so sometimes you don't want to use it
function unittest_no_race_cmd() {
if [ -x "$(command -v gotest)" ]; then
@ -66,7 +70,7 @@ function with_modules() {
function usage() {
echo "Error: <task> must be specified"
echo " do.sh <task> [tidy, lint, test, unittest, unittest_no_race, codegen]"
echo " do.sh <task> [tidy, lint, test, unittest, unittest_no_race, codegen, codegen_verify]"
exit 1
}
@ -78,6 +82,7 @@ function main() {
'unittest') with_modules 'unittest_cmd' ;;
'unittest_no_race') with_modules 'unittest_no_race_cmd' ;;
'codegen') with_modules 'codegen_cmd' ;;
'codegen_verify') with_modules 'codegen_verify_cmd' ;;
*) usage ;;
esac
}