-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·108 lines (78 loc) · 2.4 KB
/
build.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -euo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIR="$DIR/build"
# Enter the directory and start the build process for service stubs.
function buildDir {
currentDir="$1"
pushd "$currentDir" > /dev/null
target=$(basename "$currentDir")
if [ -f .protolangs ]; then
print "Building directory: '$currentDir'"
while read lang; do
repo="twirp-$target-$lang"
build_dir="$BUILD_DIR/$repo"
rm -rf "$build_dir"
print "Cloning repo: [email protected]:thingful/$repo.git"
git clone "[email protected]:thingful/$repo.git" "$build_dir"
case "$lang" in
go)
retool do protoc --proto_path=. --twirp_out="$build_dir" --go_out="$build_dir" ./*.proto
;;
ruby)
retool do protoc --proto_path=. --ruby_out="$build_dir" --twirp_ruby_out="$build_dir" ./*.proto
;;
node)
retool do protoc --twirp_out="$build_dir" --twirp_js_out="$build_dir" --js_out="import_style=commonjs,binary:$build_dir" ./*.proto
;;
python)
retool do protoc --proto_path=. --twirp_python_out="$build_dir" --python_out="$build_dir" ./*.proto
;;
*)
print "Unknown language - currently supported languages are: go, ruby, js and python"
exit 1
esac
sed -e "s|ARG_REPO_NAME|$repo|g" \
-e "s|ARG_LANG|$lang|g" \
-e "s|ARG_TARGET|$target|g" \
"$DIR/.README.template" > "$build_dir/README.md"
cp -f "$DIR/LICENSE" "$build_dir/LICENSE"
if [ "$2" = true ]; then
commitAndPush "$build_dir"
fi
done < .protolangs
fi
popd > /dev/null
}
# Finds all directories and builds proto buffer definitions
function buildAll {
print "Building protocol buffer stubs"
clean
find "$DIR" -type d -not -path '*/\.*' | while read d; do
buildDir "$d" "${1:-false}"
done
}
# Cleans our build directories
function clean {
print "Cleaning build directories"
echo $BUILD_DIR
rm -rf "$BUILD_DIR"
}
function commitAndPush {
print "Committing and pushing from $1"
pushd "$1" > /dev/null
git add -N .
if ! git diff --exit-code > /dev/null; then
print "Changes detected"
git add .
git commit -m "Automatic rebuild of Twirp stubs"
git push origin HEAD
else
print "No changes detected for $1"
fi
popd > /dev/null
}
function print {
echo "--> $1"
}
"$@"