Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,46 @@
# See the License for the specific language governing permissions and
# limitations under the License.

source "$(dirname $(readlink -f ${BASH_SOURCE}))/../test/library.sh"

set -o errexit
set -o nounset
set -o pipefail

SERVING_ROOT=$(dirname "${BASH_SOURCE}")/..

DIFFROOT="${SERVING_ROOT}"
TMP_DIFFROOT="${SERVING_ROOT}/_tmp"
_tmp="${SERVING_ROOT}/_tmp"
readonly TMP_DIFFROOT="$(mktemp -d -p ${SERVING_ROOT_DIR})"

cleanup() {
rm -rf "${_tmp}"
rm -rf "${TMP_DIFFROOT}"
}

trap "cleanup" EXIT SIGINT

cleanup

# Save working tree state
mkdir -p "${TMP_DIFFROOT}/pkg"
cp -a "${DIFFROOT}/pkg"/* "${TMP_DIFFROOT}/pkg"
cp -aR "${SERVING_ROOT_DIR}/Gopkg.lock" "${SERVING_ROOT_DIR}/pkg" "${SERVING_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"

# We symlink a few testdata files from config, so copy it as well.
mkdir -p "${TMP_DIFFROOT}/config"
cp -a "${DIFFROOT}/config"/* "${TMP_DIFFROOT}/config"
cp -a "${SERVING_ROOT_DIR}/config"/* "${TMP_DIFFROOT}/config"

# TODO(mattmoor): We should be able to rm -rf pkg/client/ and vendor/

"${SERVING_ROOT}/hack/update-codegen.sh"
echo "Diffing ${DIFFROOT} against freshly generated codegen"
"${SERVING_ROOT_DIR}/hack/update-codegen.sh"
echo "Diffing ${SERVING_ROOT_DIR} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}/pkg" "${TMP_DIFFROOT}/pkg" || ret=$?
cp -a "${TMP_DIFFROOT}/pkg"/* "${DIFFROOT}/pkg"
diff -Naupr "${SERVING_ROOT_DIR}/pkg" "${TMP_DIFFROOT}/pkg" || ret=$?

# Restore working tree state
rm -fr "${TMP_DIFFROOT}/config"
rm -fr "${SERVING_ROOT_DIR}/Gopkg.lock" "${SERVING_ROOT_DIR}/pkg" "${SERVING_ROOT_DIR}/vendor"
cp -aR "${TMP_DIFFROOT}"/* "${SERVING_ROOT_DIR}"

if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
echo "${SERVING_ROOT_DIR} up to date."
else
echo "ERROR: ${DIFFROOT} is out of date. Please run ./hack/update-codegen.sh"
echo "ERROR: ${SERVING_ROOT_DIR} is out of date. Please run ./hack/update-codegen.sh"
exit 1
fi