github.com/google/go-github/v60@v60.0.0/script/generate.sh (about) 1 #!/bin/sh 2 #/ script/generate.sh runs go generate on all modules in this repo. 3 #/ `script/generate.sh --check` checks that the generated files are up to date. 4 5 set -e 6 7 CDPATH="" cd -- "$(dirname -- "$0")/.." 8 9 if [ "$1" = "--check" ]; then 10 GENTEMP="$(mktemp -d)" 11 git worktree add -q --detach "$GENTEMP" 12 trap 'git worktree remove -f "$GENTEMP"; rm -rf "$GENTEMP"' EXIT 13 for f in $(git ls-files -com --exclude-standard); do 14 target="$GENTEMP/$f" 15 mkdir -p "$(dirname -- "$target")" 16 cp "$f" "$target" 17 done 18 if [ -f "$(pwd)"/bin ]; then 19 ln -s "$(pwd)"/bin "$GENTEMP"/bin 20 fi 21 ( 22 cd "$GENTEMP" 23 git add . 24 git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty 25 script/generate.sh 26 [ -z "$(git status --porcelain)" ] || { 27 msg="Generated files are out of date. Please run script/generate.sh and commit the results" 28 if [ -n "$GITHUB_ACTIONS" ]; then 29 echo "::error ::$msg" 30 else 31 echo "$msg" 1>&2 32 fi 33 git diff 34 exit 1 35 } 36 ) 37 exit 0 38 fi 39 40 MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" 41 42 for dir in $MOD_DIRS; do 43 ( 44 cd "$dir" 45 go generate ./... 46 go mod tidy -compat '1.21' 47 ) 48 done