-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathgenerate.sh
executable file
·52 lines (46 loc) · 1.33 KB
/
generate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
#/ script/generate.sh runs go generate on all modules in this repo.
#/ `script/generate.sh --check` checks that the generated files are up to date.
set -e
CDPATH="" cd -- "$(dirname -- "$0")/.."
# force 1.22.0 default and "auto" toolchain (i.e., use the toolchain directive)
# when running generate and mod tidy
export GOTOOLCHAIN="go1.22.0+auto"
if [ "$1" = "--check" ]; then
GENTEMP="$(mktemp -d)"
git worktree add -q --detach "$GENTEMP"
trap 'git worktree remove -f "$GENTEMP"; rm -rf "$GENTEMP"' EXIT
for f in $(git ls-files -com --exclude-standard); do
target="$GENTEMP/$f"
mkdir -p "$(dirname -- "$target")"
cp "$f" "$target"
done
if [ -f "$(pwd)"/bin ]; then
ln -s "$(pwd)"/bin "$GENTEMP"/bin
fi
(
cd "$GENTEMP"
git add .
git -c user.name='bot' -c user.email='bot@localhost' commit -m "generate" -q --allow-empty
script/generate.sh
[ -z "$(git status --porcelain)" ] || {
msg="Generated files are out of date. Please run script/generate.sh and commit the results"
if [ -n "$GITHUB_ACTIONS" ]; then
echo "::error ::$msg"
else
echo "$msg" 1>&2
fi
git diff
exit 1
}
)
exit 0
fi
MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)"
for dir in $MOD_DIRS; do
(
cd "$dir"
go generate ./...
go mod tidy
)
done