Check if generated files are out of date

pull/457/head
Eugene Kim 6 years ago
parent 687e01f137
commit 7d19151be7
  1. 33
      scripts/gogenerate.sh
  2. 17
      scripts/travis_checker.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 "$@"
)

@ -48,6 +48,23 @@ else
echo "goimports passed." echo "goimports passed."
fi 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} if ! ${ok}
then then
echo "Some checks failed; see output above." echo "Some checks failed; see output above."

Loading…
Cancel
Save