-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·56 lines (47 loc) · 1.24 KB
/
build.sh
File metadata and controls
executable file
·56 lines (47 loc) · 1.24 KB
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
53
54
55
56
#!/usr/bin/env bash
set -e
CHANGE_ONLY="false"
GO_MOD_DIRS=$(find . -type f -name "go.mod" | xargs -n1 dirname)
print_usage() {
echo "Runs go build on all modules. Output is written to ./bin"
echo
echo "Syntax: ./build.sh [-c]"
echo "options:"
echo "c Build only on changed modules."
echo "h Print this Help."
echo
}
while getopts 'cp:' flag; do
case "${flag}" in
c) CHANGE_ONLY='true' ;;
*) print_usage
exit 1 ;;
esac
done
echo "Running go build with the following options:"
echo "CHANGE_ONLY: $CHANGE_ONLY"
echo "OUTPUT_DIR: $PWD/bin"
echo $@
for f in $GO_MOD_DIRS; do
if [ -d $f ]; then
BASEDIR=$PWD
cd $f
CHANGES=""
if [ "$CHANGE_ONLY" = "true" ]; then
CHANGES=$(git diff --name-only HEAD..origin/main ../)
if [ "$CHANGES" = "" ]; then
echo "No changes in $f, skipping."
cd -
continue
fi
fi
# rename cli -> cloudquery
bin_name=$(basename $f)
if [ "$bin_name" = "cli" ]; then
bin_name="cloudquery"
fi
echo "Running go build -o bin/$bin_name on $f"
go build -v -o $BASEDIR/bin/$bin_name .
cd -
fi
done