| 1 |
#!/bin/bash |
| 2 |
# This script is used by the CI to check if 'go generate ./...' is up to date. |
| 3 |
# |
| 4 |
# Note: If the generated files aren't up to date then this script updates |
| 5 |
# them despite printing an error message so running it the second time |
| 6 |
# might not print any errors. This isn't very useful locally during development |
| 7 |
# but it works well with the CI that downloads a fresh version of the repo |
| 8 |
# each time before executing this script. |
| 9 |
|
| 10 |
set -euo pipefail |
| 11 |
|
| 12 |
BASE_DIR="$PWD" |
| 13 |
TEMP_DIR=$( mktemp -d ) |
| 14 |
function cleanup() { |
| 15 |
rm -rf "${TEMP_DIR}" |
| 16 |
} |
| 17 |
trap cleanup EXIT |
| 18 |
|
| 19 |
cp -r . "${TEMP_DIR}/" |
| 20 |
cd $TEMP_DIR |
| 21 |
|
| 22 |
for i in $(find $PWD -name go.mod); do |
| 23 |
pushd $(dirname $i) |
| 24 |
go generate ./... |
| 25 |
popd |
| 26 |
done |
| 27 |
|
| 28 |
if ! diff -r . "${BASE_DIR}"; then |
| 29 |
echo |
| 30 |
echo "The generated files aren't up to date." |
| 31 |
echo "Update them with the 'go generate ./...' command." |
| 32 |
exit 1 |
| 33 |
fi |