From 7d19151be7a076c3c799ec4ce72aae574e31cfd5 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 14 Feb 2019 21:15:42 -0800 Subject: [PATCH] Check if generated files are out of date --- scripts/gogenerate.sh | 33 +++++++++++++++++++++++++++++++++ scripts/travis_checker.sh | 17 +++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 scripts/gogenerate.sh diff --git a/scripts/gogenerate.sh b/scripts/gogenerate.sh new file mode 100755 index 000000000..575424407 --- /dev/null +++ b/scripts/gogenerate.sh @@ -0,0 +1,33 @@ +#!/bin/sh +unset -v progdir +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; +esac +git grep -l '^//go:generate ' | sort -t/ | ( + gogenerate() { + case $# in 0) return;; esac + go generate "$@" + } + unset -v prevdir dir file + prevdir= + set -- + while read -r file + do + case "${file}" in + */*) dir="${file%/*}";; + *) dir=".";; + esac + case "${prevdir}" in + "${dir}") + set -- "${@}" "${file}" + ;; + *) # includes "" + gogenerate "${@}" # no-op for "" + set -- "${file}" + ;; + esac + prevdir="${dir}" + done + gogenerate "$@" +) diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 4f462338b..559743ed4 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -48,6 +48,23 @@ else echo "goimports passed." fi +echo "Running go generate..." +gogenerate_status_before="${tmpdir}/gogenerate_status_before.txt" +gogenerate_status_after="${tmpdir}/gogenerate_status_after.txt" +gogenerate_status_diff="${tmpdir}/gogenerate_status.diff" +git status --porcelain=v2 > "${gogenerate_status_before}" +"${progdir}/gogenerate.sh" +git status --porcelain=v2 > "${gogenerate_status_after}" +if diff -u "${gogenerate_status_before}" "${gogenerate_status_after}" \ + > "${gogenerate_status_diff}" +then + echo "go generate succeeded; all generated files seem up to date." +else + echo "go generate changed working tree contents!" + "${progdir}/print_file.sh" "${gogenerate_status_diff}" "git status diff" + ok=false +fi + if ! ${ok} then echo "Some checks failed; see output above."